infer_mutations

infer_mutations(mappings: Iterable[Mapping], pairs: dict[tuple[str, str], float], old_predicate: NormalizedNamableReference, new_predicate: NormalizedNamableReference, *, progress: bool = False) list[Mapping][source]

Infer mappings with alternate predicates for the given prefix pairs.

Parameters:
  • mappings – Mappings to infer from

  • pairs – A dictionary of pairs of (subject prefix, object prefix) to the confidence of inference

  • old_predicate – The predicate on which inference should be done

  • new_predicate – The predicate to get inferred

  • progress – Should a progress bar be shown? Defaults to true.

Returns:

A list of all old mapping plus inferred ones interspersed.

In the following example, we use three different terms for cranioectodermal dysplasia from the Disease Ontology (DOID), Medical Subject Headings (MeSH), and Unified Medical Language System (UMLS). We use the prior knowledge that there’s a high confidence that dbxrefs from DOID to MeSH are actually exact matches. This lets us infer m3 from m1. We don’t make any assertions about DOID-UMLS or MeSH-UMLS mappings here, so the example mapping m2 comes along for the ride.

>>> from semra.vocabulary import KNOWLEDGE_MAPPING    >>> from semra import DB_XREF, EXACT_MATCH, Reference
>>> curies = "DOID:0050577", "mesh:C562966", "umls:C4551571"
>>> r1, r2, r3 = (Reference.from_curie(c) for c in curies)
>>> m1 = Mapping.from_triple((r1, DB_XREF, r2))
>>> m2 = Mapping.from_triple((r2, DB_XREF, r3))
>>> pairs = {("DOID", "mesh"): 0.99}
>>> m3 = Mapping.from_triple(
...     (r1, EXACT_MATCH, r2),
...     evidence=[
...         ReasonedEvidence(
...             mappings=[m1], justification=KNOWLEDGE_MAPPING, confidence_factor=0.99
...         )
...     ],
... )  # this is what we are inferring  # this is what we are inferring
>>> mappings = infer_mutations([m1, m2], pairs, DB_XREF, EXACT_MATCH)
>>> assert mappings == [m1, m3, m2]