[Biopython-dev] Bio.AlignIO, Bio.Nexus, MrBayes, polymorphic sites, maximum line length

Nick Loman n.j.loman at bham.ac.uk
Thu Dec 2 15:27:06 UTC 2010


Cymon Cox wrote:
> Note, "interleave" on the format line. Also beware that some Nexus parsers
> don't check that taxa in additional blocks are in the same order as the
> first block - they just assume they are.
>
> You can write interleaved Nexus formatted data with
> Nexus.write_nexus_data(interleave_by_partition=True) provide you have a
> character partition set.
>   
Hi Cymon

Thanks for that - this would be a useful workaround, however 
unfortunately I am combining a bunch of alignments a la:

from Bio.Nexus import Nexus
import sys
handles = [open(fh) for fh in sys.argv[2:]]
nexi = [(handle.name, Nexus.Nexus(handle)) for handle in handles]
combined = Nexus.combine(nexi)
combined.write_nexus_data(filename=sys.argv[1])

I was hoping perhaps this might set up the partitions for me for each 
alignment which is merged.

However, if I use:
combined.write_nexus_data(filename=sys.argv[1], 
interleave_by_partition=True)

I get the following error:

Traceback (most recent call last):
  File "combine_alignments.py", line 11, in <module>
    combined.write_nexus_data(filename=sys.argv[1], 
interleave_by_partition=True)
  File "Bio/Nexus/Nexus.py", line 1275, in write_nexus_data
    raise NexusError('Unknown partition: '+interleave_by_partition)
TypeError: cannot concatenate 'str' and 'bool' objects

Which suggests that combine does not add partitions for each alignment. 
I could of course work around this with extra code.

Regards,

Nick.




More information about the Biopython-dev mailing list