Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interop printing function with ETE Toolkit #236

Open
PerretB opened this issue Mar 5, 2021 · 1 comment
Open

Interop printing function with ETE Toolkit #236

PerretB opened this issue Mar 5, 2021 · 1 comment
Labels
feature request Feature request

Comments

@PerretB
Copy link
Member

PerretB commented Mar 5, 2021

It could be interesting to add an interface for drawing trees with ETE Toolkit especially for documentation purpose

@PerretB PerretB added the feature request Feature request label Mar 5, 2021
@PerretB
Copy link
Member Author

PerretB commented Mar 30, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Feature request
Projects
None yet
Development

No branches or pull requests

1 participant