-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add function to fetch curated ontology term lists (#141)
- Loading branch information
1 parent
5fc917b
commit 5c7db62
Showing
8 changed files
with
149 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
api/python/src/cellxgene_ontology_guide/curated_ontology_term_lists.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import functools | ||
import json | ||
import os | ||
from typing import List | ||
|
||
from cellxgene_ontology_guide._constants import DATA_ROOT | ||
from cellxgene_ontology_guide.entities import CuratedOntologyTermList | ||
|
||
|
||
@functools.cache | ||
def get_curated_ontology_term_list(curated_ontology_term_list: CuratedOntologyTermList) -> List[str]: | ||
""" | ||
Get the list of curated ontology terms for the given curated_ontology_term_list. | ||
:param curated_ontology_term_list: Enum attribute representing the curated ontology term list | ||
:return: List[str] of ontology term IDs | ||
""" | ||
filename = f"{curated_ontology_term_list.value}_list.json" | ||
with open(os.path.join(DATA_ROOT, filename)) as f: | ||
return json.load(f) # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import json | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from cellxgene_ontology_guide.curated_ontology_term_lists import get_curated_ontology_term_list | ||
from cellxgene_ontology_guide.entities import CuratedOntologyTermList | ||
|
||
MODULE_PATH = "cellxgene_ontology_guide.curated_ontology_term_lists" | ||
|
||
|
||
@pytest.fixture | ||
def mock_curated_ontology_term_list_file(tmpdir): | ||
with patch(f"{MODULE_PATH}.DATA_ROOT", tmpdir): | ||
test_file_name = "cell_class_list.json" | ||
test_enum = CuratedOntologyTermList.CELL_CLASS | ||
onto_file = tmpdir.join(test_file_name) | ||
file_contents = ["cell class 1", "cell class 2"] | ||
with open(str(onto_file), "wt") as onto_file: | ||
json.dump(file_contents, onto_file) | ||
yield test_enum, file_contents | ||
|
||
|
||
def test_get_curated_ontology_term_list(mock_curated_ontology_term_list_file): | ||
test_enum, file_contents = mock_curated_ontology_term_list_file | ||
assert get_curated_ontology_term_list(test_enum) == file_contents | ||
assert get_curated_ontology_term_list.cache_info().hits == 0 | ||
assert get_curated_ontology_term_list.cache_info().misses == 1 | ||
get_curated_ontology_term_list(test_enum) | ||
assert get_curated_ontology_term_list.cache_info().hits == 1 | ||
assert get_curated_ontology_term_list.cache_info().misses == 1 | ||
|
||
|
||
def test__clear_curated_ontology_term_list_cache(mock_curated_ontology_term_list_file): | ||
test_enum, _ = mock_curated_ontology_term_list_file | ||
get_curated_ontology_term_list(test_enum) | ||
assert get_curated_ontology_term_list.cache_info().misses == 1 | ||
get_curated_ontology_term_list.cache_clear() | ||
assert get_curated_ontology_term_list.cache_info().misses == 0 | ||
get_curated_ontology_term_list(test_enum) | ||
assert get_curated_ontology_term_list.cache_info().misses == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "Curated 'Development Stage' UBERON Ontology Terms Schema", | ||
"description": "A schema for validating an array of high-level UBERON ontology term IDs representing 'development stage' ontology terms, curated for CZ CellxGene use.", | ||
"type": "array", | ||
"items": {"$ref": "ontology_term_id_schema.json#/definitions/UBERON_term_id"}, | ||
"minItems": 1, | ||
"uniqueItems": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[ | ||
"UBERON:0007236", | ||
"UBERON:0000106", | ||
"UBERON:0014859", | ||
"UBERON:0008264", | ||
"UBERON:0007233", | ||
"UBERON:0000112", | ||
"UBERON:8000003", | ||
"UBERON:0014857", | ||
"UBERON:0009849", | ||
"UBERON:0034920", | ||
"UBERON:0000069", | ||
"UBERON:0000109", | ||
"UBERON:8000001", | ||
"UBERON:0000068", | ||
"UBERON:0018685", | ||
"UBERON:0000107", | ||
"UBERON:0007222", | ||
"UBERON:0000092", | ||
"UBERON:0018378", | ||
"UBERON:0014864", | ||
"UBERON:0004730", | ||
"UBERON:0000111", | ||
"UBERON:0007220", | ||
"UBERON:0014405", | ||
"UBERON:0014862", | ||
"UBERON:8000000", | ||
"UBERON:0000071", | ||
"UBERON:0014860", | ||
"UBERON:0012101", | ||
"UBERON:0000113", | ||
"UBERON:0014858", | ||
"UBERON:0007232", | ||
"UBERON:0000070", | ||
"UBERON:0000110", | ||
"UBERON:8000002", | ||
"UBERON:0014856", | ||
"UBERON:0004728", | ||
"UBERON:0034919", | ||
"UBERON:0000108", | ||
"UBERON:0000066", | ||
"UBERON:0004707", | ||
"UBERON:0000105", | ||
"UBERON:0018241", | ||
"UBERON:0007221", | ||
"UBERON:0014406", | ||
"UBERON:0014863", | ||
"UBERON:0004729", | ||
"UBERON:0014861" | ||
] |