Displaying tree with attributes as Image with ETE3
1
2
Entering edit mode
9.0 years ago
moranr ▴ 290

Hi,

I want to print a tree with selected attributes using ete3 in python using a Newick (with NHX annotations) file e.g. :

(dog[&&NHX:Genes=3:Identical=3:Duplicated=0:Lost=0:Novel=0:Singleton=0], ((mouse2[&&NHX:Genes=19:Identical=19:Duplicated=0:Lost=0:Novel=0:Singleton=0], mouse[&&NHX:Genes=21:Identical=17:Duplicated=4:Lost=0:Novel=0:Singleton=0])mouse_mouse2[&&NHX:Genes=19:Identical=9:Duplicated=0:Lost=1:Novel=10:Singleton=0], human[&&NHX:Genes=9:Identical=9:Duplicated=0:Lost=1:Novel=0:Singleton=0])"human/mouse/mouse2"[&&NHX:Genes=10:Identical=3:Duplicated=0:Lost=0:Novel=7:Singleton=0])LUCA[&&NHX:Genes=3];

I can print an ascii tree like so:

    /-dog, 3, 0, 0, 0
   |
-LUCA                                           /-mouse2, 19, 0, 0, 0
   |                              /mouse_mouse2, 9, 0, 1, 0
    \"human/mouse/mouse2", 3, 0, 0, 0           \-mouse, 17, 4, 0, 0
                                  |
                                   \-human, 9, 0, 1, 0

Is there a way to do this as a phylogenetic tree image e.g. using the TreeStyle() function?

Thanks.

python ete phylogenetics ete3 • 4.5k views
ADD COMMENT
4
Entering edit mode
9.0 years ago
jhc ★ 3.0k

Yes, each graphical feature associated to a node is called a Node Face. You can add any number of faces to each node, and you can control de position of each face relative to its node. Then call the tree.render(...) function to get an image. There are many type of faces and parameters to customize the image, check this part of the tutorial

A very simple example would like this:

from ete3 import Tree, TextFace, AttrFace
tree = Tree("((A, B), C);")
nodeA = tree & ("A")
nodeAB = tree.get_common_ancestor("A", "B")
nodeA.add_face(TextFace("mouse"), column=1, position="branch-right")
nodeA.add_face(TextFace("/human"), column=2, position="branch-right")
nodeAB.add_face(TextFace("mouse"), column=0, position="branch-top")
nodeAB.add_face(TextFace("/mouse"), column=1, position="branch-top")
nodeAB.add_face(AttrFace("dist", text_prefix="/"), column=2, position="branch-top")
tree.render("tree.png")
ADD COMMENT
0
Entering edit mode

Thanks, I do think this is a good place to start and it answers my question.

However, a problem: How can this be done iteratively for a very big tree. I want to display this at each node of the tree.

Can I simply just recurse over each node and at that node say n.add_face(AttrFace("dist", text_prefix="/"), column=2, position="branch-top")?

Thanks,

ADD REPLY
2
Entering edit mode

yes, iter over nodes and add as many faces as you want. Faces in the same column will be stacked.

ADD REPLY
0
Entering edit mode

Great, thank you.

ADD REPLY
0
Entering edit mode
ADD REPLY
1
Entering edit mode
ADD REPLY

Login before adding your answer.

Traffic: 2279 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6