diff --git a/src/pyobo/sources/geonames.py b/src/pyobo/sources/geonames.py index 5c213ddf..4e39fa81 100644 --- a/src/pyobo/sources/geonames.py +++ b/src/pyobo/sources/geonames.py @@ -9,7 +9,7 @@ from pystow.utils import read_zipfile_csv from tqdm import tqdm -from pyobo import Obo, Term +from pyobo import Obo, Term, TypeDef from pyobo.struct import Reference, part_of from pyobo.utils.path import ensure_df, ensure_path @@ -22,6 +22,7 @@ ADMIN1_URL = "https://download.geonames.org/export/dump/admin1CodesASCII.txt" ADMIN2_URL = "https://download.geonames.org/export/dump/admin2Codes.txt" CITIES_URL = "https://download.geonames.org/export/dump/cities15000.zip" +CODE_TYPEDEF = TypeDef.default(PREFIX, "code") class GeonamesGetter(Obo): @@ -29,7 +30,7 @@ class GeonamesGetter(Obo): ontology = PREFIX dynamic_version = True - typedefs = [part_of] + typedefs = [part_of, CODE_TYPEDEF] def iter_terms(self, force: bool = False) -> Iterable[Term]: """Iterate over terms in the ontology.""" @@ -80,7 +81,7 @@ def get_code_to_country(*, force: bool = False) -> Mapping[str, Term]: term.append_synonym(fips) if pd.notna(iso3): term.append_synonym(iso3) - term.annotate_literal("code", code) + term.annotate_literal(CODE_TYPEDEF, code) code_to_country[code] = term logger.info(f"got {len(code_to_country):,} country records") return code_to_country @@ -107,7 +108,7 @@ def get_code_to_admin1( term = Term.from_triple( "geonames", identifier, name if pd.notna(name) else None, type="Instance" ) - term.annotate_literal("code", code) + term.annotate_literal(CODE_TYPEDEF, code) code_to_admin1[code] = term country_code = code.split(".")[0] @@ -135,7 +136,7 @@ def get_code_to_admin2( term = Term.from_triple( "geonames", identifier, name if pd.notna(name) else None, type="Instance" ) - term.annotate_literal("code", code) + term.annotate_literal(CODE_TYPEDEF, code) code_to_admin2[code] = term admin1_code = code.rsplit(".", 1)[0] admin1_term = code_to_admin1.get(admin1_code) diff --git a/src/pyobo/sources/icd10.py b/src/pyobo/sources/icd10.py index b905bb01..d05e7dd4 100644 --- a/src/pyobo/sources/icd10.py +++ b/src/pyobo/sources/icd10.py @@ -17,7 +17,7 @@ get_icd, visiter, ) -from ..struct import Obo, Reference, Synonym, Term +from ..struct import Obo, Reference, Synonym, Term, has_category from ..utils.path import prefix_directory_join __all__ = [ @@ -35,6 +35,7 @@ class ICD10Getter(Obo): ontology = PREFIX dynamic_version = True + typedefs = [has_category] def iter_terms(self, force: bool = False) -> Iterable[Term]: """Iterate over terms in the ontology.""" @@ -81,8 +82,7 @@ def _extract_icd10(res_json: Mapping[str, Any]) -> Term: synonyms=synonyms, parents=parents, ) - - rv.annotate_literal("class_kind", res_json["classKind"]) + rv.annotate_literal(has_category, res_json["classKind"]) return rv diff --git a/src/pyobo/struct/__init__.py b/src/pyobo/struct/__init__.py index b9af56d2..adaa91b0 100644 --- a/src/pyobo/struct/__init__.py +++ b/src/pyobo/struct/__init__.py @@ -17,6 +17,7 @@ enables, from_species, gene_product_member_of, + has_category, has_gene_product, has_member, has_part, @@ -47,6 +48,7 @@ "enables", "from_species", "gene_product_member_of", + "has_category", "has_gene_product", "has_member", "has_part",