def greedyMotifSearch(dna, k, t):
    best_motifs = []
    for string in dna:
        best_motifs.append(string[0:k])

    for i in range(len(dna[0]) - k + 1):
        motifs = [dna[0][i:i + k]]
        for j in range(1, t):
            profile_matrix = formProfile(motifs)
            motifs.append(detectMostProbableKMer(dna[j], k, profile_matrix))
        if score(motifs) < score(best_motifs):
            best_motifs = motifs
    return best_motifs
Example #2
0
def gibbsSampler(dna, k, t, N):
    motifs = []
    n = len(dna[0])
    for i in xrange(t):
        index = random.randint(0, n - k)
        motifs.append(dna[i][index:index + k])
    best_motifs = motifs
    for j in xrange(N):
        r = random.randint(0, t - 1)
        profile_matrix = formProfileGibbs(motifs, r)
        motif = detectMostProbableKMer(dna[r], k, profile_matrix)
        motifs = [motif if index == r else m for index, m
                  in enumerate(motifs)]
        if score(motifs) < score(best_motifs):
            best_motifs = motifs
    return best_motifs
def selectMotifs(profile_matrix, dna, k):
    motifs = []
    for string in dna:
        motifs.append(detectMostProbableKMer(string, k, profile_matrix))
    return motifs