Question: Make tree a cladogram in ETE2
2
gravatar for moranr
4.2 years ago by
moranr260
Ireland
moranr260 wrote:

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, 

ete python • 2.0k views
ADD COMMENTlink modified 4.2 years ago by jhc2.8k • written 4.2 years ago by moranr260
4
gravatar for jhc
4.2 years ago by
jhc2.8k
Spain
jhc2.8k wrote:

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 COMMENTlink modified 3 months ago by RamRS26k • written 4.2 years ago by jhc2.8k

Excellent, thank you very much.

ADD REPLYlink modified 3 months ago by RamRS26k • written 4.2 years ago by moranr260
0
gravatar for Antonio R. Franco
4.2 years ago by
Spain. Universidad de Córdoba
Antonio R. Franco4.4k wrote:
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 COMMENTlink written 4.2 years ago by Antonio R. Franco4.4k

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 REPLYlink modified 3 months ago by RamRS26k • written 4.2 years ago by moranr260
Please log in to add an answer.

Help
Access

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