Make tree a cladogram in ETE2
2
2
Entering edit mode
8.9 years ago
moranr ▴ 290

Hi,

Is there any way to force the tree to look like a cladogram in ETE?

I can make the tree I want , but now I just want to add the style of the tree to have aligned branches the terminate at the same point.

Thanks

python ete • 3.9k views
ADD COMMENT
4
Entering edit mode
8.9 years ago
jhc ★ 3.0k

You need to convert the tree into ultrametric. ETE allows to do this with the tree.convert_to_ultrametric() method, which balances all branches in the tree to meet a given tree length. However, you can use a very simple strategy to add an extra offset to only leaf nodes so the rest of the tree conserves original branch distances.

from ete3 import Tree

#create a random tree
t = Tree()
t.populate(25, random_branches=True)

# prevent using labels and symbols in internal nodes
for n in t.traverse():
    n.img_style["size"] = 0
    n.img_style["vt_line_width"] = 0
t.render("regular.png")

#Convert to ultrametric
most_distant_leaf, tree_length = t.get_farthest_leaf()
current_dist = 0
for postorder, node in t.iter_prepostorder():
    if postorder:
        current_dist -= node.dist
    else:
        if node.is_leaf():
            node.dist += tree_length - (current_dist + node.dist)
        elif node.up: # node is internal
            current_dist += node.dist
t.render("ultrametric.png")

ADD COMMENT
0
Entering edit mode

Excellent, thank you very much.

ADD REPLY
0
Entering edit mode
8.9 years ago
Look for the Program FigTree It is written in Java and it is likely can do that for you. It depends of the type of data and their format
ADD COMMENT
0
Entering edit mode

Thanks, but I am aware of figTree, my problem is that I am creating a tree with ETE as it can do things FigTree cannot. This needs to be a python based solution.

ADD REPLY

Login before adding your answer.

Traffic: 2098 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