示例#1
0
def spoof_motif_cftp_occ(motif, num_motifs=10, trials=1, sigma=None,Ne_tol=10**-2,verbose=False):
    """spoof motifs based on occupancy rather than motif IC"""
    N = len(motif)
    L = len(motif[0])
    copies = 10*N
    pssm = pssm_from_motif(motif,pc=1)
    if sigma is None: sigma = sigma_from_matrix(pssm)
    print "sigma:", sigma
    matrix = sample_matrix(L, sigma)
    bio_matrix = matrix_from_motif(motif)
    mu = approx_mu(matrix, copies=copies, G=5*10**6)
    mean_bio_occ = mean(occupancies(motif))
    print "mu:", mu
    def f(Ne):
        motifs = [sample_motif_cftp(matrix, mu, Ne, N, verbose=verbose)
                  for i in trange(trials)]
        
        return mean(map(lambda m:mean(occupancies(m)), motifs)) - mean_bio_occ
    # 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)]
示例#2
0
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)]
示例#3
0
def spoof_motif_cftp_occ(motif,
                         num_motifs=10,
                         trials=1,
                         sigma=None,
                         Ne_tol=10**-2,
                         verbose=False):
    """spoof motifs based on occupancy rather than motif IC"""
    N = len(motif)
    L = len(motif[0])
    copies = 10 * N
    pssm = pssm_from_motif(motif, pc=1)
    if sigma is None: sigma = sigma_from_matrix(pssm)
    print "sigma:", sigma
    matrix = sample_matrix(L, sigma)
    bio_matrix = matrix_from_motif(motif)
    mu = approx_mu(matrix, copies=copies, G=5 * 10**6)
    mean_bio_occ = mean(occupancies(motif))
    print "mu:", mu

    def f(Ne):
        motifs = [
            sample_motif_cftp(matrix, mu, Ne, N, verbose=verbose)
            for i in trange(trials)
        ]

        return mean(map(lambda m: mean(occupancies(m)), motifs)) - mean_bio_occ

    # 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)]
示例#4
0
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)]