Skip to content

Commit

Permalink
feat: Add API ontology querying module
Browse files Browse the repository at this point in the history
  • Loading branch information
nayib-jose-gloria committed Feb 20, 2024
1 parent 2179ebb commit 68f3168
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/generate_all_ontology.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Updates to Ontology Files
on:
push:
paths:
- "**/tools/ontology-builder/src/ontology-references/ontology_info.yml"
- "**/api/python/src/cellxgene_ontology_guide/fixtures/ontology_info.yml"
branches-ignore:
- main

Expand Down Expand Up @@ -36,7 +36,7 @@ jobs:
- name: ontology-processing
run: |
python3 ./tools/ontology-builder/src/all_ontology_generator.py
git add ./tools/ontology-builder/src/ontology-references/all_ontology.json.gz
git add ./api/python/src/cellxgene_ontology_guide/fixtures/all_ontology.json.gz
- name: Commit
run: |
git commit -m "AUTO: update ontologies"
Expand Down
Empty file removed api/python/__init__.py
Empty file.
4 changes: 1 addition & 3 deletions api/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ authors = [
license = { text = "MIT" }
readme = "README.md"
requires-python = "~= 3.11"
dependencies = [
"owlready2"
]
dependencies = []

[project.optional-dependencies]
test = ["pytest"]
Expand Down
5 changes: 5 additions & 0 deletions api/python/src/cellxgene_ontology_guide/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os

PACKAGE_ROOT = os.path.dirname(os.path.realpath(__file__))
ALL_ONTOLOGY_JSON = os.path.join(PACKAGE_ROOT, "fixtures/all_ontology.json.gz")
ONTOLOGY_INFO_YML = os.path.join(PACKAGE_ROOT, "fixtures/ontology_info.yml")
Binary file not shown.
16 changes: 16 additions & 0 deletions api/python/src/cellxgene_ontology_guide/query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import List

import env
import gzip
import json

with gzip.open(env.ALL_ONTOLOGY_JSON, "rt") as f:
ONTOLOGY_DICT = json.load(f)


def get_ancestors(term_id: str) -> List[str]:
# TODO: Support List input, Dict return?
# TODO: Regex input validation?
# TODO: docstring
ontology_name = term_id.split(":")[0]
return ONTOLOGY_DICT[ontology_name][term_id]["ancestors"]
6 changes: 6 additions & 0 deletions api/python/tests/test_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from cellxgene_ontology_guide import query


def test_get_ancestors():
ancestors = query.get_ancestors("UBERON:0000966")
assert len(ancestors) == 39
6 changes: 4 additions & 2 deletions tools/ontology-builder/src/env.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os

PACKAGE_ROOT = os.path.dirname(os.path.realpath(__file__))
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(PACKAGE_ROOT)))
FIXTURES_ROOT = os.path.join(ROOT_DIR, "api/python/src/cellxgene_ontology_guide/fixtures")
ONTOLOGY_REF_DIR = os.path.join(PACKAGE_ROOT, "ontology-references")
RAW_ONTOLOGY_DIR = os.path.join(ONTOLOGY_REF_DIR, "raw-files")
ONTO_INFO_YAML = os.path.join(ONTOLOGY_REF_DIR, "ontology_info.yml")
PARSED_ONTOLOGIES_FILE = os.path.join(ONTOLOGY_REF_DIR, "all_ontology.json.gz")
ONTO_INFO_YAML = os.path.join(FIXTURES_ROOT, "ontology_info.yml")
PARSED_ONTOLOGIES_FILE = os.path.join(FIXTURES_ROOT, "all_ontology.json.gz")

0 comments on commit 68f3168

Please sign in to comment.