[BioPython] Generating Nexus file from Genbank file
Åsmund Skjæveland
asmund.skjaveland at usit.uio.no
Mon Jun 12 15:45:26 UTC 2006
I have a file of Genbank records, and want to extract some of them and
save to a Nexus file. As far as I can tell from the API, this should work:
#!/site/compython/Linux/bin/python
import Bio, sys, time
from Bio.GenBank import Iterator
from Bio.Nexus.Nexus import Nexus
gbfile='results/sequences-txid34828.genbank'
fp = Bio.GenBank.FeatureParser()
gb = open(gbfile, 'r')
it = Bio.GenBank.Iterator(gb, fp)
nex = Nexus()
nr = 0;
rec = it.next()
while rec:
# A string to identify the sequence with
nexusname=rec.features[0].qualifiers['db_xref'][0] + '--' + rec.name
nex.add_sequence(nexusname, rec.seq)
rec = it.next()
print "\n\n%d records, %d gene names" % (nr, len(genenames))
nex.write_nexus_data('results/genegrab.nex', mrbayes=True)
But it doesn't. When I run it:
Traceback (most recent call last):
File "py_nexustest.py", line 39, in ?
nex.add_sequence(nexusname, rec.seq)
File
"/site/compython/Linux/lib/python2.4/site-packages/Bio/Nexus/Nexus.py",
line 1412, in add_sequence
self.matrix[name]=Seq(sequence,self.alphabet)
AttributeError: 'Nexus' object has no attribute 'alphabet'
What am I doing wrong? I don't really know the Nexus format, I just want
to send certain sequences to MrBayes.
--
Åsmund Skjæveland {
Scientific Computing Group, UiO;
}
More information about the Biopython
mailing list