Ejemplo n.º 1
0
def wrapperRMS(dna, k, t, iter):
    motifs = randomizedMotifSearch(dna, k, t)
    for i in range(iter - 1):
        newMotifs = randomizedMotifSearch(dna, k, t)
        if score(newMotifs) < score(motifs):
            motifs = newMotifs
    return motifs
Ejemplo n.º 2
0
def wrapperGS(dna, k, t, n, iter):
    motifs = gibbsSampler(dna, k, t, n)
    for i in range(iter - 1):
        newMotifs = gibbsSampler(dna, k, t, n)
        if score(newMotifs) < score(motifs):
            motifs = newMotifs
    return motifs
Ejemplo n.º 3
0
def randomizedMotifSearch(dna, k, t):
    bestMotifs = randomMotifs(dna, k, t)
    while True:
        profile = profileMotifs(bestMotifs)
        newMotifs = motifs(profile, dna)
        if score(newMotifs) < score(bestMotifs):
            bestMotifs = newMotifs
        else:
            return bestMotifs
Ejemplo n.º 4
0
def greedyMotifSearch(dna, k, t):
    #computes a collection of strings as best motifs.
    bestMotifs = [row[:k] for row in dna[:t]]

    for i in range(len(dna[0]) - k + 1):

        motif1 = dna[0][i:i + k]
        candidateMotifs = [motif1]
        for j in range(1, t):
            profile = profileMotifs(candidateMotifs)
            motif_i = profileMostProbableKmer(dna[j], k, profile)
            candidateMotifs.append(motif_i)
        if (score(candidateMotifs) < score(bestMotifs)):
            bestMotifs = candidateMotifs
    return bestMotifs
Ejemplo n.º 5
0
def gibbsSampler(dna, k, t, n):
    # applys Gibss sampling
    bestMotifs = randomMotifs(dna, k, t)

    for i in range(n):
        index = randint(0, len(dna) - 1)
        newMotifs = bestMotifs
        newMotifs.pop(index)
        profile = profileMotifs(newMotifs)
        probDistr = probDistribution(dna[index], profile, k)
        indexBiased = randomWithBias(probDistr)
        newMotifs.insert(index, dna[index][indexBiased:indexBiased + k])
        if score(newMotifs) < score(bestMotifs):
            bestMotifs = newMotifs
    return bestMotifs
Ejemplo n.º 6
0
def randomizedMotifSearch(dna, k, t):
    bestMotifs = randomMotifs(dna, k, t)
    while True:
        profile = profileMotifs(bestMotifs)
        newMotifs = motifs(profile, dna)
        if score(newMotifs) < score(bestMotifs):
            bestMotifs = newMotifs
        else:
            return bestMotifs


def wrapperRMS(dna, k, t, iter):
    motifs = randomizedMotifSearch(dna, k, t)
    for i in range(iter - 1):
        newMotifs = randomizedMotifSearch(dna, k, t)
        if score(newMotifs) < score(motifs):
            motifs = newMotifs
    return motifs


if __name__ == "__main__":
    file = open("data/subtle_motif_dataset.txt", 'r')
    dna = [line.rstrip('\n') for line in file]

    result_motifs = wrapperRMS(dna, 15, 10, 1000)
    score_motifs = score(result_motifs)
    consensusMotifs = consensus(result_motifs)
    verticalPrint(result_motifs)
    print(score_motifs)
    print(consensusMotifs)