gravatar for a.zielezinski

1 hour ago by

In Python you can use ete3 package.

import ete3

YOUR_TREE = '((raccoon:19.19959,bear:6.80041):0.84600,((sea_lion:11.99700, seal:12.00300):7.52973,((monkey:100.85930,cat:47.14069):20.59201, weasel:18.87953):2.09460):3.87382,dog:25.46154);'
YOUR_QUERY = 'weasel'

t = ete3.Tree(YOUR_TREE)
node = t.search_nodes(name=YOUR_QUERY)[0]
closest_leaves = node.up.get_leaves()
for leaf in closest_leaves:
    if leaf != node:
        printleaf.name)

You will get the names of leaves that are closest to weasel (i.e., monkey and cat).



Source link