Skip to content

Commit

Permalink
Add append contributor shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Jan 14, 2025
1 parent f150d6b commit 3e8796f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
7 changes: 3 additions & 4 deletions src/pyobo/sources/geonames/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from tqdm import tqdm

from pyobo import Reference, Term, TypeDef, default_reference
from pyobo.struct.struct import CHARLIE_TERM, HUMAN_TERM
from pyobo.struct.vocabulary import has_contributor
from pyobo.struct.struct import CHARLIE_TERM, HUMAN_TERM, PYOBO_INJECTED
from pyobo.utils.path import ensure_df

PREFIX = "geonames"
Expand Down Expand Up @@ -108,8 +107,8 @@ def get_feature_terms(
yield (
Term(reference=cat)
.append_parent(FEATURE_TERM)
.annotate_object(has_contributor, CHARLIE_TERM)
.append_comment("injected by PyOBO source")
.append_contributor(CHARLIE_TERM)
.append_comment(PYOBO_INJECTED)
)
if features is None:
features = get_features(force=force)
Expand Down
12 changes: 6 additions & 6 deletions src/pyobo/sources/ncbi/ncbi_gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections.abc import Iterable

from pyobo import default_reference
from pyobo.struct import CHARLIE_TERM, HUMAN_TERM, Obo, Reference, Term, TypeDef
from pyobo.struct import CHARLIE_TERM, HUMAN_TERM, PYOBO_INJECTED, Obo, Reference, Term, TypeDef
from pyobo.struct.typedef import comment, has_contributor, see_also, term_replaced_by
from pyobo.utils.path import ensure_path

Expand All @@ -29,7 +29,7 @@
definition="Connects a taxonomy term to a genetic code translation table",
domain=NCBITAXON_ROOT,
range=GC_ROOT,
).annotate_object(has_contributor, CHARLIE_TERM)
).append_contributor(CHARLIE_TERM)

NUCLEAR_GENETIC_CODE = default_reference(
prefix=PREFIX, identifier="nuclear-genetic-code", name="nuclear genetic code translation table"
Expand Down Expand Up @@ -120,15 +120,15 @@ def get_terms() -> Iterable[Term]:
definition="A table for translating codons into amino acids. This can change for "
"different taxa, or be different in different organelles that include genetic information.",
)
.annotate_object(has_contributor, CHARLIE_TERM)
.append_comment("injected by PyOBO")
.append_contributor(CHARLIE_TERM)
.append_comment(PYOBO_INJECTED)
)

for reference in CATEGORY_TO_TABLES:
term = Term(reference=reference)
term.append_parent(GC_ROOT)
term.annotate_object(has_contributor, CHARLIE_TERM)
term.append_comment("injected by PyOBO")
term.append_contributor(CHARLIE_TERM)
term.append_comment(PYOBO_INJECTED)
if substructure := CATEGORY_TO_CELLULAR_COMPONENT.get(reference):
term.append_see_also(substructure)
yield term
Expand Down
12 changes: 6 additions & 6 deletions src/pyobo/sources/nlm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from tqdm import tqdm

from pyobo import Reference, Term, TypeDef, default_reference, ensure_path
from pyobo.struct.struct import CHARLIE_TERM
from pyobo.struct.typedef import has_contributor, has_end_date, has_start_date
from pyobo.struct.struct import CHARLIE_TERM, PYOBO_INJECTED
from pyobo.struct.typedef import has_end_date, has_start_date
from pyobo.utils.path import ensure_df

PREFIX_CATALOG = "nlm"
Expand All @@ -29,16 +29,16 @@
.append_exact_match(Reference(prefix="MI", identifier="0885"))
.append_exact_match(Reference(prefix="bibo", identifier="Journal"))
.append_exact_match(Reference(prefix="uniprot.core", identifier="Journal"))
.annotate_object(has_contributor, CHARLIE_TERM)
.append_comment("injected by PyOBO source")
.append_contributor(CHARLIE_TERM)
.append_comment(PYOBO_INJECTED)
)
PUBLISHER_TERM = (
Term(reference=default_reference(PREFIX_CATALOG, "publisher", name="publisher"))
.append_exact_match(Reference(prefix="biolink", identifier="publisher"))
.append_exact_match(Reference(prefix="schema", identifier="publisher"))
.append_exact_match(Reference(prefix="uniprot.core", identifier="publisher"))
.annotate_object(has_contributor, CHARLIE_TERM)
.append_comment("injected by PyOBO source")
.append_contributor(CHARLIE_TERM)
.append_comment(PYOBO_INJECTED)
)


Expand Down
10 changes: 5 additions & 5 deletions src/pyobo/sources/signor/signor_complexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pyobo import Obo, Reference, Term, default_reference
from pyobo.sources.signor.download import DownloadKey, get_signor_df
from pyobo.struct import CHARLIE_TERM, HUMAN_TERM, PYOBO_INJECTED
from pyobo.struct.typedef import exact_match, has_component, has_contributor, has_member
from pyobo.struct.typedef import exact_match, has_component, has_member

__all__ = [
"SignorGetter",
Expand All @@ -17,22 +17,22 @@

PROTEIN_FAMILY = (
Term(reference=default_reference(PREFIX, "protein-family"))
.annotate_object(has_contributor, CHARLIE_TERM)
.append_contributor(CHARLIE_TERM)
.append_comment(PYOBO_INJECTED)
)
PROTEIN_COMPLEX = (
Term(reference=default_reference(PREFIX, "protein-complex"))
.annotate_object(has_contributor, CHARLIE_TERM)
.append_contributor(CHARLIE_TERM)
.append_comment(PYOBO_INJECTED)
)
PHENOTYPE = (
Term(reference=default_reference(PREFIX, "phenotype"))
.annotate_object(has_contributor, CHARLIE_TERM)
.append_contributor(CHARLIE_TERM)
.append_comment(PYOBO_INJECTED)
)
STIMULUS = (
Term(reference=default_reference(PREFIX, "stimulus"))
.annotate_object(has_contributor, CHARLIE_TERM)
.append_contributor(CHARLIE_TERM)
.append_comment(PYOBO_INJECTED)
)
ROOT_TERMS = (PROTEIN_FAMILY, PROTEIN_COMPLEX, PHENOTYPE, STIMULUS)
Expand Down
4 changes: 4 additions & 0 deletions src/pyobo/struct/struct_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ def annotate_object(
self._extend_annotations(typedef, value, annotations)
return self

def append_contributor(self, reference: ReferenceHint) -> Self:
"""Append contributor."""
return self.annotate_object(v.has_contributor, reference)

def get_see_also(self) -> list[Reference]:
"""Get all see also objects."""
return self.get_property_objects(v.see_also)
Expand Down

0 comments on commit 3e8796f

Please sign in to comment.