Skip to content

Commit 5dd0db8

Browse files
authored
fix: use safe ancestors() wrapper in CellGuide tree_builder (#7686)
1 parent 949c22e commit 5dd0db8

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

backend/cellguide/pipeline/ontology_tree/tree_builder.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
from backend.cellguide.pipeline.constants import CELLGUIDE_PIPELINE_NUM_CPUS
1111
from backend.cellguide.pipeline.ontology_tree.types import OntologyTree, OntologyTreeState
1212
from backend.common.census_cube.data.ontology_labels import ontology_term_label
13-
from backend.common.census_cube.utils import ontology_parser, rollup_across_cell_type_descendants, to_dict
13+
from backend.common.census_cube.utils import (
14+
ancestors,
15+
descendants,
16+
ontology_parser,
17+
rollup_across_cell_type_descendants,
18+
to_dict,
19+
)
1420

1521
logger = logging.getLogger(__name__)
1622

@@ -88,7 +94,7 @@ def __init__(self, cell_counts_df, root_node="CL:0000000"):
8894

8995
logger.info("Initializing cell type data structures from the input cell counts dataframe...")
9096

91-
self.all_cell_type_ids = self.ontology.get_term_descendants(root_node, include_self=True)
97+
self.all_cell_type_ids = descendants(root_node)
9298

9399
self.cell_counts_df, self.cell_counts_df_rollup = self._initialize_cell_counts_df_rollup(cell_counts_df)
94100
self.all_cell_type_ids_in_corpus = self.cell_counts_df_rollup.index.values[
@@ -392,15 +398,13 @@ def _process_tissue__parallel(self, tissueId: str) -> OntologyTreeState:
392398
"""
393399
end_nodes = self.uberon_by_celltype[tissueId]
394400
tissue_label = ontology_term_label(tissueId)
395-
uberon_ancestors = self.ontology.get_term_ancestors(tissueId, include_self=True)
401+
uberon_ancestors = ancestors(tissueId)
396402

397403
# filter out hemaotoietic cell types from non-whitelisted tissues
398404
uberon_ancestors_in_whitelist = list(set(TISSUES_IMMUNE_CELL_WHITELIST).intersection(uberon_ancestors))
399405
if len(uberon_ancestors_in_whitelist) == 0:
400406
end_nodes_that_are_not_hematopoietic = [
401-
e
402-
for e in end_nodes
403-
if HEMATOPOIETIC_CELL_TYPE_ID not in self.ontology.get_term_ancestors(e, include_self=True)
407+
e for e in end_nodes if HEMATOPOIETIC_CELL_TYPE_ID not in ancestors(e)
404408
]
405409
if len(end_nodes_that_are_not_hematopoietic) == 0:
406410
logger.info(f"Not filtering out immune cell for {tissue_label}")

backend/common/census_cube/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def get_all_cell_type_ids_in_corpus(snapshot: CensusCubeSnapshot, root_node="CL:
190190
list[str]: A list of cell type ontology term IDs that have at least one cell in the corpus.
191191
"""
192192

193-
all_cell_type_ids = ontology_parser.get_term_descendants(root_node, include_self=True)
193+
all_cell_type_ids = descendants(root_node)
194194
cell_counts_df = snapshot.cell_counts_df
195195

196196
cell_counts_df = (

0 commit comments

Comments
 (0)