Open main menu

Biolecture.org β

Minsu Kim/python/Rosalind / problem12

 

import itertools

f = open('rosalind_ba1n.txt', 'r')
lines = f.readlines()
seq = lines[0].strip()
d = int(lines[1])
f.close

solution = open('solution3.txt', 'w')
for i in itertools.product("ACGT", repeat=len(seq)):
    p = ''.join(i)
    count = 0
    for k in range(len(p)):
        if seq[k] != p[k]:
            count += 1
        if count > d:
            break
    if count <= d:
        solution.write(p + '\n')

solution.close()