[Biopython] Unable to convert alignment to nexus format

Brad Chapman chapmanb at 50mail.com
Thu Aug 11 13:52:38 UTC 2011


Morten;

> I am getting an exception when trying to output an alignment in nexus
> format:
> 
>   ValueError: Need a DNA, RNA or Protein alphabet
> 
> The alignment is read by AlignIO.read() in fasta format from an output
> file written by Muscle, and so the alphabet specified in the sequences
> is IUPACProtein. Apparently, NexusIO checks for ProteinAlphabet and thus
> fails. I am using BioPython 1.56.

If you specify the alphabet to AlignIO, Nexus will be happy. Here's
your modified test program:

from Bio import AlignIO
from Bio.Alphabet import IUPAC, Gapped
alignment = AlignIO.read(open("aln.muscle"), "fasta", alphabet=Gapped(IUPAC.protein))
g = open("aln.nexus", "w")
g.write (alignment.format("nexus"))

Hope this helps,
Brad



More information about the Biopython mailing list