Revision as of 16:24, 14 May 2008

This page describes Bio.AlignIO, a new multiple sequence Alignment Input/Output interface for BioPython which is currently only in our source code repository. It should be included in the next release of Biopython.

Contents

Aims

You may already be familiar with the Bio.SeqIO module which deals with files containing one or more sequences represented as SeqRecord objects. The purpose of the SeqIO module is to provide a simple uniform interface to assorted file formats.

Similarly, Bio.AlignIO deals with files containing one or more sequence alignments represented as Alignment objects. Bio.AlignIO uses the same set of functions for input and output as in Bio.SeqIO, and the same names for the file formats supported.

Note that the inclusion of Bio.AlignIO does lead to some duplication or choice in how to deal with some file formats. For example, Bio.SeqIO and Bio.Clustalw will both read sequences from Clustal files - but Bio.Clustalw also includes a command line wrapper to call the program.

My vision is that for manipulating sequence alignments you should try Bio.AlignIO as your first choice. In some cases you may only care about the sequences themselves, in which case try using Bio.SeqIO on the alignment file directly. Unless you have some very specific requirements, I hope this should suffice.

Peter

File Formats

This table lists the file formats that Bio.SeqIO can read and write. The format name is a simple lowercase string. Where possible we use the same name as BioPerl's SeqIO and EMBOSS.

Table 1: Bio.AlignIO supported file formats

Format name

Reads

Writes

Notes

fasta

Yes

Yes

This refers to the input file format introduced for Bill Pearson's FASTA tool, where each record starts with a ">" line. Note that storing more than one alignment in this format is ambiguous.

clustal

Yes

Yes

See also Bio.Clustalw for calling the command line tool.

emboss

Yes

Soon...

The EMBOSS simple/pairs alignment format.

nexus

Yes

No

Also known as PAUP format. Uses Bio.Nexus

phylip

Yes

Yes

Truncates names at 10 characters.

stockholm

Yes

Yes

Also known as PFAM format.

In addition, you can store the (gapped) sequences from an alignment in any of the file formats supported by Bio.SeqIO. The most common example of this is storing multiple alignments in the simple fasta format. However, storing more than one alignment in a single such file is ambiguous - see the section below on alignment input.

Alignment Input

As in Bio.SeqIO, there are two functions for alignment input. These are Bio.AlignIO.read() for when the file contains one and only one alignment, and the more general Bio.AlignIO.parse() when the file may contain multiple separate alignments.

Both these functions have two required arguments, a file handle and a file format. As with Bio.SeqIO, Biopython insists that you explicitly give the expected file format, rather than attempting to guess this based on the filename or contents. The file format is specified as a lower case string, see the table above.

As an example, we'll look at a PFAM seed alignment for the Fibrinogen gamma chain PF09395 Fib_gamma. At the time of writing, this contained 14 sequences with an alignment length of 77 amino acids, and is shown below in the PFAM or Stockholm format:

You will notice that there is plenty of annotation information here, including accession numbers for each sequence and also some PDB database cross-references and secondary structure information for the human and chick fibrinogen proteins.

This file contains a single alignment, so we can use the Bio.AlignIO.read() function to load it in Biopython. Let's assume you have downloaded this alignment from Sanger, or have copy and pasted the text above, and saved this as a file called PF09395_seed.sth on your computer. Then in python: