Bio.Align.interfaces module

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

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

class Bio.Align.interfaces.AlignmentIterator(source, mode='t', fmt=None)

Bases: abc.ABC

Base class for building Alignment iterators.

You should write a parse method that returns an Alignment generator. You may wish to redefine the __init__ method as well.

__init__(source, mode='t', fmt=None)

Create an AlignmentIterator object.

Arguments: - source - input file stream, or path to input file

This method MAY be overridden by any subclass.

Note when subclassing: - there should be a single non-optional argument, the source. - you can add additional optional arguments.

__next__()

Return the next entry.

__iter__()

Iterate over the entries as Alignment objects.

This method SHOULD NOT be overridden by any subclass. It should be left as is, which will call the subclass implementation of __next__ to actually parse the file.

__abstractmethods__ = frozenset({'_read_next_alignment'})
class Bio.Align.interfaces.AlignmentWriter(target, mode='w')

Bases: object

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

It is intended for sequential file formats with an (optional) header, one or more alignments, and an (optional) footer.

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

Alternatively, users may call the write_header(), followed by multiple calls to format_alignment() and/or write_alignments(), followed finally by write_footer().

Note that write_header() cannot require any assumptions about the number of alignments.

__init__(target, mode='w')

Create the writer object.

write_header(alignments)

Write the file header to the output file.

Write the file footer to the output file.

format_alignment(alignment)

Format a single alignment as a string.

alignment - an Alignment object

write_alignments(alignments)

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

alignments - A list or iterator returning Alignment objects

write_file(alignments)

Write a file with the alignments, and return the number of alignments.

alignments - A list or iterator returning Alignment objects