def _binom_logpmf(X, N, P): val = binom.logpmf( np.array([X], dtype=np.int64), np.array([N], dtype=np.int64), np.array([P], dtype=np.float64), ) return val[0]
def _calc_llh(var_reads, ref_reads, omega, A, Z, psi): K = len(psi) assert Z.shape == (K, K) assert var_reads.shape == ref_reads.shape == omega.shape eta = util.softmax(psi) phi = np.dot(Z, eta) # Kx1 var_phis = np.dot(A, phi) logp = binom.logpmf(var_reads, ref_reads + var_reads, var_phis * omega) return np.sum(logp)
def _integral_same_cluster(args): phi1, V1_var_reads, V1_ref_reads, V1_omega, V2_var_reads, V2_ref_reads, V2_omega, logsub = args V1_total_reads = V1_var_reads + V1_ref_reads V2_total_reads = V2_var_reads + V2_ref_reads X = np.array([V1_var_reads, V2_var_reads]) N = np.array([V1_total_reads, V2_total_reads]) P = np.array([V1_omega * phi1, V2_omega * phi1]) B = binom.logpmf(X, N, P) logP = B[0] + B[1] - logsub return np.exp(logP)
def integral_same_cluster(phi1, V1, V2, sidx, logsub): binom_params = [( V.var_reads[sidx], V.total_reads[sidx], V.omega_v[sidx] * phi1, ) for V in (V1, V2)] X, N, P = [np.array(A) for A in zip(*binom_params)] B = binom.logpmf(X, N, P) # The `log(sqrt(2))` comes from computing the line integral. See theorem 6.3 # ("Evaluating a Scalar Line Integral") at # https://openstax.org/books/calculus-volume-3/pages/6-2-line-integrals. logP = np.log(np.sqrt(2)) + B[0] + B[1] - logsub return np.exp(logP)
def calc_llh(var_reads, ref_reads, A, Z, psi): total_reads = var_reads + ref_reads mut_p = calc_mut_p(A, Z, psi) mut_probs = binom.logpmf(var_reads, total_reads, mut_p) return np.sum(mut_probs)
def binom_logpmf_scalar(X, N, P): return binom.logpmf( np.array([X]), np.array([N]), np.array([P]), )[0]