MSA File

This module defines functions and classes for parsing, manipulating, and analyzing multiple sequence alignments.

class MSAFile(msa, mode='r', format=None, aligned=True, **kwargs)[source]

Handle MSA files in FASTA, SELEX and Stockholm formats.

msa may be a filename or a stream. Multiple sequence alignments can be read from or written in FASTA (.fasta), Stockholm (.sth), or SELEX (.slx) format. For spesified extensions, format argument is not needed. If aligned is True, unaligned sequences in the file or stream will cause an IOError exception. filter, a function that returns a boolean, can be used for filtering sequences, see setFilter() for details. slice can be used to slice sequences, and is applied after filtering, see setSlice() for details.


Close the file. This method will not affect a stream.


Returns filename, or None if instance is handling a stream.


Returns function used for filtering sequences.


Returns file format.


Returns object used to slice sequences.


Returns title of the instance.


Returns True if MSA is aligned.


Returns to the beginning of the file.

setFilter(filter, filter_full=False)

Set function used for filtering sequences. filter will be applied to split sequence label, by default. If filter_full is True, filter will be applied to the full label.


Set object used to slice sequences, which may be a slice() or a list() of numbers.


Set title of the instance.


Write seq, an Sequence instance, into the MSA file.


True for closed file.


Format of the MSA file.


Returns label, starting residue number, and ending residue number parsed from sequence label.

parseMSA(filename, **kwargs)[source]

Returns an MSA instance that stores multiple sequence alignment and sequence labels parsed from Stockholm, SELEX, or FASTA format filename file, which may be a compressed file. Uncompressed MSA files are parsed using C code at a fraction of the time it would take to parse compressed files in Python.

writeMSA(filename, msa, **kwargs)[source]

Returns filename containing msa, a MSA or MSAFile instance, in the specified format, which can be SELEX, Stockholm, or FASTA. If compressed is True or filename ends with .gz, a compressed file will be written. MSA instances will be written using C function into uncompressed files.