def calc_term_overlap(termsA, termsB):
    """
    Calculate the reciprocal overlap between two lists of HPO terms
    """

    nA = len(termsA)
    nB = len(termsB)

    if nA == 0 or nB == 0:
        ro = 0
    else:
        nOvr = len(set(termsA).intersection(set(termsB)))
        oA = nOvr / nA
        oB = nOvr / nB
        ro = min([oA, oB])

    return ro