Back to index

python-biopython  1.60
Classes | Functions | Variables
Bio.AlignIO.NexusIO Namespace Reference

Classes

class  NexusWriter

Functions

def NexusIterator

Variables

tuple handle = StringIO("""#NEXUS [TITLE: NoName] begin data; dimensions ntax=4 nchar=50; format interleave datatype=protein gap=- symbols="FSTNKEYVQMCLAWPHDRIG"; matrix CYS1_DICDI -----MKVIL LFVLAVFTVF VSS------- --------RG IPPEEQ---- ALEU_HORVU MAHARVLLLA LAVLATAAVA VASSSSFADS NPIRPVTDRA ASTLESAVLG CATH_HUMAN ------MWAT LPLLCAGAWL LGV------- -PVCGAAELS VNSLEK---- CYS1_DICDI -----MKVIL LFVLAVFTVF VSS------- --------RG IPPEEQ---X ; end; """)

Function Documentation

def Bio.AlignIO.NexusIO.NexusIterator (   handle,
  seq_count = None 
)
Returns SeqRecord objects from a Nexus file.

Thus uses the Bio.Nexus module to do the hard work.

You are expected to call this function via Bio.SeqIO or Bio.AlignIO
(and not use it directly).

NOTE - We only expect ONE alignment matrix per Nexus file,
meaning this iterator will only yield one MultipleSeqAlignment.

Definition at line 28 of file NexusIO.py.

00028 
00029 def NexusIterator(handle, seq_count=None):
00030     """Returns SeqRecord objects from a Nexus file.
00031 
00032     Thus uses the Bio.Nexus module to do the hard work.
00033 
00034     You are expected to call this function via Bio.SeqIO or Bio.AlignIO
00035     (and not use it directly).
00036 
00037     NOTE - We only expect ONE alignment matrix per Nexus file,
00038     meaning this iterator will only yield one MultipleSeqAlignment.
00039     """
00040     n = Nexus.Nexus(handle)
00041     if not n.matrix:
00042         #No alignment found
00043         raise StopIteration
00044 
00045     #Bio.Nexus deals with duplicated names by adding a '.copy' suffix.
00046     #The original names and the modified names are kept in these two lists:
00047     assert len(n.unaltered_taxlabels) == len(n.taxlabels)
00048     
00049     if seq_count and seq_count != len(n.unaltered_taxlabels):
00050         raise ValueError("Found %i sequences, but seq_count=%i" \
00051                % (len(n.unaltered_taxlabels), seq_count))
00052 
00053     #ToDo - Can we extract any annotation too?
00054     records = (SeqRecord(n.matrix[new_name], id=new_name, \
00055                          name=old_name, description="") \
00056                for old_name, new_name \
00057                in zip (n.unaltered_taxlabels, n.taxlabels))
00058     #All done
00059     yield MultipleSeqAlignment(records, n.alphabet)


Variable Documentation

tuple Bio.AlignIO.NexusIO.handle = StringIO("""#NEXUS [TITLE: NoName] begin data; dimensions ntax=4 nchar=50; format interleave datatype=protein gap=- symbols="FSTNKEYVQMCLAWPHDRIG"; matrix CYS1_DICDI -----MKVIL LFVLAVFTVF VSS------- --------RG IPPEEQ---- ALEU_HORVU MAHARVLLLA LAVLATAAVA VASSSSFADS NPIRPVTDRA ASTLESAVLG CATH_HUMAN ------MWAT LPLLCAGAWL LGV------- -PVCGAAELS VNSLEK---- CYS1_DICDI -----MKVIL LFVLAVFTVF VSS------- --------RG IPPEEQ---X ; end; """)

Definition at line 137 of file NexusIO.py.