Question: Displaying tree with attributes as Image with ETE3
gravatar for moranr
3.8 years ago by
moranr250 wrote:


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 ? 



python ete phylogenetics ete3 • 2.1k views
ADD COMMENTlink modified 2.9 years ago by Biostar ♦♦ 20 • written 3.8 years ago by moranr250
gravatar for jhc
3.8 years ago by
jhc2.8k wrote:

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")


ADD COMMENTlink modified 3.8 years ago • written 3.8 years ago by jhc2.8k

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") ?



ADD REPLYlink written 3.8 years ago by moranr250

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

ADD REPLYlink written 3.8 years ago by jhc2.8k

Great, thank you. 

ADD REPLYlink written 3.8 years ago by moranr250

@jhc can you take a look at this if you get a chance:

ADD REPLYlink written 3.1 years ago by O.rka120

check answer her:

ADD REPLYlink written 3.1 years ago by jhc2.8k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1589 users visited in the last hour