(pfm, n)
return exact_error
Calculate exact error, using multinomial(na,nc,ng,nt)
Calculate exact error, using multinomial(na,nc,ng,nt)
Calculate exact error using multinomial ( na nc ng nt )
def exact_error(pfm, n):
    """Calculate exact error, using multinomial(na,nc,ng,nt)"""
    # Super Slow. O(n^3)
    bases = list(pfm.keys())
    na = sum(pfm[bases[0]])
    n = na
    nc = 0
    ng = 0
    nt = 0
    done = False
    exact_error = 0
    while not done:
        exact_error += sum(
            [-p * np.log2(p) for p in [na / n, nc / n, ng / n, nt / n]])
        if nt <= 0:
            # iterate inner loop
            if ng > 0:
                # g => t
                ng = ng - 1
                nt = nt + 1
            elif nc > 0:
                # c -> g
                nc = nc - 1
                ng = ng + 1
            else:
                # a->c
                na = na - 1
                nc = nc + 1
        else:
            if ng > 0:
                # g => t
                ng = ng - 1
                nt = nt + 1
            elif nc > 0:
                # c => g; all t -> g
                nc = nc - 1
                ng = nt + 1
                nt = 0
            elif na > 0:
                # a => c; all g,t -> c
                nc = nt + 1
                na = na - 1
                nt = 0
            else:
                done = True
    return exact_error
def exact_error ( pfm , n ) : # Super Slow. O(n^3) bases = list ( pfm . keys ( ) ) na = sum ( pfm [ bases [ 0 ] ] ) n = na nc = 0 ng = 0 nt = 0 done = False exact_error = 0 while not done : exact_error += sum ( [ - p * np . log2 ( p ) for p in [ na / n , nc / n , ng / n , nt / n ] ] ) if nt <= 0 : # iterate inner loop if ng > 0 : # g => t ng = ng - 1 nt = nt + 1 elif nc > 0 : # c -> g nc = nc - 1 ng = ng + 1 else : # a->c na = na - 1 nc = nc + 1 else : if ng > 0 : # g => t ng = ng - 1 nt = nt + 1 elif nc > 0 : # c => g; all t -> g nc = nc - 1 ng = nt + 1 nt = 0 elif na > 0 : # a => c; all g,t -> c nc = nt + 1 na = na - 1 nt = 0 else : done = True return exact_error