Skip to content

Commit

Permalink
improve autopruning by finding lca
Browse files Browse the repository at this point in the history
  • Loading branch information
dengzq1234 committed Apr 3, 2024
1 parent 6055db3 commit 25dd68b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion treeprofiler/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,21 @@ def ete4_parse(newick, internal_parser="name"):
# pruning
def taxatree_prune(tree, rank_limit='subspecies'):
for node in tree.traverse("preorder"):
if node.props.get('rank') == rank_limit:
rank = node.props.get('rank')
if rank == rank_limit:
children = node.children.copy()
for ch in children:
print("prune", ch.name)
remove(ch)
lca_dict = node.props.get('lca')
if lca_dict:
lca = lca_dict.get(rank_limit, None)
if lca:
node.name = lca
children = node.children.copy()
for ch in children:
print("prune", ch.name)
remove(ch)
return tree

def conditional_prune(tree, conditions_input, prop2type):
Expand Down

0 comments on commit 25dd68b

Please sign in to comment.