Functions#

pycomsa.open(file, mode='r', format=None, size_format='N')#

Open a file for reading or for writing with CoMSA.

Parameters:
  • file (str, PathLike, or IOBase) – Either the path to a file to be opened, or a file-like object in binary mode that supports seek.

  • mode (r or w) – The mode with which to open the file, similarly to open.

  • format (fasta, stockholm or None) – The format of the file to be read or written. If None given (the default), the format will be auto-detected while reading, or set to stockholm when writing.

  • size_format (str) – The format to use for reading and writing size_t values, as a struct format specifier. The default N uses the native size_t type, but other formats can be given for cross-platform compatibility.

Example

>>> with pycomsa.open("trimal.msac") as reader:
...     msa = reader[0]
...     len(msa.sequences)
50
Raises:

ValueError – When given an invalid argument, or when the file format could not be auto-detected from the file contents.