Skip to content

Commit aa61135

Browse files
Merge pull request #20 from scbirlab/dev
Fix chunk calculation, spurious cpu=True override
2 parents 6ef4a8f + c8d1592 commit aa61135

3 files changed

Lines changed: 22 additions & 21 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "yunta"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
authors = [
55
{ name="Eachan Johnson", email="eachan.johnson@crick.ac.uk" },
66
]

yunta/interactions/runner.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Running interaction calculations."""
2-
from typing import TYPE_CHECKING, Any, Callable, Dict, Iterable, Mapping, Optional, Tuple, Union
2+
from typing import TYPE_CHECKING, Any
3+
from collections.abc import Callable, Iterable, Mapping
34
from abc import ABC, abstractmethod
45
from collections import defaultdict
56
from functools import partial
@@ -20,10 +21,10 @@
2021

2122
def _pair_msas(
2223
msa1: MSA,
23-
msa2: Optional[MSA] = None,
24+
msa2: MSA | None = None,
2425
max_gap_fraction: float = 1.,
2526
blocked: bool = False,
26-
interaction_map: Optional[Union[str, Mapping[str, Iterable[str]]]] = None,
27+
interaction_map: str | Mapping[str, Iterable[str]] | None = None,
2728
enforce_ref_match: bool = False
2829
) -> PairedMSA:
2930
try:
@@ -51,7 +52,7 @@ def _calculate_interaction_blocks(
5152
use_sequences: bool = False,
5253
use_id: bool = False,
5354
**kwargs
54-
) -> Tuple[ndarray, dict]:
55+
) -> tuple[ndarray, dict]:
5556

5657
import numpy as np
5758
from tqdm.auto import tqdm
@@ -68,7 +69,7 @@ def _calculate_interaction_blocks(
6869
print_err(f"[INFO] Splitting MSA with {n_msa_columns} columns into pairs of {chunksize}-column chunks.")
6970
chunks = np.split(token_ids, list(range(chunksize, n_msa_columns, chunksize)), axis=-1)
7071
n_chunks = len(chunks)
71-
n_blocks = n_chunks * (n_chunks - 1) // 2
72+
n_blocks = int(n_chunks * (n_chunks + 1) / 2)
7273
print_err(f"[INFO] Split MSA with {n_msa_columns} columns into {n_chunks} x {chunksize}-column chunks ({n_blocks} blocks).")
7374

7475
result = np.zeros(
@@ -147,30 +148,30 @@ def make_model(cpu=False, **kwargs):
147148
@abstractmethod
148149
def _run_chunk(
149150
paired_msa: PairedMSA,
150-
model: Optional[Callable] = None,
151+
model: Callable | None = None,
151152
**kwargs
152153
) -> Iterable[ArrayLike]:
153154
...
154155

155156
@staticmethod
156157
def post_run(
157158
paired_msa: PairedMSA,
158-
results: Dict[Tuple, Any],
159+
results: dict[tuple, Any],
159160
**kwargs
160161
) -> dict:
161162
return {}
162163

163164
def run(
164165
self,
165166
msa1: MSA,
166-
msa2: Optional[MSA] = None,
167+
msa2: MSA | None = None,
167168
max_gap_fraction: float = .9,
168-
interaction_map: Optional[Union[str, Mapping[str, Iterable[str]]]] = None,
169+
interaction_map: str | Mapping[str, Iterable[str]] | None = None,
169170
cpu: bool = False,
170-
model: Optional[Callable] = None,
171+
model: Callable | None = None,
171172
chunksize: int = DEFAULT_CHUNKSIZE,
172173
enforce_ref_match: bool = False,
173-
model_kwargs: Optional[dict] = None,
174+
model_kwargs: dict | None = None,
174175
**kwargs
175176
):
176177
paired_msa = _pair_msas(
@@ -224,7 +225,7 @@ class AF2Runner(Runner):
224225
def make_model(
225226
cpu=False,
226227
max_recycles: int = 10,
227-
param_dir: Optional[str] = None,
228+
param_dir: str | None = None,
228229
**kwargs
229230
):
230231
from .af2.modelling import make_model_runner
@@ -239,8 +240,8 @@ def _run_chunk(
239240
paired_msa: ArrayLike,
240241
chain_a_length: int,
241242
_id: str,
242-
model: Optional[Callable] = None,
243-
seed: Optional[int] = None,
243+
model: Callable | None = None,
244+
seed: int | None = None,
244245
**kwargs
245246
):
246247
from .af2 import run_af2
@@ -255,8 +256,8 @@ def _run_chunk(
255256
@staticmethod
256257
def post_run(
257258
paired_msa: PairedMSA,
258-
results: Dict[Tuple, Any],
259-
seed: Optional[int] = None,
259+
results: dict[tuple, Any],
260+
seed: int | None = None,
260261
**kwargs
261262
):
262263
from .af2 import post_af2
@@ -271,7 +272,7 @@ class DCARunner(Runner):
271272
@staticmethod
272273
def _run_chunk(
273274
paired_msa: PairedMSA,
274-
model: Optional[Callable] = None,
275+
model: Callable | None = None,
275276
apc: bool = True,
276277
**kwargs
277278
):
@@ -284,7 +285,7 @@ def _run_chunk(
284285
@staticmethod
285286
def post_run(
286287
paired_msa: PairedMSA,
287-
results: Dict[Tuple, Any],
288+
results: dict[tuple, Any],
288289
apc: bool = True,
289290
**kwargs
290291
):
@@ -311,7 +312,7 @@ def make_model(cpu=False, **kwargs):
311312
def _run_chunk(
312313
paired_msa: PairedMSA,
313314
chain_a_length: int,
314-
model: Optional[Callable] = None,
315+
model: Callable | None = None,
315316
**kwargs
316317
):
317318
result, cα_coords = model.predict(

yunta/screening.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def rf2track_one_vs_many(
8888
max_gap_fraction: float = DEFAULT_MAX_GAP_FRACTION,
8989
interaction_map: Optional[Union[str, Mapping[str, Iterable[str]]]] = None,
9090
enforce_ref_match: bool = False,
91-
cpu: bool = True,
91+
cpu: bool = False,
9292
**kwargs
9393
) -> List[Tuple[np.ndarray, np.ndarray, RF2TMetrics]]:
9494
return _screen_one_vs_many(

0 commit comments

Comments
 (0)