Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve typedef parsing #259

Merged
merged 10 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading