def spoof_maxent_motifs(motif, num_motifs, verbose=False, A=4): N = len(motif) L = len(motif[0]) des_ic = motif_ic(motif, A=A) if verbose: print "N: {} L: {} des_ic: {}".format(N, L, des_ic) return maxent_motifs(N, L, des_ic, num_motifs, verbose=verbose, A=A)
def spoof_motif_cftp(motif, num_motifs=10, trials=1, sigma=None,Ne_tol=10**-2,verbose=False): n = len(motif) L = len(motif[0]) copies = 10*n if sigma is None: sigma = sigma_from_matrix(pssm_from_motif(motif,pc=1)) print "sigma:", sigma bio_ic = motif_ic(motif) matrix = sample_matrix(L, sigma) mu = approx_mu(matrix, copies=10*n, G=5*10**6) print "mu:", mu def f(Ne): motifs = [sample_motif_cftp(matrix, mu, Ne, n, verbose=verbose) for i in trange(trials)] return mean(map(motif_ic,motifs)) - bio_ic # lb = 1 # ub = 10 # while f(ub) < 0: # ub *= 2 # print ub x0s = [2,10]#(lb + ub)/2.0 # print "choosing starting seed for Ne" # fs = map(lambda x:abs(f(x)),x0s) # print "starting values:",x0s,fs # x0 = x0s[argmin(fs)] # print "chose:",x0 # Ne = bisect_interval_noisy_ref(f,x0,lb=1,verbose=True) Ne = log_regress_spec2(f,x0s,tol=Ne_tol) print "Ne:",Ne return [sample_motif_cftp(matrix, mu, Ne, n) for _ in trange(num_motifs)]
def spoof_maxent_motif(motif, verbose=False, A=4): N = len(motif) L = len(motif[0]) des_ic = motif_ic(motif) if verbose: print "n: {} L: {} des_ic: {}".format(n, L, des_ic) return maxent_motif(N, L, des_ic, verbose=verbose, A=A)
def spoof_maxent_motifs(motif,num_motifs,verbose=False, A=4): N = len(motif) L = len(motif[0]) des_ic = motif_ic(motif, A=A) if verbose: print "N: {} L: {} des_ic: {}".format(N,L,des_ic) return maxent_motifs(N,L,des_ic,num_motifs,verbose=verbose, A=A)
def spoof_maxent_motif(motif,verbose=False, A=4): N = len(motif) L = len(motif[0]) des_ic = motif_ic(motif) if verbose: print "n: {} L: {} des_ic: {}".format(n,L,des_ic) return maxent_motif(N,L,des_ic,verbose=verbose, A=A)
def spoof_uniform_motifs(motif, num_motifs, epsilon=0.1, verbose=False): N, L = len(motif), len(motif[0]) desired_ic = motif_ic(motif) if verbose: print "starting spoof motifs uniform with:", N, L, desired_ic return uniform_motifs(N, L, desired_ic, num_motifs, epsilon, verbose=verbose)
def test_spoof_motif_cftp(): motif = [ 'CGGTGAACTA', 'CGGTGTGCGA', 'CGCTGTGCTG', 'CGGGATGCAA', 'CACGCTACGA', 'CGCTATGCTA', 'CGGTTGGCTA', 'CGGCGTGCTA', 'CGGTATATTG', 'CGGGTTGCGA' ] given_ic = motif_ic(motif) # ~ 9.05 bits motifs = spoof_motif_cftp(motif, num_motifs=1000) spoof_ics = map(motif_ic, motifs) lb, ub = mean_ci(spoof_ics) print lb, given_ic, ub assert_less_equal(lb - 1, given_ic) assert_less_equal(given_ic, ub + 1)
def test_spoof_motif_cftp(): motif = ['CGGTGAACTA', 'CGGTGTGCGA', 'CGCTGTGCTG', 'CGGGATGCAA', 'CACGCTACGA', 'CGCTATGCTA', 'CGGTTGGCTA', 'CGGCGTGCTA', 'CGGTATATTG', 'CGGGTTGCGA'] given_ic = motif_ic(motif) # ~ 9.05 bits motifs = spoof_motif_cftp(motif, num_motifs=1000) spoof_ics = map(motif_ic, motifs) lb, ub = mean_ci(spoof_ics) print lb, given_ic, ub assert_less_equal(lb - 1, given_ic) assert_less_equal(given_ic, ub + 1)
def spoof_motif_cftp(motif, num_motifs=10, trials=1, sigma=None, Ne_tol=10**-2, verbose=False): n = len(motif) L = len(motif[0]) copies = 10 * n if sigma is None: sigma = sigma_from_matrix(pssm_from_motif(motif, pc=1)) print "sigma:", sigma bio_ic = motif_ic(motif) matrix = sample_matrix(L, sigma) mu = approx_mu(matrix, copies=10 * n, G=5 * 10**6) print "mu:", mu def f(Ne): motifs = [ sample_motif_cftp(matrix, mu, Ne, n, verbose=verbose) for i in trange(trials) ] return mean(map(motif_ic, motifs)) - bio_ic # lb = 1 # ub = 10 # while f(ub) < 0: # ub *= 2 # print ub x0s = [2, 10] #(lb + ub)/2.0 # print "choosing starting seed for Ne" # fs = map(lambda x:abs(f(x)),x0s) # print "starting values:",x0s,fs # x0 = x0s[argmin(fs)] # print "chose:",x0 # Ne = bisect_interval_noisy_ref(f,x0,lb=1,verbose=True) Ne = log_regress_spec2(f, x0s, tol=Ne_tol) print "Ne:", Ne return [sample_motif_cftp(matrix, mu, Ne, n) for _ in trange(num_motifs)]
def spoof_uniform_motif(motif, epsilon=0.1, verbose=False): N, L = len(motif), len(motif[0]) desired_ic = motif_ic(motif) if verbose: print "starting spoof motifs uniform with:",n,L,desired_ic return uniform_motifs(N, L, desired_ic, num_motifs, epsilon, verbose=verbose)[0]
def dQ(motif): return exp(beta*motif_ic(motif) + log_M)
def dQhat(motif): return exp(beta*motif_ic(motif))
def dQ(motif): return exp(beta * motif_ic(motif) + log_M)
def dQhat(motif): return exp(beta * motif_ic(motif))