Skip to content

Commit

Permalink
Implement rewiring (#977)
Browse files Browse the repository at this point in the history
Closes #976

Fixes a bug where the rewiring configuration from a prescriptive context
wasn't used. For the OBO context, this is applicable for `PMID`. Now,
there are explicit tests about this too.

CC @matentzn, but no action needed
  • Loading branch information
cthoyt authored Nov 2, 2023
1 parent 0c4ff72 commit fe07b38
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion exports/contexts/obo.context.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
"PLANA": "http://purl.obolibrary.org/obo/PLANA_",
"PLANP": "http://purl.obolibrary.org/obo/PLANP_",
"PLO": "http://purl.obolibrary.org/obo/PLO_",
"PMID": "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
"PMID": "https://www.ncbi.nlm.nih.gov/pubmed/",
"PO": "http://purl.obolibrary.org/obo/PO_",
"PORO": "http://purl.obolibrary.org/obo/PORO_",
"PPO": "http://purl.obolibrary.org/obo/PPO_",
Expand Down
2 changes: 1 addition & 1 deletion exports/contexts/obo.context.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
[ sh:prefix "PLANA" ; sh:namespace "http://purl.obolibrary.org/obo/PLANA_"^^xsd:anyURI ; sh:pattern "^\\d{7}$" ],
[ sh:prefix "PLANP" ; sh:namespace "http://purl.obolibrary.org/obo/PLANP_"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
[ sh:prefix "PLO" ; sh:namespace "http://purl.obolibrary.org/obo/PLO_"^^xsd:anyURI ],
[ sh:prefix "PMID" ; sh:namespace "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
[ sh:prefix "PMID" ; sh:namespace "https://www.ncbi.nlm.nih.gov/pubmed/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
[ sh:prefix "PO" ; sh:namespace "http://purl.obolibrary.org/obo/PO_"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
[ sh:prefix "PORO" ; sh:namespace "http://purl.obolibrary.org/obo/PORO_"^^xsd:anyURI ; sh:pattern "^\\d{7}$" ],
[ sh:prefix "PPO" ; sh:namespace "http://purl.obolibrary.org/obo/PPO_"^^xsd:anyURI ; sh:pattern "^\\d{7}$" ],
Expand Down
6 changes: 3 additions & 3 deletions exports/contexts/obo.epm.json
Original file line number Diff line number Diff line change
Expand Up @@ -4366,7 +4366,7 @@
"pmid",
"pubmed"
],
"uri_prefix": "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
"uri_prefix": "https://www.ncbi.nlm.nih.gov/pubmed/",
"uri_prefix_synonyms": [
"http://bio2rdf.org/pubmed:",
"http://bioregistry.io/MEDLINE:",
Expand All @@ -4382,6 +4382,7 @@
"http://pubmed.ncbi.nlm.nih.gov/",
"http://purl.uniprot.org/citations/",
"http://purl.uniprot.org/pubmed/",
"http://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
"http://scholia.toolforge.org/pubmed/",
"http://www.hubmed.org/display.cgi?uids=",
"http://www.ncbi.nlm.nih.gov/pubmed/",
Expand All @@ -4401,8 +4402,7 @@
"https://purl.uniprot.org/pubmed/",
"https://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
"https://scholia.toolforge.org/pubmed/",
"https://www.hubmed.org/display.cgi?uids=",
"https://www.ncbi.nlm.nih.gov/pubmed/"
"https://www.hubmed.org/display.cgi?uids="
]
},
{
Expand Down
10 changes: 5 additions & 5 deletions exports/contexts/obo_synonyms.context.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
"MC": "http://purl.obolibrary.org/obo/MC_",
"MCO": "http://purl.obolibrary.org/obo/MCO_",
"MCRO": "http://purl.obolibrary.org/obo/MCRO_",
"MEDLINE": "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
"MEDLINE": "https://www.ncbi.nlm.nih.gov/pubmed/",
"MEDRA": "http://purl.bioontology.org/ontology/MDRFRE/",
"MESH": "http://id.nlm.nih.gov/mesh/",
"MESHA": "http://id.nlm.nih.gov/mesh/",
Expand Down Expand Up @@ -437,7 +437,7 @@
"PLO": "http://purl.obolibrary.org/obo/PLO_",
"PMC": "http://europepmc.org/articles/",
"PMCID": "http://europepmc.org/articles/",
"PMID": "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
"PMID": "https://www.ncbi.nlm.nih.gov/pubmed/",
"PO": "http://purl.obolibrary.org/obo/PO_",
"PORO": "http://purl.obolibrary.org/obo/PORO_",
"PPO": "http://purl.obolibrary.org/obo/PPO_",
Expand All @@ -459,7 +459,7 @@
"Progenetix": "https://progenetix.org/services/ids/",
"PuRO": "http://purl.org/spar/pro/",
"PubChem_Compound_CID": "http://rdf.ncbi.nlm.nih.gov/pubchem/compound/CID",
"PubMed": "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
"PubMed": "https://www.ncbi.nlm.nih.gov/pubmed/",
"Pubchem": "http://rdf.ncbi.nlm.nih.gov/pubchem/compound/CID",
"RBO": "http://purl.obolibrary.org/obo/RBO_",
"RCSB_PDB": "https://rdf.wwpdb.org/pdb/",
Expand Down Expand Up @@ -1657,7 +1657,7 @@
"pmap.substratedb": "https://identifiers.org/pmap.substratedb:",
"pmc": "http://europepmc.org/articles/",
"pmdb": "https://bioinformatics.cineca.it/PMDB/user//search.php?idsearch=",
"pmid": "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
"pmid": "https://www.ncbi.nlm.nih.gov/pubmed/",
"pmp": "http://purl.uniprot.org/uniprot/",
"pmr": "https://models.physiomeproject.org/exposure/",
"pmr.workspace": "https://models.physiomeproject.org/workspace/",
Expand Down Expand Up @@ -1697,7 +1697,7 @@
"pubchem_id": "http://rdf.ncbi.nlm.nih.gov/pubchem/compound/CID",
"publons.publication": "https://publons.com/publon/",
"publons.researcher": "https://publons.com/researcher/",
"pubmed": "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/",
"pubmed": "https://www.ncbi.nlm.nih.gov/pubmed/",
"px": "http://proteomecentral.proteomexchange.org/cgi/GetDataset?ID=",
"pypi": "https://pypi.org/project/",
"qb": "http://purl.org/linked-data/cube#",
Expand Down
10 changes: 5 additions & 5 deletions exports/contexts/obo_synonyms.context.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,11 @@
[ sh:prefix "PLANA" ; sh:namespace "http://purl.obolibrary.org/obo/PLANA_"^^xsd:anyURI ; sh:pattern "^\\d{7}$" ],
[ sh:prefix "PLANP" ; sh:namespace "http://purl.obolibrary.org/obo/PLANP_"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
[ sh:prefix "PLO" ; sh:namespace "http://purl.obolibrary.org/obo/PLO_"^^xsd:anyURI ],
[ sh:prefix "PMID" ; sh:namespace "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
[ sh:prefix "MEDLINE" ; sh:namespace "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
[ sh:prefix "PubMed" ; sh:namespace "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
[ sh:prefix "pmid" ; sh:namespace "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
[ sh:prefix "pubmed" ; sh:namespace "http://rdf.ncbi.nlm.nih.gov/pubchem/reference/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
[ sh:prefix "PMID" ; sh:namespace "https://www.ncbi.nlm.nih.gov/pubmed/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
[ sh:prefix "MEDLINE" ; sh:namespace "https://www.ncbi.nlm.nih.gov/pubmed/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
[ sh:prefix "PubMed" ; sh:namespace "https://www.ncbi.nlm.nih.gov/pubmed/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
[ sh:prefix "pmid" ; sh:namespace "https://www.ncbi.nlm.nih.gov/pubmed/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
[ sh:prefix "pubmed" ; sh:namespace "https://www.ncbi.nlm.nih.gov/pubmed/"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
[ sh:prefix "PO" ; sh:namespace "http://purl.obolibrary.org/obo/PO_"^^xsd:anyURI ; sh:pattern "^\\d+$" ],
[ sh:prefix "PORO" ; sh:namespace "http://purl.obolibrary.org/obo/PORO_"^^xsd:anyURI ; sh:pattern "^\\d{7}$" ],
[ sh:prefix "PPO" ; sh:namespace "http://purl.obolibrary.org/obo/PPO_"^^xsd:anyURI ; sh:pattern "^\\d{7}$" ],
Expand Down
3 changes: 3 additions & 0 deletions src/bioregistry/record_accumulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def get_converter(
strict: bool = False,
blacklist: Optional[Collection[str]] = None,
remapping: Optional[Mapping[str, str]] = None,
rewiring: Optional[Mapping[str, str]] = None,
) -> Converter:
"""Generate a converter from resources."""
records = _get_records(
Expand All @@ -130,6 +131,8 @@ def get_converter(
converter = curies.Converter(records)
if remapping:
converter = curies.remap_curie_prefixes(converter, remapping)
if rewiring:
converter = curies.rewire(converter, rewiring)
return converter


Expand Down
16 changes: 9 additions & 7 deletions src/bioregistry/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ def get_converter(
include_prefixes: bool = False,
strict: bool = False,
remapping: Optional[Mapping[str, str]] = None,
rewiring: Optional[Mapping[str, str]] = None,
blacklist: Optional[typing.Collection[str]] = None,
) -> curies.Converter:
"""Get a converter from this manager.
Expand All @@ -657,6 +658,7 @@ def get_converter(
If true, errors on URI prefix collisions. If false, sends logging
and skips them.
:param remapping: A mapping from bioregistry prefixes to preferred prefixes.
:param rewiring: A mapping from bioregistry prefixes to new URI prefixes.
:param blacklist:
A collection of prefixes to skip
Expand All @@ -677,6 +679,7 @@ def get_converter(
strict=strict,
blacklist=blacklist,
remapping=remapping,
rewiring=rewiring,
)
return converter

Expand Down Expand Up @@ -727,6 +730,7 @@ def get_prefix_map(
prefix_priority: Optional[Sequence[str]] = None,
include_synonyms: bool = False,
remapping: Optional[Mapping[str, str]] = None,
rewiring: Optional[Mapping[str, str]] = None,
blacklist: Optional[typing.Collection[str]] = None,
) -> Mapping[str, str]:
"""Get a mapping from Bioregistry prefixes to their URI prefixes .
Expand All @@ -740,22 +744,18 @@ def get_prefix_map(
:param include_synonyms: Should synonyms of each prefix also be included as additional prefixes, but with
the same URI prefix?
:param remapping: A mapping from Bioregistry prefixes to preferred prefixes.
:param rewiring: A mapping from Bioregistry prefixes to URI prefixes.
:param blacklist: Prefixes to skip
:return: A mapping from prefixes to URI prefixes.
"""
converter = self.get_converter(
prefix_priority=prefix_priority,
uri_prefix_priority=uri_prefix_priority,
remapping=remapping,
rewiring=rewiring,
blacklist=blacklist,
)
rv = {}
for record in converter.records:
rv[record.prefix] = record.uri_prefix
if include_synonyms:
for prefix in record.prefix_synonyms:
rv[prefix] = record.uri_prefix
return rv
return converter.prefix_map if include_synonyms else converter.bimap

def get_curie_pattern(self, prefix: str, *, use_preferred: bool = False) -> Optional[str]:
r"""Get the CURIE pattern for this resource.
Expand Down Expand Up @@ -1586,6 +1586,7 @@ def get_converter_from_context(
uri_prefix_priority=context.uri_prefix_priority,
strict=strict,
remapping=context.prefix_remapping,
rewiring=context.custom_prefix_map,
blacklist=context.blacklist,
include_prefixes=include_prefixes,
)
Expand All @@ -1606,6 +1607,7 @@ def get_context_artifacts(
prefix_priority=context.prefix_priority,
include_synonyms=include_synonyms,
blacklist=context.blacklist,
rewiring=context.custom_prefix_map,
)
prescriptive_pattern_map = self.get_pattern_map(
remapping=context.prefix_remapping,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_obo_context(self):
self.assertEqual(f"{p}/FBcv_", prefix_map["FBcv"])
self.assertIn("GEO", prefix_map)
self.assertEqual(f"{p}/GEO_", prefix_map["GEO"])
self.assertEqual("https://www.ncbi.nlm.nih.gov/pubmed/", prefix_map["PMID"])

self.assertNotIn("biomodels.kisao", prefix_map)

Expand All @@ -64,6 +65,7 @@ def test_obo_converter(self):
self.assertEqual("Orphanet", converter.standardize_prefix("ordo"))
self.assertEqual("GO", converter.standardize_prefix("GO"))
self.assertEqual("GO", converter.standardize_prefix("gomf"))
self.assertEqual("https://www.ncbi.nlm.nih.gov/pubmed/", converter.bimap["PMID"])
# FIXME later, handle adding canonical bioregistry prefix
# as synonym when non-default prefix priority ordering is given
# self.assertEqual("GO", converter.standardize_prefix("go"))
Expand Down

0 comments on commit fe07b38

Please sign in to comment.