Skip to content

Commit b24bb23

Browse files
committed
Fix AF2 test with trucated MSA
1 parent 25990af commit b24bb23

2 files changed

Lines changed: 19 additions & 14 deletions

File tree

test/scripts/test-af2.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,10 @@ python -c '
2222
from yunta.structs.msa import MSA
2323
2424
def make_stub(f):
25-
msa = MSA.from_file(f)
25+
msa = MSA.from_file(f).truncate(20)
2626
# Write a cropped version — first 60 columns
2727
with open(f.split(".")[0] + "_stub.a3m", "w") as f:
28-
for i, line in enumerate(msa.lines):
29-
line.sequence = line.sequence[:20]
30-
print(str(line), file=f)
31-
if i > 40:
32-
break
28+
msa.write(f)
3329
3430
make_stub("test/inputs/DYR_YEAST.a3m")
3531
make_stub("test/inputs/CAPZA_YEAST.a3m")

yunta/structs/msa.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,16 @@ def sequences(self) -> list[str]:
250250
def gap_fraction(self) -> list[float]:
251251
return [line.gap_fraction for line in self.lines]
252252

253+
def truncate(self, n: int) -> 'MSA':
254+
return replace(self, lines=[
255+
MSALine(
256+
sequence=line.sequence[:n],
257+
description=str(line.description),
258+
name=str(line.name),
259+
)
260+
for line in self.lines
261+
])
262+
253263
@classmethod
254264
def from_file(cls, file: str | TextIOWrapper) -> 'MSA':
255265
from bioino import FastaCollection
@@ -331,32 +341,31 @@ def write(self, file=sys.stdout) -> None:
331341
return None
332342

333343

344+
@dataclass
334345
class PairedMSA(MSA):
335-
336346
"""Paired MSA object which can be used for co-evolutionary analyses.
337347
"""
348+
chain_a_length: int
349+
chain_b_length: int = field(init=False)
338350

339-
def __init__(self,
340-
chain_a_length: int,
341-
*args, **kwargs):
342-
super().__init__(*args, **kwargs)
343-
self.chain_a_length = chain_a_length
351+
def __post_init__(self):
352+
super().__post_init__()
344353
self.chain_b_length = self.seq_length - self.chain_a_length
345354

346355
def split(
347356
self
348357
):
349358
msa1 = MSA([
350359
MSALine(
351-
sequence=line.sequence[self.chain_a_length:],
360+
sequence=line.sequence[:self.chain_a_length],
352361
description=str(line.description[0]),
353362
name=str(line.name[0]),
354363
)
355364
for line in self.lines
356365
])
357366
msa2 = MSA([
358367
MSALine(
359-
sequence=line.sequence[:self.chain_a_length],
368+
sequence=line.sequence[self.chain_a_length:],
360369
description=str(line.description[1]),
361370
name=str(line.name[1]),
362371
)

0 commit comments

Comments
 (0)