网页
综合
更新时间 2026-11-14 16:59:30
The module for multiple sequence alignments, AlignIO · Biopython
自动蜘蛛
biopython.org
正文约 4085 字
Python Tools for Computational Molecular Biology
This page describes Bio.AlignIO, a new multiple sequence Alignment Input/Output interface for BioPython 1.46 and later.
In addition to the built in API documentation, there is a whole chapter in the Tutorial on Bio.AlignIO, and although there is some overlap it is well worth reading in addition to this page. There is also the API documentation (which you can read online, or from within Python with the help() command).
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 sequence 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.AlignIO and Bio.Nexus will both read alignments from NEXUS files - but Bio.NEXUS allows more control and the use of trees.
My vision is that for reading or writing 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.
This table lists the file formats that Bio.AlignIO can read and write, with the Biopython version where this was first supported.
The format name is a simple lowercase string, matching the names used in Bio.SeqIO. Where possible we use the same name as BioPerl’s SeqIO and EMBOSS.
In addition, you can store the (gapped) sequences from an alignment in many of the file formats supported by Bio.SeqIO. The most common example of this is storing alignments in the simple fasta format. However, storing more than one alignment in a single such file is ambiguous - and this is not recommended.
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:
As in Bio.SeqIO, there is a single output function Bio.AlignIO.write(). This takes three arguments: some alignments, a file handle to write to, and the format to use.
You can use the format function to turn the alignment into a string containing the alignment in the specified file format, e.g.
Or using an f-string:
Please refer to the Bio.AlignIO chapter in the Tutorial for more details.
Suppose you have a file containing PHYLIP alignment(s) that you want to convert into the PFAM/Stockholm format:
By changing the format strings, that code could be used to convert between any supported file formats.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。