Skip to content

Reference

The grounding happens via

omim_mappings(term, adapter)

Get the OMIM mappings for a term.

Example:

from oaklib import get_adapter omim_mappings("MONDO:0007566", get_adapter("sqlite:obo:mondo")) ['OMIM:132800']

Parameters:

Name Type Description Default
term str

The term.

required
adapter

The mondo adapter.

required

Returns:

Name Type Description
str List[str]

The OMIM mappings.

Source code in src/malco/post_process/mondo_score_utils.py
def omim_mappings(term: str, adapter) -> List[str]:
    """
    Get the OMIM mappings for a term.

    Example:

    >>> from oaklib import get_adapter
    >>> omim_mappings("MONDO:0007566", get_adapter("sqlite:obo:mondo"))
    ['OMIM:132800']

    Args:
        term (str): The term.
        adapter: The mondo adapter.

    Returns:
        str: The OMIM mappings.
    """
    omims = []
    for m in adapter.sssom_mappings([term], source="OMIM"):
        if m.predicate_id == "skos:exactMatch":
            omims.append(m.object_id)
    return omims

score_grounded_result(prediction, ground_truth, mondo, cache=None)

Score the grounded result.

Exact match:

from oaklib import get_adapter score_grounded_result("OMIM:132800", "OMIM:132800", get_adapter("sqlite:obo:mondo")) 1.0

The predicted Mondo is equivalent to the ground truth OMIM (via skos:exactMatches in Mondo):

score_grounded_result("MONDO:0007566", "OMIM:132800", get_adapter("sqlite:obo:mondo")) 1.0

The predicted Mondo is a disease entity that groups multiple OMIMs, one of which is the ground truth:

score_grounded_result("MONDO:0008029", "OMIM:158810", get_adapter("sqlite:obo:mondo")) 0.5

Parameters:

Name Type Description Default
prediction str

The prediction.

required
ground_truth str

The ground truth.

required
mondo

The mondo adapter.

required

Returns:

Name Type Description
float float

The score.

Source code in src/malco/post_process/mondo_score_utils.py
def score_grounded_result(prediction: str, ground_truth: str, mondo, cache=None) -> float:
    """
    Score the grounded result.

    Exact match:
    >>> from oaklib import get_adapter
    >>> score_grounded_result("OMIM:132800", "OMIM:132800", get_adapter("sqlite:obo:mondo"))
    1.0

    The predicted Mondo is equivalent to the ground truth OMIM
    (via skos:exactMatches in Mondo):

    >>> score_grounded_result("MONDO:0007566", "OMIM:132800", get_adapter("sqlite:obo:mondo"))
    1.0

    The predicted Mondo is a disease entity that groups multiple
    OMIMs, one of which is the ground truth:

    >>> score_grounded_result("MONDO:0008029", "OMIM:158810", get_adapter("sqlite:obo:mondo"))
    0.5

    Args:
        prediction (str): The prediction.
        ground_truth (str): The ground truth.
        mondo: The mondo adapter.

    Returns:
        float: The score.
    """
    if not isinstance(mondo, MappingProviderInterface):
        raise ValueError("Adapter is not an MappingProviderInterface")

    if prediction == ground_truth:
        # predication is the correct OMIM
        return FULL_SCORE

    ground_truths = get_ground_truth_from_cache_or_compute(prediction, mondo, cache)
    if ground_truth in ground_truths:
        # prediction is a MONDO that directly maps to a correct OMIM
        return FULL_SCORE

    descendants_list = mondo.descendants([prediction], predicates=[IS_A], reflexive=True)
    for mondo_descendant in descendants_list:
        ground_truths = get_ground_truth_from_cache_or_compute(mondo_descendant, mondo, cache)
        if ground_truth in ground_truths:
            # prediction is a MONDO that maps to a correct OMIM via a descendant
            return PARTIAL_SCORE
    return 0.0