Skip to content

Commit

Permalink
feat: refer to ontology source filenames in ontology_info and return …
Browse files Browse the repository at this point in the history
…that in get_ontology_download_url (#106)
  • Loading branch information
nayib-jose-gloria authored Mar 13, 2024
1 parent 341d418 commit ff9d826
Show file tree
Hide file tree
Showing 17 changed files with 27 additions and 66 deletions.
2 changes: 1 addition & 1 deletion api/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ authors = [
]
license = { file = "LICENSE" }
readme = "README.md"
requires-python = "~= 3.11"
requires-python = "~= 3.10"
dependencies = ["semantic_version==2.10.0"]

[project.optional-dependencies]
Expand Down
25 changes: 0 additions & 25 deletions api/python/src/cellxgene_ontology_guide/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,3 @@ class Ontology(Enum):
MmusDv = "mmusdv"
PATO = "pato"
NCBITaxon = "ncbitaxon"


class OntologyVariant(Enum):
"""
Enum for the standard set of ontology variants. Each is curated for a specific purpose.
See https://oboacademy.github.io/obook/explanation/owl-format-variants/ for more information on the distinction
and use-cases for each variant.
"""

FULL = "full"
BASE = "base"
SIMPLE = "simple"
BASIC = "basic"


class OntologyFileType(Enum):
"""
Enum for the standard set of ontology file types. Each requires different parsing tools, but relay the same
information.
"""

OWL = "owl"
OBO = "obo"
JSON = "json"
21 changes: 6 additions & 15 deletions api/python/src/cellxgene_ontology_guide/ontology_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from typing import Any, Dict, Iterable, List, Union

from cellxgene_ontology_guide.entities import Ontology, OntologyFileType, OntologyVariant
from cellxgene_ontology_guide.entities import Ontology
from cellxgene_ontology_guide.supported_versions import CXGSchema


Expand Down Expand Up @@ -274,26 +274,17 @@ def get_term_label(self, term_id: str) -> str:
label: str = self.cxg_schema.ontology(ontology_name)[term_id]["label"]
return label

def get_ontology_download_url(
self, ontology: Ontology, ontology_filetype: OntologyFileType, ontology_variant: OntologyVariant = None
) -> str:
def get_ontology_download_url(self, ontology: Ontology) -> str:
"""
Get the download URL for a given ontology file. If the ontology_variant is not provided, the default ontology
file will be returned.
Get the download URL for a given ontology file.
Examples:
get_ontology_download_url("CL", "owl") -> "http://example.com/2024-01-01/cl.owl"
get_ontology_download_url("CL", "obo", "base") -> "http://example.com/2024-01-01/cl-base.obo"
get_ontology_download_url("CL") -> "http://example.com/2024-01-01/cl.owl"
:param ontology: Ontology enum of the ontology to fetch
:param ontology_filetype: OntologyFileType enum of the ontology file type to fetch
:param ontology_variant: OntologyVariant enum of the ontology variant to fetch
:return: str download URL for the requested ontology file
"""
source_url = self.cxg_schema.supported_ontologies[ontology.name]["source"]
version = self.cxg_schema.supported_ontologies[ontology.name]["version"]
return (
f"{source_url}/{version}/{ontology.value}-{ontology_variant.value}.{ontology_filetype.value}"
if ontology_variant
else f"{source_url}/{version}/{ontology.value}.{ontology_filetype.value}"
)
filename = self.cxg_schema.supported_ontologies[ontology.name]["filename"]
return f"{source_url}/{version}/{filename}"
13 changes: 3 additions & 10 deletions api/python/tests/test_ontology_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest.mock import patch

import pytest
from cellxgene_ontology_guide.entities import Ontology, OntologyFileType, OntologyVariant
from cellxgene_ontology_guide.entities import Ontology
from cellxgene_ontology_guide.ontology_parser import OntologyParser
from cellxgene_ontology_guide.supported_versions import CXGSchema

Expand Down Expand Up @@ -44,7 +44,7 @@ def ontology_dict():
@pytest.fixture
def mock_CXGSchema(ontology_dict, mock_load_supported_versions, mock_load_ontology_file):
mock_load_supported_versions.return_value = {
"v5.0.0": {"CL": {"version": "2024-01-01", "source": "http://example.com", "filetype": "owl"}}
"v5.0.0": {"CL": {"version": "2024-01-01", "source": "http://example.com", "filename": "cl.owl"}}
}
cxg_schema = CXGSchema()
cxg_schema.ontology_file_names = {"CL": "CL-ontology-2024-01-01.json.gz"}
Expand Down Expand Up @@ -212,11 +212,4 @@ def test_get_distance_between_terms(ontology_parser):


def test_get_ontology_download_url(ontology_parser):
assert (
ontology_parser.get_ontology_download_url(Ontology.CL, OntologyFileType.OWL)
== "http://example.com/2024-01-01/cl.owl"
)
assert (
ontology_parser.get_ontology_download_url(Ontology.CL, OntologyFileType.OBO, OntologyVariant.BASE)
== "http://example.com/2024-01-01/cl-base.obo"
)
assert ontology_parser.get_ontology_download_url(Ontology.CL) == "http://example.com/2024-01-01/cl.owl"
6 changes: 3 additions & 3 deletions artifact-schemas/ontology_info_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@
"format": "uri",
"description": "Source to find and download canonical ontology version for this data release"
},
"filetype": {
"filename": {
"type": "string",
"description": "filetype used to build generated artifacts for this ontology data release"
"description": "name of ontology file used to build generated artifacts for this ontology data release"
}
},
"required": [
"version",
"source",
"filetype"
"filename"
],
"additionalProperties": false
}
Expand Down
Binary file modified ontology-assets/CL-ontology-v2024-01-04.json.gz
Binary file not shown.
Binary file modified ontology-assets/EFO-ontology-v3.62.0.json.gz
Binary file not shown.
Binary file modified ontology-assets/HANCESTRO-ontology-3.0.json.gz
Binary file not shown.
Binary file modified ontology-assets/HsapDv-ontology-11.json.gz
Binary file not shown.
Binary file modified ontology-assets/MONDO-ontology-v2024-01-03.json.gz
Binary file not shown.
Binary file modified ontology-assets/MmusDv-ontology-9.json.gz
Binary file not shown.
Binary file modified ontology-assets/NCBITaxon-ontology-v2023-06-20.json.gz
Binary file not shown.
Binary file modified ontology-assets/PATO-ontology-v2023-05-18.json.gz
Binary file not shown.
Binary file modified ontology-assets/UBERON-ontology-v2024-01-18.json.gz
Binary file not shown.
18 changes: 9 additions & 9 deletions ontology-assets/ontology_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,47 @@
"CL": {
"version": "v2024-01-04",
"source": "https://github.com/obophenotype/cell-ontology/releases/download",
"filetype": "owl"
"filename": "cl.owl"
},
"EFO": {
"version": "v3.62.0",
"source": "https://github.com/EBISPOT/efo/releases/download",
"filetype": "owl"
"filename": "efo.owl"
},
"HANCESTRO": {
"version": "3.0",
"source": "https://github.com/EBISPOT/hancestro/raw",
"filetype": "owl"
"filename": "hancestro.owl"
},
"HsapDv": {
"version": "11",
"source": "http://aber-owl.net/media/ontologies/HSAPDV",
"filetype": "owl"
"filename": "hsapdv.owl"
},
"MONDO": {
"version": "v2024-01-03",
"source": "https://github.com/monarch-initiative/mondo/releases/download",
"filetype": "owl"
"filename": "mondo.owl"
},
"MmusDv": {
"version": "9",
"source": "http://aber-owl.net/media/ontologies/MMUSDV",
"filetype": "owl"
"filename": "mmusdv.owl"
},
"NCBITaxon": {
"version": "v2023-06-20",
"source": "https://github.com/obophenotype/ncbitaxon/releases/download",
"filetype": "owl.gz"
"filename": "ncbitaxon.owl.gz"
},
"UBERON": {
"version": "v2024-01-18",
"source": "https://github.com/obophenotype/uberon/releases/download",
"filetype": "owl"
"filename": "uberon.owl"
},
"PATO": {
"version": "v2023-05-18",
"source": "https://github.com/pato-ontology/pato/raw",
"filetype": "owl"
"filename": "pato.owl"
}
}
}
2 changes: 1 addition & 1 deletion tools/ontology-builder/src/all_ontology_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def download(_ontology: str, _url: str) -> None:

