Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from Bio import Phylo
'''
I want to get a dictionary where the keys are every leaf name
and the value is the parental (internal) node of that leaf
'''
tree = Phylo.read(tree_handle, 'newick')
res_dict = {}
for node in tree.find_clades():
## if the node is a leaf, the name will be in node.name
## if the node is internal, the name will be node.confidence
print node.name, node.confidence
## iterate through the descendet clades (should only be 2)
for c in node.clades:
## if one of them is a leaf aka terminal
if c.is_terminal():
## print leaf name and parent node
print c, node.confidence
assert c not in res_dict
res_dict[c] = node.confidence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.