def score_efo(endpoint_doids, efo_doids):
    """Compute a score for a match of two sets of DOIDs.

    Score is built with:
    - number of DOID that matches in the 2 sets
    - number of DOID attributed to the EFO but not the endpoint

    Sorting these, the last item is the best. It will have the maximum
    number of matches. In case of equality, the EFO with less non
    matching DOIDs will have a higher score.
    """
    matches = efo_doids.intersection(endpoint_doids)
    non_matches = efo_doids - endpoint_doids
    score = (len(matches), - len(non_matches))
    return score