FASTA#

class pyncbitk.objtools.FastaReader#

An iterative reader over the sequences in a FASTA file.

classmethod __new__(*args, **kwargs)#
__init__(file, *, split=True, parse_ids=True)#

Create a new FASTA reader from a file or a file-like object.

Parameters:
  • file (str, os.PathLike or file-like object) – Either the path to a file to be open, or a Python file-like object open in binary mode.

  • split (bool) – Set to False to force the reader to produce BioSeq objects where the instance is a ContinuousInst object.

  • parse_ids (bool) – If True (the default), the FASTA header line will be parsed to build a sequence identifier. This may cause errors on certain files where the IDs are too long (>50 letters). Pass False to generate a LocalId for each BioSeq using a counter. The whole FASTA header line can be accessed as TitleDesc instances of the BioSeq in both cases.

__iter__()#

Implement iter(self).

__reduce__()#

Helper for pickle.

read()#

Read a single sequence if available.

Returns:

BioSeq – The next sequence in the FASTA file, or None if the reader reached the end of the file.