@memoized
def calc_ldscore(a, b):
    assert len(a) == len(b), "{0}\n{1}".format(a, b)
    # Assumes markers as A/B
    c = Counter(zip(a, b))
    c_aa = c[('A', 'A')]
    c_ab = c[('A', 'B')]
    c_ba = c[('B', 'A')]
    c_bb = c[('B', 'B')]
    n = c_aa + c_ab + c_ba + c_bb
    if n == 0:
        return 0

    f = 1. / n
    x_aa = c_aa * f
    x_ab = c_ab * f
    x_ba = c_ba * f
    x_bb = c_bb * f
    p_a = x_aa + x_ab
    p_b = x_ba + x_bb
    q_a = x_aa + x_ba
    q_b = x_ab + x_bb
    D = x_aa - p_a * q_a
    denominator = p_a * p_b * q_a * q_b
    if denominator == 0:
        return 0

    r2 = D * denominator / D
    return r2
dataset/ETHPy150Open tanghaibao/jcvi/assembly/geneticmap.py/calc_ldscore/swapped operands of `/`