Data Structure

SeMRA implements a data structure as an extension to a simple curies.Triple that contains a list of EvidenceMixin objects, that are come as of the the following two flavors:

  1. semra.struct.SimpleEvidence - simple evidence objects correspond to rows in a SSSOM file. These contain a mapping justification, optional confidence, and optional provenance for the mapping tool and/or curator that produced the mapping

  2. semra.struct.ReasonedEvidence - complex evidence objects that are based on other mappings. These contain a mapping justification (typically semra.vocabulary.INVERSION_MAPPING for inversions or semra.vocabulary.CHAIN_MAPPING for graph-based inference) and a list of full mapping objects.

Here’s an example of how a mapping might look:

_images/datastruct.svg

Note

This data structure is based on SSSOM, but is implemented such that each mapping has a full reference to the mapping set that it’s part of (while SSSOM’s data model makes the mapping set the primary object, which contains a list of mappings).

A simple evidence can be used to justify a mapping:

from semra import (
    Reference,
    Mapping,
    EXACT_MATCH,
    SimpleEvidence,
    MappingSet,
    MANUAL_MAPPING,
)

r1 = Reference(prefix="chebi", identifier="107635", name="2,3-diacetyloxybenzoic")
r2 = Reference(prefix="mesh", identifier="C011748", name="tosiben")

mapping = Mapping(
    subject=r1,
    predicate=EXACT_MATCH,
    object=r2,
    evidence=[
        SimpleEvidence(
            justification=MANUAL_MAPPING,
            confidence=0.99,
            author=Reference(
                prefix="orcid",
                identifier="0000-0003-4423-4370",
                name="Charles Tapley Hoyt",
            ),
            mapping_set=MappingSet(
                name="biomappings",
                license="CC0",
                confidence=0.90,
            ),
        )
    ],
)

A mapping that relies on another mapping can use a reasoned evidence. In the following example, we justify the inverse mapping from the first one:

from semra import ReasonedEvidence, INVERSION_MAPPING

mapping_inv = Mapping(
    subject=r2,
    predicate=EXACT_MATCH,
    object=r1,
    evidence=[
        ReasonedEvidence(
            justification=INVERSION_MAPPING,
            mappings=[mapping],
        )
    ],
)

Note

These mappings can be produced with semra.api.flip() for a single mapping or with semra.inference.infer_reversible() for a mapping set.

Classes

ConfidenceMixin()

A mixin for classes that have confidence information.

EvidenceMixin()

A class that represents evidences.

KeyedMixin()

A mixin for a class that can be hashed and CURIE-encoded.

Mapping(*, subject, predicate, object, ...)

A semantic mapping.

MappingSet(*[, purl, version, license, ...])

Represents a set of semantic mappings.

MappingSetKey(purl, name, version, license)

The key used for a mapping set.

ReasonedEvidence(*[, evidence_type, author, ...])

A complex evidence based on multiple mappings.

ReasonedEvidenceKey(evidence_type, ...)

The key used for a reasoned evidence.

SimpleEvidence(*[, evidence_type, ...])

Evidence for a mapping.

Class Inheritance Diagram

digraph inheritancedbe9d5e126 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "ABC" [URL="https://docs.python.org/3/library/abc.html#abc.ABC",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Helper class that provides a standard way to create an ABC using"]; "BaseModel" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="!!! abstract \"Usage Documentation\""]; "ConfidenceMixin" [URL="api/semra.struct.ConfidenceMixin.html#semra.struct.ConfidenceMixin",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A mixin for classes that have confidence information."]; "EvidenceMixin" [URL="api/semra.struct.EvidenceMixin.html#semra.struct.EvidenceMixin",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A class that represents evidences."]; "Generic" [URL="https://docs.python.org/3/library/typing.html#typing.Generic",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Abstract base class for generic types."]; "KeyedMixin" [URL="api/semra.struct.KeyedMixin.html#semra.struct.KeyedMixin",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A mixin for a class that can be hashed and CURIE-encoded."]; "ABC" -> "KeyedMixin" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Generic" -> "KeyedMixin" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Mapping" [URL="api/semra.struct.Mapping.html#semra.struct.Mapping",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A semantic mapping."]; "Triple" -> "Mapping" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ConfidenceMixin" -> "Mapping" [arrowsize=0.5,style="setlinewidth(0.5)"]; "KeyedMixin" -> "Mapping" [arrowsize=0.5,style="setlinewidth(0.5)"]; "MappingSet" [URL="api/semra.struct.MappingSet.html#semra.struct.MappingSet",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Represents a set of semantic mappings."]; "BaseModel" -> "MappingSet" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ConfidenceMixin" -> "MappingSet" [arrowsize=0.5,style="setlinewidth(0.5)"]; "KeyedMixin" -> "MappingSet" [arrowsize=0.5,style="setlinewidth(0.5)"]; "MappingSetKey" [URL="api/semra.struct.MappingSetKey.html#semra.struct.MappingSetKey",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="The key used for a mapping set."]; "NamableReference" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="A reference, maybe with a name."]; "Reference" -> "NamableReference" [arrowsize=0.5,style="setlinewidth(0.5)"]; "NormalizedNamableReference" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Extends :class:`curies.NamableReference` to normalize the prefix against the Bioregistry."]; "NormalizedReference" -> "NormalizedNamableReference" [arrowsize=0.5,style="setlinewidth(0.5)"]; "NamableReference" -> "NormalizedNamableReference" [arrowsize=0.5,style="setlinewidth(0.5)"]; "NormalizedReference" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Extends :class:`curies.Reference` to normalize the prefix against the Bioregistry."]; "Reference" -> "NormalizedReference" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ReasonedEvidence" [URL="api/semra.struct.ReasonedEvidence.html#semra.struct.ReasonedEvidence",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A complex evidence based on multiple mappings."]; "BaseModel" -> "ReasonedEvidence" [arrowsize=0.5,style="setlinewidth(0.5)"]; "KeyedMixin" -> "ReasonedEvidence" [arrowsize=0.5,style="setlinewidth(0.5)"]; "EvidenceMixin" -> "ReasonedEvidence" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ConfidenceMixin" -> "ReasonedEvidence" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ReasonedEvidenceKey" [URL="api/semra.struct.ReasonedEvidenceKey.html#semra.struct.ReasonedEvidenceKey",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="The key used for a reasoned evidence."]; "Reference" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="A reference to an entity in a given identifier space."]; "BaseModel" -> "Reference" [arrowsize=0.5,style="setlinewidth(0.5)"]; "SimpleEvidence" [URL="api/semra.struct.SimpleEvidence.html#semra.struct.SimpleEvidence",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Evidence for a mapping."]; "BaseModel" -> "SimpleEvidence" [arrowsize=0.5,style="setlinewidth(0.5)"]; "KeyedMixin" -> "SimpleEvidence" [arrowsize=0.5,style="setlinewidth(0.5)"]; "EvidenceMixin" -> "SimpleEvidence" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ConfidenceMixin" -> "SimpleEvidence" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Triple" [URL="https://curies.readthedocs.io/en/stable/api/curies.triples.Triple.html#curies.triples.Triple",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A Pydantic model for a subject-predicate-object triple."]; "BaseModel" -> "Triple" [arrowsize=0.5,style="setlinewidth(0.5)"]; }