Difference between revisions of "Minsu Kim/python/Rosalind / problem8"

From Biolecture.org
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...")
 
imported>Minsukim
 
Line 40: Line 40:
 
for x in range(len(ans)):<br />
 
for x in range(len(ans)):<br />
 
&nbsp; &nbsp; if ans[x][1]==m:<br />
 
&nbsp; &nbsp; if ans[x][1]==m:<br />
&nbsp; &nbsp; &nbsp; &nbsp; f_ft.write(ans[x][0])<br />
+
&nbsp; &nbsp; &nbsp; &nbsp; solution.write(ans[x][0])<br />
&nbsp; &nbsp; &nbsp; &nbsp; f_ft.write(&quot;\n&quot;)</p>
+
&nbsp; &nbsp; &nbsp; &nbsp; solution.write(&quot;\n&quot;)</p>
  
 
<p>solution.close()</p>
 
<p>solution.close()</p>

Latest revision as of 21:34, 12 December 2017

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:
        solution.write(ans[x][0])
        solution.write("\n")

solution.close()