Friday, March 22, 2013

More Python issues

This time completely unrelated to Phycas. I've been using Biopython to concatenate several nexus files that share some taxa into one nexus file. This is something I have been doing on my Mac, but I have been attempting this again on my new (to me) PC. After installing Python and Biopython, I tried to run the script with the appropriate modifications for the nexus files I am attempting to combine. I immediately ran into some issues.


getattr(self,'_'+line.command)(line.options)
AttributeError: 'Nexus' object has no attribute '_mitochondrial'']'

Considering my script (below) has no mention of mitochondrial, nor does Nexus.py in the Biopython package, this must be something about the nexus files themselves. When I look in the nexus file, it is divided into a taxa block and a character block. If I combine the two into a single data block and remove all of the information in the taxa block (other than the number of taxa, which I leave in the dimensions of the data block), everything works smoothly!

I don't know if this is related to the Mac/PC switch or whether it was just something about the newer version of Biopython, but I am glad it works.



from Bio.Nexus import Nexus

handles = [open('COI.nex', 'r'), open('cytb.nex','r'), open('RAG1.nex','r')]
  
nexi =  [(handle.name, Nexus.Nexus(handle)) for handle in handles]

combined = Nexus.combine(nexi)
combined.write_nexus_data(filename='COMBINED.nex')

No comments:

Post a Comment