Skip to content

Commit

Permalink
Improve typedef parsing (#259)
Browse files Browse the repository at this point in the history
This PR introduces a new function that consolidates parsing when an
unprefixed identifier should be tried to be grounded against RO/BFO.

It also does a bit of renaming to make the diff easier to read
  • Loading branch information
cthoyt authored Dec 3, 2024
1 parent 8fcf1fc commit 15ff667
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 132 deletions.
6 changes: 5 additions & 1 deletion src/pyobo/getters.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def get_ontology(
strict: bool = True,
version: str | None = None,
robot_check: bool = True,
upgrade: bool = True,
) -> Obo:
"""Get the OBO for a given graph.
Expand All @@ -81,6 +82,9 @@ def get_ontology(
:param robot_check:
If set to false, will send the ``--check=false`` command to ROBOT to disregard
malformed ontology components. Necessary to load some ontologies like VO.
:param upgrade:
If set to true, will automatically upgrade relationships, such as
``obo:chebi#part_of`` to ``BFO:0000051``
:returns: An OBO object
:raises OnlyOWLError: If the OBO foundry only has an OWL document for this resource.
Expand Down Expand Up @@ -132,7 +136,7 @@ def get_ontology(
else:
raise UnhandledFormatError(f"[{prefix}] unhandled ontology file format: {path.suffix}")

obo = from_obo_path(path, prefix=prefix, strict=strict, version=version)
obo = from_obo_path(path, prefix=prefix, strict=strict, version=version, upgrade=upgrade)
obo.write_default(force=force_process)
return obo

Expand Down
12 changes: 7 additions & 5 deletions src/pyobo/identifier_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def normalize_curie(
strict: bool = True,
ontology_prefix: str | None = None,
node: Reference | None = None,
upgrade: bool = True,
) -> ReferenceTuple | tuple[None, None]:
"""Parse a string that looks like a CURIE.
Expand All @@ -86,11 +87,12 @@ def normalize_curie(
- Normalizes the namespace
- Checks against a blacklist for the entire curie, for the namespace, and for suffixes.
"""
# Remap the curie with the full list
curie = remap_full(curie)
if upgrade:
# Remap the curie with the full list
curie = remap_full(curie)

# Remap node's prefix (if necessary)
curie = remap_prefix(curie, ontology_prefix=ontology_prefix)
# Remap node's prefix (if necessary)
curie = remap_prefix(curie, ontology_prefix=ontology_prefix)

if curie_is_blacklisted(curie):
return None, None
Expand All @@ -99,7 +101,7 @@ def normalize_curie(
if curie_has_blacklisted_suffix(curie):
return None, None

if reference_t := bioontologies.upgrade.upgrade(curie):
if upgrade and (reference_t := bioontologies.upgrade.upgrade(curie)):
return reference_t

if curie.startswith("http:") or curie.startswith("https:"):
Expand Down
Loading

0 comments on commit 15ff667

Please sign in to comment.