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 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 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 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