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

From Biolecture.org
imported>Minsukim
imported>Minsukim
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
<h4>I solve the problem relative the bioinformatics in web site : rosalind</h4>
+
<h4>I solve the problem related&nbsp;to the bioinformatics in web site : rosalind</h4>
  
 
<h1>Problem</h1>
 
<h1>Problem</h1>
Line 11: Line 11:
 
<p><a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind / problem1">[1]</a>&nbsp; &nbsp;<a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind / problem2">[2]</a>&nbsp; &nbsp;<a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind / problem3">[3]</a>&nbsp; &nbsp;<a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind /problem4">[4]</a> &nbsp; <a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind /problem5">[5]</a> &nbsp; <a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind /problem6">[6]</a></p>
 
<p><a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind / problem1">[1]</a>&nbsp; &nbsp;<a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind / problem2">[2]</a>&nbsp; &nbsp;<a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind / problem3">[3]</a>&nbsp; &nbsp;<a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind /problem4">[4]</a> &nbsp; <a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind /problem5">[5]</a> &nbsp; <a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind /problem6">[6]</a></p>
  
<h2>function</h2>
+
<p><a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind / problem7">[7]</a> &nbsp; <a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind / problem8">[8]</a> &nbsp; <a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind / problem9">[9]</a> &nbsp; <a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind / problem10">[10]</a> &nbsp; <a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind / problem11">[11]</a> &nbsp; <a href="http://biolecture.org/index.php?title=Minsu_Kim/python/Rosalind / problem12">[12]</a></p>
 
 
<p>def patterncount(text, pattern):<br />
 
&nbsp; &nbsp; count=0<br />
 
&nbsp; &nbsp; for i in range(0,len(text)):<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; if(text[i:len(pattern)+i]==pattern):<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; count += 1<br />
 
&nbsp; &nbsp; return count</p>
 
 
 
<p>def complementing(sequence):<br />
 
&nbsp; &nbsp; sequence = sequence[::-1]<br />
 
&nbsp; &nbsp; text = list(sequence)<br />
 
&nbsp; &nbsp; for i in range(0,len(text)):<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; if text[i] == &#39;A&#39;:<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text[i] = &#39;T&#39;<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; elif text[i] == &#39;G&#39;:<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text[i] = &#39;C&#39;<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; elif text[i] == &#39;C&#39;:<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text[i] = &#39;G&#39;<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; elif text[i] == &#39;T&#39;:<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text[i] = &#39;A&#39;<br />
 
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br />
 
&nbsp; &nbsp; s = &#39;&#39;.join(text)<br />
 
&nbsp; &nbsp; print(s)<br />
 
&nbsp; &nbsp; return 0</p>
 
 
 
<h1>rosalind transcript basic</h1>
 
 
 
