Mapping Provider Interface
- class oaklib.interfaces.mapping_provider_interface.MappingProviderInterface(resource: ~oaklib.resource.OntologyResource | None = None, strict: bool = False, _multilingual: bool | None = None, autosave: bool = <factory>, exclude_owl_top_and_bottom: bool = <factory>, ontology_metamodel_mapper: ~oaklib.mappers.ontology_metadata_mapper.OntologyMetadataMapper | None = None, _converter: ~curies.api.Converter | None = None, auto_relax_axioms: bool | None = None, cache_lookups: bool = False, property_cache: ~oaklib.utilities.keyval_cache.KeyValCache = <factory>, _edge_index: ~oaklib.indexes.edge_index.EdgeIndex | None = None, _entailed_edge_index: ~oaklib.indexes.edge_index.EdgeIndex | None = None, _prefix_map: ~typing.Mapping[str, str] | None = None)[source]
An ontology interface that provides SSSOM mappings.
For more on the SSSOM Data Model, see https://w3id.org/sssom/
Note
most ontologies only include minimal metadata about mappings at this time, so many fields in the sssom mapping datamodel are not populated.
The core method in this interface is
sssom_mappings()
.Note
This interface is for serving pre-calculated mappings. See sssom_utils for on-the-fly mapping creation
Data Model
The central datamodel used here is SSSOM
Command Line Use
runoak -i bioportal: term-mappings UBERON:0002101 -O sssom -o limb-mappings.sssom.tsv
- sssom_mappings(curies: str | Iterable[str] | None = None, source: str | None = None) Iterable[Mapping] [source]
returns all sssom mappings matching filter conditions.
To fetch all mappings, simply leave the filter conditions empty:
>>> from oaklib import get_adapter >>> adapter = get_adapter("tests/input/go-nucleus.obo") >>> for mapping in adapter.sssom_mappings(): ... print(mapping.subject_id, mapping.object_id) ... GO:0016772 EC:2.7.-.- ...
To get annotations for a particular term or terms, and to constrain the source of the mapping, use the curies and source parameters:
>>> from oaklib import get_adapter >>> adapter = get_adapter("tests/input/go-nucleus.obo") >>> for mapping in adapter.sssom_mappings(["GO:0005886"], source="Wikipedia"): ... print(mapping.subject_id, mapping.object_id) GO:0005886 Wikipedia:Cell_membrane
Note you can also lookup from the perspective of the mapped entity:
>>> from oaklib import get_adapter >>> adapter = get_adapter("tests/input/go-nucleus.obo") >>> for mapping in adapter.sssom_mappings(["Wikipedia:Cell_membrane"]): ... print(mapping.subject_id, mapping.object_id) GO:0005886 Wikipedia:Cell_membrane
- Parameters:
curies – [Optional] entity IDs (in ontology or mapped ontology) to filter by
source – [Optional] only show mappings to source
- Returns:
- sssom_mappings_by_source(subject_or_object_source: str | None = None) Iterable[Mapping] [source]
All SSSOM mappings in the ontology
The subject_id MUST be a CURIE in the ontology
- Parameters:
object_source
- Returns:
- all_sssom_mappings(subject_or_object_source: str | None = None) Iterable[Mapping] [source]
Deprecated since version Replaced: by sssom_mappings()
- get_sssom_mappings_by_curie(*args, **kwargs) Iterable[Mapping] [source]
All SSSOM mappings about a curie
MUST yield mappings where EITHER subject OR object equals the CURIE
- Parameters:
kwargs
- Returns:
Deprecated since version Use: sssom_mappings()
- normalize(curie: str, target_prefixes: List[str], source_prefixes: List[str] | None = None, strict=False) str | None [source]
Normalize a CURIE to a target prefix.
>>> from oaklib import get_adapter >>> adapter = get_adapter("tests/input/go-nucleus.obo") >>> adapter.normalize("Wikipedia:Cell_membrane", ["GO"]) 'GO:0005886'
- Parameters:
curie – the CURIE to normalize
target_prefixes – the prefixes to normalize to
source_prefixes – the prefixes to normalize from
strict – if True, raise an error if there is no single mapping to a target prefix
- Returns:
the normalized CURIE
- normalize_prefix(curie: str, prefixes: Collection[str] | None = None, prefix_alias_map: Dict[str, str] | None = None) str [source]
Normalize a CURIE to a target prefix.
If a prefix alias map is supplied, this is takes precedence:
>>> from oaklib import get_adapter >>> adapter = get_adapter("tests/input/go-nucleus.obo") >>> adapter.normalize_prefix("uniprot:P12345", prefix_alias_map={"uniprot": "UniProtKB"}) 'UniProtKB:P12345'
If not prefix alias map is supplied, then the prefix is mapped to the preferred casing determined by the supplied prefixes:
>>> from oaklib import get_adapter >>> adapter = get_adapter("tests/input/go-nucleus.obo") >>> adapter.normalize_prefix("go:0000001", prefixes=["GO"]) 'GO:0000001'
- Parameters:
curie – the CURIE to normalize
prefixes – the prefixes to normalize to
prefix_alias_map – a map of prefix aliases to prefixes
- Returns:
the normalized CURIE
- create_normalization_map(curies: Iterable[str] | None = None, source_prefixes: Collection[str] | None = None, target_prefixes: Collection[str] | None = None, prefix_alias_map: Dict[str, str] | None = None) Dict[str, str] [source]
Create a normalization map for a set of CURIEs.
This map can then be used to map IDs from one prefix space to another.
For each curie in curies, find a mapping to a target prefix, and add it to the map.
>>> from oaklib import get_adapter >>> adapter = get_adapter("tests/input/go-nucleus.obo") >>> nmap = adapter.create_normalization_map(source_prefixes=["GO"], target_prefixes=["Wikipedia"]) >>> nmap["GO:0005634"] 'Wikipedia:Cell_nucleus'
You can also pass in an explicit prefix alias map:
>>> from oaklib import get_adapter >>> adapter = get_adapter("tests/input/go-nucleus.obo") >>> nmap = adapter.create_normalization_map(source_prefixes=["GO"], target_prefixes=["WIKIPEDIA"], ... prefix_alias_map={"Wikipedia": "WIKIPEDIA"}) >>> nmap["GO:0005634"] 'WIKIPEDIA:Cell_nucleus'
>>> from oaklib import get_adapter >>> adapter = get_adapter("tests/input/go-nucleus.obo") >>> nmap = adapter.create_normalization_map(source_prefixes=["go"], target_prefixes=["WIKIPEDIA"], ... prefix_alias_map={"Wikipedia": "WIKIPEDIA", "GO": "go"}) >>> nmap["go:0005634"] 'WIKIPEDIA:Cell_nucleus'
>>> from oaklib import get_adapter >>> adapter = get_adapter("tests/input/go-nucleus.obo") >>> nmap = adapter.create_normalization_map(["go:0005634"], source_prefixes=["go"], ... target_prefixes=["WIKIPEDIA"], ... prefix_alias_map={"Wikipedia": "WIKIPEDIA", "GO": "go"}) >>> nmap["go:0005634"] 'WIKIPEDIA:Cell_nucleus'
- Parameters:
curies
subject_prefixes
object_prefixes
prefix_alias_map – maps from prefixes used in the adapter to desired prefixes
- Returns: