Changes

From Biolecture.org

Minsu Kim/python/Rosalind / problem8

1,729 bytes added, 21:30, 12 December 2017
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..."
<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 />
&nbsp; &nbsp; countt = 0<br />
&nbsp; &nbsp; for i in range(len(seq)-len(sample)+1):<br />
&nbsp; &nbsp; &nbsp; &nbsp; count = 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; for j in range(len(sample)):<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if seq[i+j]!=sample[j]:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; count += 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; if count &lt;= d:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; countt += 1<br />
&nbsp; &nbsp; return countt</p>

<p>f = open(&#39;rosalind_ba1i.txt&#39;, &#39;r&#39;)<br />
lines = f.readlines()<br />
f.close()</p>

<p>seq = lines[0].strip()<br />
k = int(lines[1].split()[0])<br />
d = int(lines[1].split()[1])</p>

<p>p = [&#39;A&#39;,&#39;C&#39;,&#39;G&#39;,&#39;T&#39;]<br />
ans = []<br />
m = 0</p>

<p>solution = open(&#39;solution1.txt&#39;, &#39;w&#39;)<br />
for turn in range(k**4):<br />
&nbsp; &nbsp; num = []<br />
&nbsp; &nbsp; st = &#39;&#39;<br />
&nbsp; &nbsp; left = turn<br />
&nbsp; &nbsp; for x in range(k):<br />
&nbsp; &nbsp; &nbsp; &nbsp; num.append(left%4)<br />
&nbsp; &nbsp; &nbsp; &nbsp; left = int(left / 4)<br />
&nbsp; &nbsp; for x in range(k):<br />
&nbsp; &nbsp; &nbsp; &nbsp; st += p[num[x]]<br />
&nbsp; &nbsp; temp = mmm(st)<br />
&nbsp; &nbsp; ans.append([st, temp])<br />
&nbsp; &nbsp; if temp&gt;m:<br />
&nbsp; &nbsp; &nbsp; &nbsp; m = temp<br />
for x in range(len(ans)):<br />
&nbsp; &nbsp; if ans[x][1]==m:<br />
&nbsp; &nbsp; &nbsp; &nbsp; f_ft.write(ans[x][0])<br />
&nbsp; &nbsp; &nbsp; &nbsp; f_ft.write(&quot;\n&quot;)</p>

<p>solution.close()</p>
Anonymous user

Navigation menu