def _build_url(_ontology: str) -> str:
onto_ref_data = ontology_info[_ontology]
return f"{onto_ref_data['source']}/{onto_ref_data['version']}/{ontology.lower()}.{onto_ref_data['filetype']}"
return f"{onto_ref_data['source']}/{onto_ref_data['version']}/{onto_ref_data['filename']}"

threads = []
for ontology, _ in ontology_info.items():
Expand Down
6 changes: 4 additions & 2 deletions tools/ontology-builder/tests/test_all_ontology_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def mock_ontology_info():
"ontology_name": {
"source": "http://example.com",
"version": "v1",
"filetype": "owl",
"filename": "ontology_name.owl",
}
}

Expand Down Expand Up @@ -50,7 +50,9 @@ def test_get_ontology_info_file_default(mock_ontology_info_file):
ontology_info = _get_ontology_info_file(ontology_info_file=mock_ontology_info_file)

# Assertion
assert ontology_info == {"ontology_name": {"source": "http://example.com", "version": "v1", "filetype": "owl"}}
assert ontology_info == {
"ontology_name": {"source": "http://example.com", "version": "v1", "filename": "ontology_name.owl"}
}


def test_get_ontology_info_file_version(mock_ontology_info_file):
Expand Down

0 comments on commit ff9d826

Please sign in to comment.