Package Bio :: Package SeqIO :: Module NexusIO
[hide private]
[frames] | no frames]

Source Code for Module Bio.SeqIO.NexusIO

 1  # Copyright 2006 by Peter Cock.  All rights reserved. 
 2  # This code is part of the Biopython distribution and governed by its 
 3  # license.  Please see the LICENSE file that should have been included 
 4  # as part of this package. 
 5   
 6  from Bio.Seq import Seq 
 7  from Bio.SeqRecord import SeqRecord 
 8  from Bio.Nexus import Nexus 
 9   
10  #You can get a couple of example files here: 
11  #http://www.molecularevolution.org/resources/fileformats/ 
12       
13  #This is a generator function! 
14 -def NexusIterator(handle) :
15 """Returns SeqRecord objects from a Nexus file 16 17 Thus uses the Bio.Nexus module to do the hard work.""" 18 n = Nexus.Nexus(handle) 19 for id in n.original_taxon_order : 20 if id in n.matrix : 21 seq = n.matrix[id] 22 else : 23 #Missing the sequence? 24 seq = Seq("", n.alphabet) 25 #ToDo - Can we extract any annotation too? 26 yield SeqRecord(seq, id=id, name=id, description="") 27 #All done 28 return
29