Ultrametric tree in ete3 (python)
1
Hi all,
does anyone know how to check if a tree has been correctly converted to ultrametric with ete3 in python? Kinda like the is.ultrametric() function of the R ape package?
Thanks!
phylogeny
python
• 2.8k views
try something like this:
from ete3 import Tree
def is_ultrametric(tree):
last_distance = None
distance = 0
for post, node in tree.iter_prepostorder():
if post:
distance -= node.dist
else:
if not node.is_leaf():
distance += node.dist
else:
if last_distance is None:
print(last_distance)
last_distance = distance + node.dist
elif last_distance != distance + node.dist:
return False, last_distance
return True, last_distance
t = Tree('((a:1,(b:0.5, d:0.5):0.5):1,c:2);')
print(is_ultrametric(t))
t = Tree()
t.populate(10, random_branches=True)
print(is_ultrametric(t))
•
link
6.9 years ago by
jhc
★
3.0k
Login before adding your answer.
Thanks, so there is not existing method. It would be a good idea to add one I guess.