Skip to content

Commit

Permalink
Clean up annotations typing
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Jan 11, 2025
1 parent afcedd1 commit 50146b2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
5 changes: 2 additions & 3 deletions src/pyobo/reader_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from pyobo.struct.reference import _parse_identifier
from pyobo.struct.struct import Reference, SynonymTypeDef, _synonym_typedef_warn
from pyobo.struct.struct_utils import Annotation

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -115,7 +116,5 @@ def _chomp_references(
return references, rest


def _chomp_axioms(
s: str, *, strict: bool = True, node: Reference
) -> list[tuple[Reference, Reference]]:
def _chomp_axioms(s: str, *, strict: bool = True, node: Reference) -> list[Annotation]:
return []
14 changes: 3 additions & 11 deletions src/pyobo/struct/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class Synonym:
provenance: list[Reference] = field(default_factory=list)

#: Extra annotations
annotations: list[tuple[Reference, Reference]] = field(default_factory=list)
annotations: list[Annotation] = field(default_factory=list)

def __lt__(self, other: Synonym) -> bool:
"""Sort lexically by name."""
Expand Down Expand Up @@ -405,11 +405,7 @@ def iterate_obo_lines(
if emit_annotation_properties:
yield from self._iterate_obo_properties(
ontology_prefix=ontology_prefix,
skip_predicates=[
v.term_replaced_by,
v.see_also,
v.alternative_term,
],
skip_predicates=v.SKIP_PROPERTY_PREDICATES,
typedefs=typedefs,
)
# 13
Expand Down Expand Up @@ -1848,11 +1844,7 @@ def iterate_obo_lines(
# 11
yield from self._iterate_obo_properties(
ontology_prefix=ontology_prefix,
skip_predicates={
v.term_replaced_by,
v.see_also,
v.alternative_term,
},
skip_predicates=v.SKIP_PROPERTY_PREDICATES,
typedefs=typedefs,
)
# 12
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 @@ -331,6 +331,10 @@ def annotate_object(
self._annotate_axioms(typedef, value, axioms)
return self

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

def get_replaced_by(self) -> list[Reference]:
"""Get all replaced by."""
return self.get_property_objects(v.term_replaced_by)
Expand Down
10 changes: 8 additions & 2 deletions src/pyobo/struct/vocabulary.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"mapping_has_justification",
]


RO_PREFIX = "RO"
BFO_PREFIX = "BFO"
IAO_PREFIX = "IAO"
Expand Down Expand Up @@ -53,7 +52,6 @@ def _c(c: curies.NamedReference) -> Reference:
see_also = Reference(prefix="rdfs", identifier="seeAlso", name="see also")
comment = Reference(prefix="rdfs", identifier="comment", name="comment")


from_species = Reference(prefix=RO_PREFIX, identifier="0002162", name="in taxon")
species_specific = Reference(prefix="debio", identifier="0000007", name="species specific")
has_left_to_right_reaction = Reference(
Expand Down Expand Up @@ -96,3 +94,11 @@ def _c(c: curies.NamedReference) -> Reference:
alternative_term,
term_replaced_by,
)

#: These are predicates that have their own dedicated fields
#: in OBO and FunOWL output
SKIP_PROPERTY_PREDICATES = [
term_replaced_by,
see_also,
alternative_term,
]

0 comments on commit 50146b2

Please sign in to comment.