Skip to content

Commit

Permalink
Merge pull request #732 from etetoolkit/ete4_tutorial_taxa
Browse files Browse the repository at this point in the history
only take leaves' species attributes as taxid
  • Loading branch information
jordibc committed Nov 10, 2023
2 parents 27a0122 + 4bf721e commit abc80e7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ete4/gtdb_taxonomy/gtdbquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,11 @@ def annotate_tree(self, t, taxid_attr='name',
"""
taxids = set()
if taxid_attr == "taxid":
for n in t.traverse():
for n in t.leaves():
if taxid_attr in n.props:
taxids.add(n.props[taxid_attr])
else:
for n in t.traverse():
for n in t.leaves():
try:
# translate gtdb name -> id
taxaname = getattr(n, taxid_attr, n.props.get(taxid_attr))
Expand Down Expand Up @@ -507,7 +507,10 @@ def annotate_tree(self, t, taxid_attr='name',
n2leaves = t.get_cached_content()

for node in t.traverse('postorder'):
node_taxid = getattr(node, taxid_attr, node.props.get(taxid_attr))
if node.is_leaf:
node_taxid = getattr(node, taxid_attr, node.props.get(taxid_attr))
else:
node_taxid = None
node.add_prop('taxid', node_taxid)

if node_taxid:
Expand Down

0 comments on commit abc80e7

Please sign in to comment.