Bio.AlignIO.Interfaces module

AlignIO support module (not for general use).

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

class Bio.AlignIO.Interfaces.AlignmentIterator(handle, seq_count=None)

Bases: object

Base class for building MultipleSeqAlignment iterators.

You should write a next() method to return Alignment objects. You may wish to redefine the __init__ method as well.

__init__(self, handle, seq_count=None)

Create an AlignmentIterator object.

Arguments:
  • handle - input file

  • count - optional, expected number of records per alignment Recommend for fasta file format.

Note when subclassing:
  • there should be a single non-optional argument, the handle, and optional count IN THAT ORDER.

  • you can add additional optional arguments.

__next__(self)

Return the next alignment in the file.

This method should be replaced by any derived class to do something useful.

__iter__(self)

Iterate over the entries as MultipleSeqAlignment objects.

Example usage for (concatenated) PHYLIP files:

with open("many.phy","r") as myFile:
    for alignment in PhylipIterator(myFile):
        print("New alignment:")
        for record in alignment:
            print(record.id)
            print(record.seq)
class Bio.AlignIO.Interfaces.AlignmentWriter(handle)

Bases: object

Base class for building MultipleSeqAlignment writers.

You should write a write_alignment() method. You may wish to redefine the __init__ method as well.

__init__(self, handle)

Initialize the class.

write_file(self, alignments)

Use this to write an entire file containing the given alignments.

Arguments:
  • alignments - A list or iterator returning MultipleSeqAlignment objects

In general, this method can only be called once per file.

This method should be replaced by any derived class to do something useful. It should return the number of alignments..

clean(self, text)

Use this to avoid getting newlines in the output.

class Bio.AlignIO.Interfaces.SequentialAlignmentWriter(handle)

Bases: Bio.AlignIO.Interfaces.AlignmentWriter

Base class for building MultipleSeqAlignment writers.

This assumes each alignment can be simply appended to the file. You should write a write_alignment() method. You may wish to redefine the __init__ method as well.

__init__(self, handle)

Initialize the class.

write_file(self, alignments)

Use this to write an entire file containing the given alignments.

Arguments:
  • alignments - A list or iterator returning MultipleSeqAlignment objects

In general, this method can only be called once per file.

write_header(self)

Use this to write any header.

This method should be replaced by any derived class to do something useful.

Use this to write any footer.

This method should be replaced by any derived class to do something useful.

write_alignment(self, alignment)

Use this to write a single alignment.

This method should be replaced by any derived class to do something useful.