[Biopython] Adding phyloxml colors to newick trees

Aaron Gallagher agallagh at fhcrc.org
Tue Apr 19 18:20:50 EDT 2011


So, I'm trying to add colors to a phylogenetic tree when writing it out in
phyloxml format. It's being originally loaded from Newick format, which seems
to be causing problems. This doesn't raise any errors, but the output doesn't
contain any coloring:

    tree = Phylo.read(..., 'newick')
    tree.root.color = BranchColor(255, 0, 0)
    Phylo.write(tree, ..., 'phyloxml')

This, however, does include coloring in the output:
    
    sio = StringIO()
    Phylo.convert(..., 'newick', sio, 'phyloxml')
    sio.seek(0)
    tree = Phylo.read(sio, 'phyloxml')
    tree.root.color = BranchColor(255, 0, 0)
    Phylo.write(tree, ..., 'phyloxml')

Is there any way to do this conversion on-the-fly with an already-loaded tree
instead of having to convert it via a StringIO (or temporary file) ?

Thanks in advance,
Aaron



More information about the Biopython mailing list