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

Propogate RDF URI format string to API and update EDAM #924

Merged
merged 5 commits into from
Aug 15, 2023
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
3 changes: 3 additions & 0 deletions src/bioregistry/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def _get_resource_providers(
metaprefix = prefix
name = manager.get_name(prefix)
homepage = manager.get_homepage(prefix)
elif metaprefix == "rdf":
name = f"{manager.get_name(prefix)} (RDF)"
homepage = manager.get_homepage(prefix)
else:
name = manager.get_registry_name(metaprefix)
homepage = manager.get_registry_homepage(metaprefix)
Expand Down
2 changes: 2 additions & 0 deletions src/bioregistry/data/bioregistry.json
Original file line number Diff line number Diff line change
Expand Up @@ -27317,6 +27317,7 @@
"prefix": "edam",
"uri_format": "http://purl.bioontology.org/ontology/EDAM/$1"
},
"name": "EDAM Ontology",
"ols": {
"contact": "[email protected]",
"description": "EDAM is a simple ontology of well established, familiar concepts that are prevalent within bioinformatics, including types of data and data identifiers, data formats, operations and topics. EDAM provides a set of terms with synonyms and definitions - organised into an intuitive hierarchy for convenient use.",
Expand Down Expand Up @@ -27352,6 +27353,7 @@
"year": 2013
}
],
"rdf_uri_format": "http://edamontology.org/$1",
"repository": "https://github.com/edamontology/edamontology",
"twitter": "edamontology",
"uri_format": "https://www.ebi.ac.uk/ols/ontologies/edam/terms?iri=http://edamontology.org/$1"
Expand Down
36 changes: 32 additions & 4 deletions src/bioregistry/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,22 @@ def get_default_iri(self, prefix: str, identifier: str) -> Optional[str]:
return None
return entry.get_default_uri(identifier)

def get_rdf_uri(self, prefix: str, identifier: str) -> Optional[str]:
"""Get the RDF URI for the given CURIE.

:param prefix: The prefix in the CURIE
:param identifier: The identifier in the CURIE
:return: A IRI string corresponding to the canonical RDF provider, if available.

>>> from bioregistry import manager
>>> manager.get_rdf_uri('edam', 'data_1153')
'http://edamontology.org/data_1153'
"""
entry = self.get_resource(prefix)
if entry is None:
return None
return entry.get_rdf_uri(identifier)

def get_miriam_curie(self, prefix: str, identifier: str) -> Optional[str]:
"""Get the identifiers.org CURIE for the given CURIE."""
resource = self.get_resource(prefix)
Expand Down Expand Up @@ -1173,6 +1189,7 @@ def get_provider_functions(self) -> Mapping[str, Callable[[str, str], Optional[s
"""Return a mapping of provider functions."""
return {
"default": self.get_default_iri,
"rdf": self.get_rdf_uri,
"miriam": self.get_miriam_iri,
"obofoundry": self.get_obofoundry_iri,
"ols": self.get_ols_iri,
Expand All @@ -1199,12 +1216,23 @@ def get_providers_list(self, prefix: str, identifier: str) -> Sequence[Tuple[str
return rv

bioregistry_link = self.get_bioregistry_iri(prefix, identifier)
if not bioregistry_link:
return rv
if bioregistry_link:
rv.append(("bioregistry", bioregistry_link))

def _key(t):
if t[0] == "default":
return 0
elif t[0] == "rdf":
return 1
elif t[0] == "bioregistry":
return 2
else:
return 3

# if a default URL is available, it goes first. otherwise the bioregistry URL goes first.
rv.insert(1 if rv[0][0] == "default" else 0, ("bioregistry", bioregistry_link))
rv = sorted(rv, key=_key)
return rv
# if a default URL is available, it goes first. otherwise the bioregistry URL goes first.
# rv.insert(1 if rv[0][0] == "default" else 0, ("bioregistry", bioregistry_link))

def get_providers(self, prefix: str, identifier: str) -> Dict[str, str]:
"""Get all providers for the CURIE.
Expand Down
15 changes: 15 additions & 0 deletions src/bioregistry/schema/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,21 @@ def get_default_uri(self, identifier: str) -> Optional[str]:
return None
return fmt.replace("$1", identifier)

def get_rdf_uri(self, identifier: str) -> Optional[str]:
"""Return the RDF URI for the identifier.

:param identifier: The local identifier in the nomenclature represented by this resource
:returns: The canonical RDF URI for the local identifier, if one can be constructed

>>> from bioregistry import get_resource
>>> get_resource("edam").get_rdf_uri("data_1153")
'http://edamontology.org/data_1153'
"""
fmt = self.get_rdf_uri_format()
if fmt is None:
return None
return fmt.replace("$1", identifier)

def __setitem__(self, key, value): # noqa: D105
setattr(self, key, value)

Expand Down