diff --git a/api/python/src/cellxgene_ontology_guide/ontology_parser.py b/api/python/src/cellxgene_ontology_guide/ontology_parser.py index cdee409a..da9889e6 100644 --- a/api/python/src/cellxgene_ontology_guide/ontology_parser.py +++ b/api/python/src/cellxgene_ontology_guide/ontology_parser.py @@ -473,3 +473,37 @@ def map_term_labels(self, term_ids: Iterable[str]) -> Dict[str, str]: :return: Dict[str, str] mapping term IDs to their respective human-readable labels """ return {term_id: self.get_term_label(term_id) for term_id in term_ids} + + def get_term_description(self, term_id: str) -> Optional[str]: + """ + Fetch the description for a given ontology term. + + Example + >>> from cellxgene_ontology_guide.ontology_parser import OntologyParser + >>> ontology_parser = OntologyParser() + >>> ontology_parser.get_term_description("CL:0000005") + 'Any fibroblast that is deriived from the neural crest.' + + :param term_id: str ontology term to fetch description for + :return: str description for the term + """ + if term_id in VALID_NON_ONTOLOGY_TERMS: + return term_id + ontology_name = self._parse_ontology_name(term_id) + description: Optional[str] = self.cxg_schema.ontology(ontology_name)[term_id].get("description", None) + return description + + def map_term_descriptions(self, term_ids: List[str]) -> Dict[str, Optional[str]]: + """ + Fetch the descriptions for a given list of ontology terms. + + Example + >>> from cellxgene_ontology_guide.ontology_parser import OntologyParser + >>> ontology_parser = OntologyParser() + >>> ontology_parser.map_term_descriptions(["CL:0000005", "CL:0000006"]) + {'CL:0000005': 'Any fibroblast that is deriived from the neural crest.', 'CL:0000006': None} + + :param term_ids: list of str ontology terms to fetch descriptions for + :return: Dict[str, str] mapping term IDs to their respective descriptions + """ + return {term_id: self.get_term_description(term_id) for term_id in term_ids} diff --git a/api/python/tests/test_ontology_parser.py b/api/python/tests/test_ontology_parser.py index 8ac672a9..d78a434f 100644 --- a/api/python/tests/test_ontology_parser.py +++ b/api/python/tests/test_ontology_parser.py @@ -8,7 +8,7 @@ @pytest.fixture def ontology_dict(): return { - "CL:0000000": {"ancestors": {}, "label": "cell A", "deprecated": False}, + "CL:0000000": {"ancestors": {}, "label": "cell A", "description": "This is cell A.", "deprecated": False}, "CL:0000001": { "ancestors": {"CL:0000000": 1}, "label": "cell B", @@ -221,6 +221,19 @@ def test_map_term_labels(ontology_parser): } +def test_get_term_description(ontology_parser): + assert ontology_parser.get_term_description("CL:0000000") == "This is cell A." + + +def test_map_term_description(ontology_parser): + assert ontology_parser.map_term_descriptions(["CL:0000000", "CL:0000004", "unknown", "na"]) == { + "CL:0000000": "This is cell A.", + "CL:0000004": None, + "unknown": "unknown", + "na": "na", + } + + def test_get_high_level_terms(ontology_parser): high_level_terms = ["CL:0000000", "CL:0000001"] assert ontology_parser.get_high_level_terms("CL:0000004", high_level_terms) == ["CL:0000000", "CL:0000001"] diff --git a/artifact-schemas/all_ontology_schema.json b/artifact-schemas/all_ontology_schema.json index 80ef2430..e61228b3 100644 --- a/artifact-schemas/all_ontology_schema.json +++ b/artifact-schemas/all_ontology_schema.json @@ -13,6 +13,10 @@ "type": "string", "description": "human-readable name for the ontology entry." }, + "description": { + "type": "string", + "description": "Optional description of the ontology entry." + }, "deprecated": { "type": "boolean", "description": "Indicates whether the ontology entry is deprecated." diff --git a/ontology-assets/CL-ontology-v2024-01-04.json.gz b/ontology-assets/CL-ontology-v2024-01-04.json.gz index 179e883f..2e732332 100644 Binary files a/ontology-assets/CL-ontology-v2024-01-04.json.gz and b/ontology-assets/CL-ontology-v2024-01-04.json.gz differ diff --git a/ontology-assets/EFO-ontology-v3.62.0.json.gz b/ontology-assets/EFO-ontology-v3.62.0.json.gz index 8ee10131..4b9c9ce0 100644 Binary files a/ontology-assets/EFO-ontology-v3.62.0.json.gz and b/ontology-assets/EFO-ontology-v3.62.0.json.gz differ diff --git a/ontology-assets/HANCESTRO-ontology-3.0.json.gz b/ontology-assets/HANCESTRO-ontology-3.0.json.gz index 43121128..2f7b385c 100644 Binary files a/ontology-assets/HANCESTRO-ontology-3.0.json.gz and b/ontology-assets/HANCESTRO-ontology-3.0.json.gz differ diff --git a/ontology-assets/HsapDv-ontology-11.json.gz b/ontology-assets/HsapDv-ontology-11.json.gz index 20ec8e50..bf8a48d4 100644 Binary files a/ontology-assets/HsapDv-ontology-11.json.gz and b/ontology-assets/HsapDv-ontology-11.json.gz differ diff --git a/ontology-assets/MONDO-ontology-v2024-01-03.json.gz b/ontology-assets/MONDO-ontology-v2024-01-03.json.gz index 13e85e77..764e04de 100644 Binary files a/ontology-assets/MONDO-ontology-v2024-01-03.json.gz and b/ontology-assets/MONDO-ontology-v2024-01-03.json.gz differ diff --git a/ontology-assets/MmusDv-ontology-9.json.gz b/ontology-assets/MmusDv-ontology-9.json.gz index 7e7b5fc4..4e2f3652 100644 Binary files a/ontology-assets/MmusDv-ontology-9.json.gz and b/ontology-assets/MmusDv-ontology-9.json.gz differ diff --git a/ontology-assets/PATO-ontology-v2023-05-18.json.gz b/ontology-assets/PATO-ontology-v2023-05-18.json.gz index 32bf1424..a8b9e402 100644 Binary files a/ontology-assets/PATO-ontology-v2023-05-18.json.gz and b/ontology-assets/PATO-ontology-v2023-05-18.json.gz differ diff --git a/ontology-assets/UBERON-ontology-v2024-01-18.json.gz b/ontology-assets/UBERON-ontology-v2024-01-18.json.gz index d82357de..c881a7ed 100644 Binary files a/ontology-assets/UBERON-ontology-v2024-01-18.json.gz and b/ontology-assets/UBERON-ontology-v2024-01-18.json.gz differ diff --git a/ontology-assets/ontology_info.json b/ontology-assets/ontology_info.json index c4051ee1..a3ed4bec 100644 --- a/ontology-assets/ontology_info.json +++ b/ontology-assets/ontology_info.json @@ -48,4 +48,4 @@ } } } -} +} \ No newline at end of file diff --git a/tools/ontology-builder/src/all_ontology_generator.py b/tools/ontology-builder/src/all_ontology_generator.py index 711480b0..b278b28d 100755 --- a/tools/ontology-builder/src/all_ontology_generator.py +++ b/tools/ontology-builder/src/all_ontology_generator.py @@ -193,9 +193,12 @@ def _extract_ontology_term_metadata(onto: owlready2.entity.ThingClass) -> Dict[s # no current use-case for NCBITaxon term_dict[term_id]["ancestors"] = {} if onto.name == "NCBITaxon" else ancestors - # Gets label term_dict[term_id]["label"] = onto_term.label[0] if onto_term.label else "" + # optional description, if available + if getattr(onto_term, "IAO_0000115", None): + term_dict[term_id]["description"] = onto_term.IAO_0000115[0] + # Add the "deprecated" status and associated metadata if True term_dict[term_id]["deprecated"] = False if onto_term.deprecated and onto_term.deprecated.first():