File size: 6,379 Bytes
35cdf53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204


"""Genetic search config settings for data pipelines."""

import dataclasses
import datetime
from typing import Self
from flax_model.alphafold3.constants import mmcif_names


def _validate_chain_poly_type(chain_poly_type: str) -> None:
  if chain_poly_type not in mmcif_names.STANDARD_POLYMER_CHAIN_TYPES:
    raise ValueError(
        'chain_poly_type must be one of'
        f' {mmcif_names.STANDARD_POLYMER_CHAIN_TYPES}: {chain_poly_type}'
    )


@dataclasses.dataclass(frozen=True, kw_only=True, slots=True)
class DatabaseConfig:
  """Configuration for a database."""

  name: str
  path: str


@dataclasses.dataclass(frozen=True, kw_only=True, slots=True)
class JackhmmerConfig:
  """Configuration for a jackhmmer run.

  Attributes:
      binary_path: Path to the binary of the msa tool.
      database_config: Database configuration.
      n_cpu: An integer with the number of CPUs to use.
      n_iter: An integer with the number of database search iterations.
      e_value: e-value for the database lookup.
      z_value: The Z-value representing the database size in number of sequences
        for E-value and domain E-value calculation. Must be set for sharded
        databases.
      dom_z_value: The Z-value representing the database size in number of
        sequences for domain E-value calculation. Must be set for sharded
        databases.
      max_sequences: Max sequences to return in MSA.
      max_parallel_shards: If given, the maximum number of shards to search
        against in parallel. If None, one Jackhmmer instance will be run per
        shard. Only applicable if the database is sharded.
      max_threads: If given, the maximum number of threads used when running
        sharded databases.
  """

  binary_path: str
  database_config: DatabaseConfig
  n_cpu: int
  n_iter: int
  e_value: float
  z_value: int | None
  dom_z_value: int | None
  max_sequences: int
  max_parallel_shards: int | None = None
  max_threads: int | None = None

  
@dataclasses.dataclass(frozen=True, kw_only=True, slots=True)
class NhmmerConfig:
  """Configuration for a nhmmer run.

  Attributes:
      binary_path: Path to the binary of the msa tool.
      hmmalign_binary_path: Path to the hmmalign binary.
      hmmbuild_binary_path: Path to the hmmbuild binary.
      database_config: Database configuration.
      n_cpu: An integer with the number of CPUs to use.
      e_value: e-value for the database lookup.
      z_value: The Z-value representing the database size in megabases for
        E-value calculation. Allows fractional values. Must be set for sharded
        databases.
      max_sequences: Max sequences to return in MSA.
      alphabet: The alphabet when building a profile with hmmbuild.
      max_parallel_shards: If given, the maximum number of shards to search
        against in parallel. If None, one Nhmmer instance will be run per shard.
        Only applicable if the database is sharded.
      max_threads: If given, the maximum number of threads used when running
        sharded databases.        
  """

  binary_path: str
  hmmalign_binary_path: str
  hmmbuild_binary_path: str
  database_config: DatabaseConfig
  n_cpu: int
  e_value: float
  z_value: float | None
  max_sequences: int
  alphabet: str | None
  max_parallel_shards: int | None = None
  max_threads: int | None = None
  

@dataclasses.dataclass(frozen=True, kw_only=True, slots=True)
class MmseqsConfig:
  """Configuration for mmseqs run.

  Attributes:
      binary_path: Path to the binary of the msa tool.
      database_config: Database configuration.
      n_cpu: An integer with the number of CPUs to use.
      use_gpu: An integer with the number of GPUs to use.
      mmseqs_options: Options for the mmseqs run.
      result2msa_options: Options for the result2msa run.
  """

  binary_path: str
  database_config: DatabaseConfig
  n_cpu: int
  use_gpu: int=0
  mmseqs_options: str
  result2msa_options: str
  max_sequences: int

@dataclasses.dataclass(frozen=True, kw_only=True, slots=True)
class RunConfig:
  """Configuration for an MSA run.

  Attributes:
    config: MSA tool config.
    chain_poly_type: The chain type for which the tools will be run.
    crop_size: The maximum number of sequences to keep in the MSA. If None, all
      sequences are kept. Note that the query is included in the MSA, so it
      doesn't make sense to set this to less than 2.
  """

  config: JackhmmerConfig | NhmmerConfig | MmseqsConfig
  chain_poly_type: str
  crop_size: int | None

  def __post_init__(self):
    if self.crop_size is not None and self.crop_size < 2:
      raise ValueError(f'crop_size must be None or >= 2: {self.crop_size}')

    _validate_chain_poly_type(self.chain_poly_type)


@dataclasses.dataclass(frozen=True, kw_only=True, slots=True)
class HmmsearchConfig:
  """Configuration for a hmmsearch."""

  hmmsearch_binary_path: str
  hmmbuild_binary_path: str

  e_value: float
  inc_e: float
  dom_e: float
  incdom_e: float
  alphabet: str = 'amino'
  filter_f1: float | None = None
  filter_f2: float | None = None
  filter_f3: float | None = None
  filter_max: bool = False


@dataclasses.dataclass(frozen=True, kw_only=True, slots=True)
class TemplateToolConfig:
  """Configuration for a template tool."""

  database_path: str
  chain_poly_type: str
  hmmsearch_config: HmmsearchConfig
  max_a3m_query_sequences: int | None = 300

  def __post_init__(self):
    _validate_chain_poly_type(self.chain_poly_type)


@dataclasses.dataclass(frozen=True, kw_only=True, slots=True)
class TemplateFilterConfig:
  """Configuration for a template filter."""

  max_subsequence_ratio: float | None
  min_align_ratio: float | None
  min_hit_length: int | None
  deduplicate_sequences: bool
  max_hits: int | None
  max_template_date: datetime.date

  @classmethod
  def no_op_filter(cls) -> Self:
    """Returns a config for filter that keeps everything."""
    return cls(
        max_subsequence_ratio=None,
        min_align_ratio=None,
        min_hit_length=None,
        deduplicate_sequences=False,
        max_hits=None,
        max_template_date=datetime.date(3000, 1, 1),  # Very far in the future.
    )


@dataclasses.dataclass(frozen=True, kw_only=True, slots=True)
class TemplatesConfig:
  """Configuration for the template search pipeline."""

  template_tool_config: TemplateToolConfig
  filter_config: TemplateFilterConfig