New in version 2.1.

PhyloXML

PhyloXML (http://www.phyloxml.org/) is a novel standard used to encode phylogenetic information. In particular, phyloXML is designed to describe phylogenetic trees (or networks) and associated data, such as taxonomic information, gene names and identifiers, branch lengths, support values, and gene duplication and speciation events.

Loading PhyloXML projects from files

ETE provides full support for phyloXML projects through the Phyloxml object. Phylogenies are integrated as ETE’s tree data structures as PhyloxmlTree instances, while the rest of features are represented as simple classes (ete2.phyloxml) providing basic reading and writing operations.

from ete2 import Phyloxml
project = Phyloxml()
project.build_from_file("apaf.xml")

# Each tree contains the same methods as a PhyloTree object
for tree in project.get_phylogeny():
    print tree
    # you can even use rendering options
    tree.show()
    # PhyloXML features are stored in the phyloxml_clade attribute
    for node in tree: 
        print "Node name:", node.name
        for seq in node.phyloxml_clade.get_sequence(): 
            for domain in seq.domain_architecture.get_domain():
                domain_data = [domain.valueOf_, domain.get_from(), domain.get_to()]
                print "  Domain:", '\t'.join(map(str, domain_data))

[Download script] [Download example]

Each tree node contains two phyloxml elements, phyloxml_clade and phyloxml_phylogeny. The first attribute contains clade information referred to the node, while phyloxml_phylogeny contains general data about the subtree defined by each node. This way, you can split, or copy any part of a tree and it will be exported as a separate phyloxml phylogeny instance.

Note that node.dist, node.support and node.name features are linked to node.phyloxml_clade.branch_length, node.phyloxml_clade.confidence and node.phyloxml_clade.name, respectively.

Creating PhyloXML projects from scratch

In order to create new PhyloXML projects, a set of classes is available in the ete2.phyloxml module.

from ete2 import Phyloxml, phyloxml
import random 
project = Phyloxml()

# Creates a random tree
phylo = phyloxml.PhyloxmlTree()
phylo.populate(5, random_branches=True)
phylo.phyloxml_phylogeny.set_name("test_tree")
# Add the tree to the phyloxml project
project.add_phylogeny(phylo)

print project.get_phylogeny()[0]

#          /-iajom
#     /---|
#    |     \-wiszh
#----|
#    |     /-xrygw
#     \---|
#         |     /-gjlwx
#          \---|
#               \-ijvnk

# Trees can be operated as normal ETE trees
phylo.show()


# Export the project as phyloXML format
project.export()

# <phy:Phyloxml xmlns:phy="http://www.phyloxml.org/1.10/phyloxml.xsd">
#     <phy:phylogeny>
#         <phy:name>test_tree</phy:name>
#         <phy:clade>
#             <phy:name>NoName</phy:name>
#             <phy:branch_length>0.000000e+00</phy:branch_length>
#             <phy:confidence type="branch_support">1.0</phy:confidence>
#             <phy:clade>
#                 <phy:name>NoName</phy:name>
#                 <phy:branch_length>1.665083e-01</phy:branch_length>
#                 <phy:confidence type="branch_support">0.938507980435</phy:confidence>
#                 <phy:clade>
#                     <phy:name>NoName</phy:name>
#                     <phy:branch_length>1.366655e-01</phy:branch_length>
#                     <phy:confidence type="branch_support">0.791888248212</phy:confidence>
#                     <phy:clade>
#                         <phy:name>ojnfg</phy:name>
#                         <phy:branch_length>2.194209e-01</phy:branch_length>
#                         <phy:confidence type="branch_support">0.304705977822</phy:confidence>
#                     </phy:clade>
#                     <phy:clade>
#                         <phy:name>qrfnz</phy:name>
#                         <phy:branch_length>5.235437e-02</phy:branch_length>
#                         <phy:confidence type="branch_support">0.508533765418</phy:confidence>
#                     </phy:clade>
#                 </phy:clade>
#                 <phy:clade>
#                     <phy:name>shngq</phy:name>
#                     <phy:branch_length>9.740958e-01</phy:branch_length>
#                     <phy:confidence type="branch_support">0.642187390965</phy:confidence>
#                 </phy:clade>
#             </phy:clade>
#             <phy:clade>
#                 <phy:name>NoName</phy:name>
#                 <phy:branch_length>3.806412e-01</phy:branch_length>
#                 <phy:confidence type="branch_support">0.383619811911</phy:confidence>
#                 <phy:clade>
#                     <phy:name>vfmnk</phy:name>
#                     <phy:branch_length>6.495163e-01</phy:branch_length>
#                     <phy:confidence type="branch_support">0.141298879514</phy:confidence>
#                 </phy:clade>
#                 <phy:clade>
#                     <phy:name>btexi</phy:name>
#                     <phy:branch_length>5.704955e-01</phy:branch_length>
#                     <phy:confidence type="branch_support">0.951876078012</phy:confidence>
#                 </phy:clade>
#             </phy:clade>
#         </phy:clade>
#     </phy:phylogeny>
# </phy:Phyloxml>

[Download script]