def randomized_motif_search(dnas, k, t):
    rand_ints = [random.randint(0,len(dnas[0])-k) for a in range(t)]
    motifs = [dnas[i][r:r+k] for i, r in enumerate(rand_ints)]

    best_score = [score(motifs), motifs]
    while True:
        profile = profile_with_pseudocounts(motifs)
        motifs = motifs_from_profile(profile, dnas, k)
        current_score = score(motifs)
        if current_score < best_score[0]:
            best_score = [current_score, motifs]
        else:
            return best_score
def randomized_motif_search(dnas, k, t, N):
    rand_ints = [random.randint(0,len(dnas[0])-k) for a in range(t)]
    motifs = [dnas[i][r:r+k] for i, r in enumerate(rand_ints)]

    best_score = [score(motifs), motifs]
    for j in range(N):
        i = random.randint(0, t-1)
        profile = profile_with_pseudocounts(motifs[:i-1] + motifs[i:])
        motifs[i] = profile_most_probable_kmer_swap(dnas[i], k, profile)
        current_score = score(motifs)
        if current_score < best_score[0]:
            best_score = [current_score, motifs]
    return best_score
Beispiel #3
0
def randomized_motif_search(dnas, k, t, N):
    rand_ints = [random.randint(0, len(dnas[0]) - k) for a in range(t)]
    motifs = [dnas[i][r:r + k] for i, r in enumerate(rand_ints)]

    best_score = [score(motifs), motifs]
    for j in range(N):
        i = random.randint(0, t - 1)
        profile = profile_with_pseudocounts(motifs[:i - 1] + motifs[i:])
        motifs[i] = profile_most_probable_kmer_swap(dnas[i], k, profile)
        current_score = score(motifs)
        if current_score < best_score[0]:
            best_score = [current_score, motifs]
    return best_score