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
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
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")
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Excellent, thank you very much.