This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Make tree a cladogram in ETE2

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

2 answers

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

Excellent, thank you very much.

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

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.

Log in to answer this question.