@@ -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
334345class 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