# Bio.SeqIO.Interfaces module

Bio.SeqIO support module (not for general use).

Unless you are writing a new parser or writer for Bio.SeqIO, you should not use this module. It provides base classes to try and simplify things.

class Bio.SeqIO.Interfaces.SequenceIterator(source: IO | PathLike | str | bytes, alphabet: None = None, fmt: str | None = None)

  Bases: `ABC`, `Generic`

  Base class for building SeqRecord iterators.

  You should write a __next__ method that returns the next SeqRecord. You may wish to redefine the __init__ method as well. You must also create a class property modes specifying the allowable file stream modes.

  abstract property modes

    File modes (binary or text) that the parser can handle.

    This property must be “t” (for text mode only), “b” (for binary mode only), “tb” (if both text and binary mode are accepted, but text mode is preferred), or “bt” (if both text and binary mode are accepted, but binary mode is preferred).

  __init__(source: IO | PathLike | str | bytes, alphabet: None = None, fmt: str | None = None) → None

    Create a SequenceIterator object.

    Arguments: - source - input file stream, or path to input file - alphabet - no longer used, should be None - fmt - string, mixed case format name for in error messages

    This method MAY be overridden by any subclass.

    Note when subclassing: - there should be a single non-optional argument, the source. - you do not have to require an alphabet. - you can add additional optional arguments.

  abstractmethod __next__()

    Return the next SeqRecord.

    This method must be implemented by the subclass.

  __iter__()

    Iterate over the entries as a SeqRecord objects.

    Example usage for Fasta files:

        with open("example.fasta","r") as myFile:
            myFastaReader = FastaIterator(myFile)
            for record in myFastaReader:
                print(record.id)
                print(record.seq)

    This method SHOULD NOT be overridden by any subclass.

  __enter__()
  __exit__(exc_type, exc_value, exc_traceback)
  __abstractmethods__ = frozenset({'__next__', 'modes'})
  __annotate_func__ = None
  __annotations_cache__ = {}
  __firstlineno__ = 35
  __orig_bases__ = (<class 'abc.ABC'>, typing.Generic[~AnyStr])
  __parameters__ = (~AnyStr,)
  __static_attributes__ = ('mode', 'source', 'stream')

class Bio.SeqIO.Interfaces.SequenceWriter(target: IO | PathLike | str | bytes)

  Bases: `ABC`, `Generic`

  Base class for sequence writers. This class should be subclassed.

  The user may call the write_file() method to write a complete file containing the sequences.

  Most subclasses will only need to implement the write_record method. Subclasses must implement the write_records method to include a file header or footer, for file formats that only allow one record, or for file formats that cannot be written sequentially.

  abstract property modes

    File modes (binary or text) that the writer can handle.

    This property must be “t” (for text mode only), “b” (for binary mode only), “tb” (if both text and binary mode are accepted, but text mode is preferred), or “bt” (if both text and binary mode are accepted, but binary mode is preferred).

  __init__(target: IO | PathLike | str | bytes) → None

    Create the writer object.

  clean(text: str) → str

    Use this to avoid getting newlines in the output.

  classmethod to_string(record)

    Format the record and return the string.

  write_record(record)

    Write a single record to the output file.

    record - a SeqRecord object

  write_records(records)

    Write records to the output file, and return the number of records.

    records - A list or iterator returning SeqRecord objects

  __abstractmethods__ = frozenset({'modes'})
  __annotate_func__ = None
  __annotations_cache__ = {}
  __firstlineno__ = 155
  __orig_bases__ = (<class 'abc.ABC'>, typing.Generic[~AnyStr])
  __parameters__ = (~AnyStr,)
  __static_attributes__ = ('handle', 'target')
  write_file(records)

    Write a complete file with the records, and return the number of records.

    records - A list or iterator returning SeqRecord objects

Biopython v: 1.86

Versions
  Previous
  Latest
  Develop

Biopython Project
  Homepage
  On GitHub