From 4bf721e0483a2505b707f1b61401a8aa160d9c5a Mon Sep 17 00:00:00 2001 From: dengzq1234 Date: Fri, 10 Nov 2023 12:23:43 +0100 Subject: [PATCH] only take leaves' species attributes as taxid --- ete4/gtdb_taxonomy/gtdbquery.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ete4/gtdb_taxonomy/gtdbquery.py b/ete4/gtdb_taxonomy/gtdbquery.py index 8c130513..6cf00d18 100644 --- a/ete4/gtdb_taxonomy/gtdbquery.py +++ b/ete4/gtdb_taxonomy/gtdbquery.py @@ -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)) @@ -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: