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

From Biolecture.org
imported>Minsukim
(Created page with "<p><img alt="" src="/ckfinder/userfiles/images/bandicam%202017-12-12%2021-33-53-945.jpg" style="height:252px; width:639px" /></p> <p>f = open('rosalind_ba1m.txt','r&...")
 
imported>Minsukim
 
Line 1: Line 1:
 
<p><img alt="" src="/ckfinder/userfiles/images/bandicam%202017-12-12%2021-33-53-945.jpg" style="height:252px; width:639px" /></p>
 
<p><img alt="" src="/ckfinder/userfiles/images/bandicam%202017-12-12%2021-33-53-945.jpg" style="height:252px; width:639px" /></p>
  
<p>f = open(&#39;rosalind_ba1m.txt&#39;,&#39;r&#39;)<br />
+
<p>f = open(&#39;rosalind_ba1l.txt&#39;,&#39;r&#39;)<br />
ind = int(f.readline())<br />
+
seq = f.readline().strip()<br />
k = int(f.readline())<br />
 
 
f.close</p>
 
f.close</p>
  
<p>a = []<br />
+
<p>a = 0<br />
for i in range(0,k):<br />
+
for i in range(0, len(seq)):<br />
&nbsp; &nbsp; d = 4**(k-i-1)<br />
+
&nbsp; &nbsp; if seq[i] == &#39;A&#39;:<br />
&nbsp; &nbsp; count = 0<br />
+
&nbsp; &nbsp; &nbsp; &nbsp; d = 0<br />
&nbsp; &nbsp; if d &gt; ind:<br />
+
&nbsp; &nbsp; if seq[i] == &#39;C&#39;:<br />
&nbsp; &nbsp; &nbsp; &nbsp; a.append(&#39;A&#39;)<br />
+
&nbsp; &nbsp; &nbsp; &nbsp; d = 1<br />
&nbsp; &nbsp; else:<br />
+
&nbsp; &nbsp; if seq[i] == &#39;G&#39;:<br />
&nbsp; &nbsp; &nbsp; &nbsp; while(d&lt;=ind):<br />
+
&nbsp; &nbsp; &nbsp; &nbsp; d = 2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ind -= d<br />
+
&nbsp; &nbsp; if seq[i] == &#39;T&#39;:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; count += 1<br />
+
&nbsp; &nbsp; &nbsp; &nbsp; d = 3<br />
&nbsp; &nbsp; &nbsp; &nbsp; if count==1:<br />
+
&nbsp; &nbsp; d = d*(4**(len(seq)-i-1))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.append(&#39;C&#39;)<br />
+
&nbsp; &nbsp; a += d<br />
&nbsp; &nbsp; &nbsp; &nbsp; if count==2:<br />
+
print(a)</p>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.append(&#39;G&#39;)<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; if count==3:<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.append(&#39;T&#39;)<br />
 
print(&quot;&quot;.join(a))</p>
 

Latest revision as of 21:46, 12 December 2017

f = open('rosalind_ba1l.txt','r')
seq = f.readline().strip()
f.close

a = 0
for i in range(0, len(seq)):
    if seq[i] == 'A':
        d = 0
    if seq[i] == 'C':
        d = 1
    if seq[i] == 'G':
        d = 2
    if seq[i] == 'T':
        d = 3
    d = d*(4**(len(seq)-i-1))
    a += d
print(a)