Skip to content

Commit 25dd68b

Browse files
committed
improve autopruning by finding lca
1 parent 6055db3 commit 25dd68b

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

treeprofiler/src/utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,21 @@ def ete4_parse(newick, internal_parser="name"):
204204
# pruning
205205
def taxatree_prune(tree, rank_limit='subspecies'):
206206
for node in tree.traverse("preorder"):
207-
if node.props.get('rank') == rank_limit:
207+
rank = node.props.get('rank')
208+
if rank == rank_limit:
208209
children = node.children.copy()
209210
for ch in children:
210211
print("prune", ch.name)
211212
remove(ch)
213+
lca_dict = node.props.get('lca')
214+
if lca_dict:
215+
lca = lca_dict.get(rank_limit, None)
216+
if lca:
217+
node.name = lca
218+
children = node.children.copy()
219+
for ch in children:
220+
print("prune", ch.name)
221+
remove(ch)
212222
return tree
213223

214224
def conditional_prune(tree, conditions_input, prop2type):

0 commit comments

Comments
 (0)