Package Bio :: Package AlignIO :: Module FastaIO :: Class FastaM10Iterator
[hide private]
[frames] | no frames]

Class FastaM10Iterator

source code

Interfaces.AlignmentIterator --+
                               |
                              FastaM10Iterator

Alignment iterator for the FASTA tool's pairwise alignment output.

This is for reading the pairwise alignments output by Bill Pearson's
FASTA program when called with the -m 10 command line option for machine
readable output.  For more details about the FASTA tools, see the website
http://fasta.bioch.virginia.edu/ and the paper:

     W.R. Pearson & D.J. Lipman PNAS (1988) 85:2444-2448

This class is intended to be used via the Bio.AlignIO.parse() function
by specifying the format as "fasta-m10" as shown in the following code:

    from Bio import AlignIO
    handle = ...
    for a in AlignIO.parse(handle, "fasta-m10"):
        assert len(a.get_all_seqs()) == 2, "Should be pairwise!"
        print "Alignment length %i" % a.get_alignment_length()
        for record in a:
            print record.seq, record.name, record.id

Note that this is not a full blown parser for all the information
in the FASTA output - for example, most of the header and all of the
footer is ignored.  Also, the alignments are not batched according to
the input queries.

Also note that there can be up to about 30 letters of flanking region
included in the raw FASTA output as contextual information.  This is NOT
part of the alignment itself, and is not included in the resulting
Alignment objects returned.

Instance Methods [hide private]
 
next(self)
Reads from the handle to construct and return the next alignment.
source code
 
_skip_file_header(self, line)
Helper function for the main parsing code.
source code
 
_parse_query_header(self, line)
Helper function for the main parsing code.
source code
 
_extract_alignment_region(self, alignment_seq_with_flanking, annotation)
Helper function for the main parsing code.
source code
 
_parse_tag_section(self, line, dictionary)
Helper function for the main parsing code.
source code

Inherited from Interfaces.AlignmentIterator: __init__, __iter__

Method Details [hide private]

next(self)

source code 

Reads from the handle to construct and return the next alignment.

This returns the pairwise alignment of query and match/library sequences as an Alignment object containing two rows.

Overrides: Interfaces.AlignmentIterator.next

_skip_file_header(self, line)

source code 

Helper function for the main parsing code.

Skips over the file header region.

_parse_query_header(self, line)

source code 

Helper function for the main parsing code.

Skips over the free format query header, extracting the tagged parameters.

If there are no hits for the current query, it is skipped entirely.

_extract_alignment_region(self, alignment_seq_with_flanking, annotation)

source code 

Helper function for the main parsing code.

To get the actual pairwise alignment sequences, we must first translate the un-gapped sequence based coordinates into positions in the gapped sequence (which may have a flanking region shown using leading - characters). To date, I have never seen any trailing flanking region shown in the m10 file, but the following code should also cope with that.

Note that this code seems to work fine even when the "sq_offset" entries are prsent as a result of using the -X command line option.

_parse_tag_section(self, line, dictionary)

source code 
Helper function for the main parsing code.

line - supply line just read from the handle containing the start of
       the tagged section.
dictionary - where to record the tagged values

Returns a string, the first line following the tagged section.