def main1():
    input_dna = '''ttACCTtaac
gATGTctgtc
ccgGCGTtag
cactaACGAg
cgtcagAGGT'''
    dna = [Seq(line.strip(), IUPAC.unambiguous_dna) for line in input_dna.upper().split('\n')]
    input_motifs = '''ttac
gtct
ggcg
taac
gtca'''
    motifs = [Seq(line.strip(), IUPAC.unambiguous_dna) for line in input_motifs.upper().split('\n')]
    print_motifs(motifs)

    profile = make_profile(motifs, 4)
    print
    print profile

    print
    new_motifs = []
    for seq in dna:
        new_motifs.append(profile_most_prob(profile, seq, 4))
    print_motifs(new_motifs)

    profile = make_profile(new_motifs, 4)
    print
    print profile

    print
    new_motifs = []
    for seq in dna:
        new_motifs.append(profile_most_prob(profile, seq, 4))
    print_motifs(new_motifs)
def randomized_motif_search(dna, k, t):
    best_motifs = []
    for seq in dna:
        pos = random.randrange(len(seq) - k + 1)
        best_motifs.append(seq[pos:pos + k])

    while True:
        profile = make_profile(best_motifs, k)
        motifs = [profile_most_prob(profile, seq, k) for seq in dna]
        if score_motifs(motifs) < score_motifs(best_motifs):
            best_motifs = motifs
        else:
            return best_motifs
    def run():
        best_motifs = []
        for seq in dna:
            pos = random.randrange(len(seq) - k + 1)
            best_motifs.append(seq[pos:pos + k])
        best_score = score_motifs(best_motifs)
        motifs = best_motifs[:]
        for _ in range(N):
            i = random.randrange(t)
            profile = make_profile(motifs[:i] + motifs[i + 1:], k)
            motifs[i] = profile_rand_kmer(profile, dna[i], k)
            score = score_motifs(motifs)
            if score < best_score:
                best_motifs, best_score = motifs[:], score

        print_motifs(best_motifs)
        return best_score, best_motifs