Last active
September 14, 2017 08:25
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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