Open main menu

Biolecture.org β

Minsu Kim/python/Rosalind / problem8

Revision as of 21:30, 12 December 2017 by imported>Minsukim (Created page with "<p><img alt="" src="/ckfinder/userfiles/images/bandicam%202017-12-12%2021-27-05-884.jpg" style="height:339px; width:1000px" /></p> <p>def mmm(sample):<br />     countt...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

def mmm(sample):
    countt = 0
    for i in range(len(seq)-len(sample)+1):
        count = 0
        for j in range(len(sample)):
            if seq[i+j]!=sample[j]:
                count += 1
        if count <= d:
            countt += 1
    return countt

f = open('rosalind_ba1i.txt', 'r')
lines = f.readlines()
f.close()

seq = lines[0].strip()
k = int(lines[1].split()[0])
d = int(lines[1].split()[1])

p = ['A','C','G','T']
ans = []
m = 0

solution = open('solution1.txt', 'w')
for turn in range(k**4):
    num = []
    st = ''
    left = turn
    for x in range(k):
        num.append(left%4)
        left = int(left / 4)
    for x in range(k):
        st += p[num[x]]
    temp = mmm(st)
    ans.append([st, temp])
    if temp>m:
        m = temp
for x in range(len(ans)):
    if ans[x][1]==m:
        f_ft.write(ans[x][0])
        f_ft.write("\n")

solution.close()