<p>f = open(&#39;rosalind_rna.txt&#39;)<br />
 
a = f.readline()<br />
 
f.close</p>
 
 
 
<p>text = list(a)</p>
 
 
 
<p>for i in range(0,len(text)):<br />
 
&nbsp; &nbsp; if text[i] == &#39;T&#39;:<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; text[i] = &#39;U&#39;<br />
 
a = &#39;&#39;.join(text)</p>
 
 
 
<p>print(a)</p>
 
 
 
<p>f = open(&#39;rosalind_revc2.txt&#39;,&#39;r&#39;)<br />
 
b = f.readline()<br />
 
f.close</p>
 
 
 
<p>b = b[::-1]<br />
 
text = list(b)</p>
 
 
 
<p>for i in range(0,len(text)):<br />
 
&nbsp; &nbsp; if text[i] == &#39;A&#39;:<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; text[i] = &#39;T&#39;<br />
 
&nbsp; &nbsp; elif text[i] == &#39;G&#39;:<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; text[i] = &#39;C&#39;<br />
 
&nbsp; &nbsp; elif text[i] == &#39;C&#39;:<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; text[i] = &#39;G&#39;<br />
 
&nbsp; &nbsp; elif text[i] == &#39;T&#39;:<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; text[i] = &#39;A&#39;<br />
 
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br />
 
b = &#39;&#39;.join(text)</p>
 
 
 
<p>print(b)</p>
 
  
 
<h2>Computing CG Content</h2>
 
<h2>Computing CG Content</h2>
  
<p>f_fa = open(&#39;rosalind_gc.txt&#39;,&#39;r&#39;)<br />
+
<p>f&nbsp;= open(&#39;rosalind_gc.txt&#39;,&#39;r&#39;)<br />
 
seq_list = dict()<br />
 
seq_list = dict()<br />
 
for line in f_fa:<br />
 
for line in f_fa:<br />
Line 83: Line 23:
 
&nbsp; &nbsp; else:<br />
 
&nbsp; &nbsp; else:<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; seq_list[name]= line.strip()<br />
 
&nbsp; &nbsp; &nbsp; &nbsp; seq_list[name]= line.strip()<br />
f_fa.close()</p>
+
f.close()</p>
  
 
<p>seq_CG = dict()<br />
 
<p>seq_CG = dict()<br />

Latest revision as of 13:33, 13 December 2017

I solve the problem related to the bioinformatics in web site : rosalind

Problem

basic problem

[1]   [2]   [3]

related with bioinformatics

[1]   [2]   [3]   [4]   [5]   [6]

[7]   [8]   [9]   [10]   [11]   [12]

Computing CG Content

f = open('rosalind_gc.txt','r')
seq_list = dict()
for line in f_fa:
    if line.startswith('>'):
        name = line.strip('>').strip()
        seq_list[name] = ''
    else:
        seq_list[name]= line.strip()
f.close()

seq_CG = dict()
for k in seq_list:
    count = 0
    s = seq_list[k]
    s = list(s)
    for i in range(0,len(s)):
        if s[i] == 'C' or s[i] == 'G':
            count = count + 1
    p = count / len(s)
    seq_CG[k] = p

inverse = [(value, key) for key, value in seq_CG.items()]
max(inverse)

import matplotlib.pyplot as plt

seq_list = []
f_fa = open('Ecoli_genome.fasta', 'r')
for line in f_fa:
    if not line.startswith('>'):
        seq_list.append(line.strip())
tmp_seq = ''.join(seq_list)

count_G = 0
count_C = 0
count_list = []
for tmp_n in tmp_seq:
    if tmp_n == 'G':
        count_G += 1
    if tmp_n == 'C':
        count_C += 1
    count_list.append(count_G-count_C)

pos_list = range(0,len(tmp_seq))

fig = plt.figure(figsize = (10,6))
ax1 = fig.add_subplot(1,1,1)
ax1.plot(pos_list, count_list, 'b-')
ax1.grid()
plt.show()
f_fa.close()

 

Dynamic Program

def maxvalue(a,b,c):
    a=a+5
    b=b-6
    c=c-6
    return max(a,b,c)
def maxvalue2(a,b,c):
    a=a-2
    b=b-6
    c=c-6
    return max(a,b,c)

def compare(a,b):
    import numpy as np
    scoring = np.zeros([len(a)+1,len(b)+1])
    for i in range(0,len(a)+1):
        scoring[i,0]=-6*i
    for j in range(0,len(b)+1):
        scoring[0,j]=-6*j

    for row in range(1,len(a)+1):
        for column in range(1,len(b)+1):
            if b[column-1]==a[row-1]:
                scoring[row,column] = maxvalue(scoring[row-1,column-1],scoring[row-1,column],scoring[row,column-1])
            if b[column-1]!=a[row-1]:
                scoring[row,column] = maxvalue2(scoring[row-1,column-1],scoring[row-1,column],scoring[row,column-1])
    print(scoring)

    list=[]
    for row in range(1,len(a)+1):
        for column in range(1,len(b)+1):
            new=scoring[row,column]
            list.append(new)
    mxv=max(list)
    print(mxv)