Open PerretB opened 3 years ago
Simple POC for partition hierarchy
def hierarchy_to_ete_tree(tree, altitudes=None, **attributes):
ete_tree = ete.Tree()
stack = [(tree.root(), ete_tree)]
if altitudes is not None:
altitudes = altitudes[tree.parents()] - altitudes
while len(stack) != 0:
node, ete_node = stack.pop()
[ete_node.name](http://ete_node.name/) = str(node)
if altitudes is not None:
ete_node.dist = altitudes[node]
attr = {name:values[node] for (name,values) in attributes.items()}
ete_node.add_features(**attr)
for c in tree.children(node):
stack.append((c, ete_node.add_child()))
return ete_tree
tree = hg.Tree((7, 7, 8, 8, 8, 9, 9, 11, 10, 10, 11, 11))
altitudes = hg.attribute_regular_altitudes(tree)
t = hierarchy_to_ete_tree(tree, altitudes)
print(t)
t.render("img.png")
t.show()
It could be interesting to add an interface for drawing trees with ETE Toolkit especially for documentation purpose