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
Esempio n. 2
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
def greedy_motif_search_pseudocounts(dnas, k, t):
    best_score = t*k

    for i in range(len(dnas[0]) - k + 1):
        motifs = [dnas[0][i:i + k]]

        for j in range(1, t):
            current_profile = profile_with_pseudocounts(motifs)
            motifs.append(profile_most_probable_kmer_swap(dnas[j], k, current_profile))

        current_score = score(motifs)
        if current_score < best_score:
            best_score = current_score
            best_motifs = motifs

    return best_motifs
def motifs_from_profile(profile, dna, k):
    return [profile_most_probable_kmer_swap(seq, k, profile) for seq in dna]
Esempio n. 5
0
def motifs_from_profile(profile, dna, k):
    return [profile_most_probable_kmer_swap(seq, k, profile) for seq in dna]