[Biopython] saving tree data in phyloXML format

Eric Talevich eric.talevich at gmail.com
Mon Oct 11 13:39:20 UTC 2010


Hi Mike,

Thanks for reporting this. I'll take a closer look at it tonight. A
couple things come to mind:

On Mon, Oct 11, 2010 at 4:29 AM, Michael Thon <mike.thon at gmail.com> wrote:
> I am now reading my trees and creating tree objects.  For each clade in the
> tree I am adding a node_id attribute and one Property object.  When I print
> the tree using:
>
>    print tree
>
> I can see the new information that I've added to the tree.  When I try to
> save the tree in phyloXML format, the node_id attribute and the Property
> object are not serialized. I'm saving the tree like this:
>
>    PhyloXMLIO.write(tree, 'mytree.xml')
>

The serializer expects node_id and url to be instances of the PhyloXML.Id and
PhyloXML.Uri classes, respectively. Were you assigning plain strings to these
attributes?

http://www.biopython.org/DIST/docs/api/Bio.Phylo.PhyloXML.Id-class.html
http://www.biopython.org/DIST/docs/api/Bio.Phylo.PhyloXML.Uri-class.html

Example:

from Bio.Phylo import PhyloXML
# Get a clade...
myclade = mytree.find_any(...)
myclade.node_id = PhyloXML.Id("foo")
myclade.uri = PhyloXML.Uri("http://foo-db.org")
Phylo.write(mytree, "mytree.xml", "phyloxml")

(*untested*)


>
> Basically, what I'm trying to do is decorate the branches in the trees with
> some additional data (a node_id, branch labels, and a url) , and then render
> them in a web page, possibly using jsPhyloSVG (http://www.jsphylosvg.com).
> the examples on that website show <annotation> tags containing <desc> and
> <uri> tags.  I don't see an 'annotation' property in Bio.Phylo.PhyloXML.Clade
> but I'm hoping that there is some other property that maps to <annotation>
> when I save the tree in phyloXML format.


According to phyloxml.org, the "annotation" element goes under Sequence, not
Clade.
http://www.phyloxml.org/documentation/version_1.10/phyloxml.xsd.html#h917087604

I wonder if jsPhyloSVG is relying on each clade having an "annotation" element
for its display. If so, that could get tricky. You might be able to fool
jsPhyloSVG by using the "Other" class in Bio.Phylo.PhyloXML:
http://www.biopython.org/DIST/docs/api/Bio.Phylo.PhyloXML.Other-class.html

Something like:

myclade.other = [PhyloXML.Other("annotation", namespace="", children=[
                    PhyloXML.Other("desc", value="Base of many coffees"),
                    PhyloXML.Other("uri",
value="http://en.wikipedia.org/wiki/Espresso")])]

(*untested*)

Note that the Clade.other attribute is expected to be a list. This is low-level
stuff meant for adding elements outside the phyloXML spec, so if it seems a
little ugly... yes, it is.

Hope that helps,

-Eric



More information about the Biopython mailing list