-
Notifications
You must be signed in to change notification settings - Fork 1
/
rosalind.py
246 lines (199 loc) · 6.4 KB
/
rosalind.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import os
import solutions
import rutility
from rutility.fileops import lineoutput
from rutility.fileops import listoutput
from rutility.fileops import readfile
# The datasets for project rosalind are randomly generated.
# The data file presented is therefore only one of many possible.
def problem_dna():
''' http://rosalind.info/problems/dna/ '''
from solutions.dna import dna
f = readfile('rosalind_dna.txt')
with f:
for line in f:
listoutput(dna(line))
def problem_rna():
''' http://rosalind.info/problems/rna/ '''
from solutions.rna import rna
f = readfile('rosalind_rna.txt')
with f:
for line in f:
lineoutput(rna(line))
def problem_revc():
''' http://rosalind.info/problems/revc/ '''
from solutions.revc import revc
f = readfile('rosalind_revc.txt')
with f:
for line in f:
lineoutput(revc(line))
def problem_gc():
''' http://rosalind.info/problems/gc/ '''
from solutions.gc import gc
from rutility.parsers import fasta
f = readfile('rosalind_gc.txt')
with f:
iterfasta = fasta(f)
result = max(iterfasta, key=gc)
lineoutput(result.name)
lineoutput(gc(result))
def problem_hamm():
''' http://rosalind.info/problems/hamm/ '''
from solutions.hamm import hamm
f = readfile('rosalind_hamm.txt')
with f:
s, t = f.next(), f.next()
lineoutput(hamm(s, t))
def problem_iprb():
''' http://rosalind.info/problems/iprb/ '''
from solutions.iprb import iprb
f = readfile('rosalind_iprb.txt')
with f:
d, h, r = [int(i) for i in f.next().split()]
lineoutput(iprb(d, h, r))
def problem_prot():
''' http://rosalind.info/problems/prot/ '''
from solutions.prot import prot
f = readfile('rosalind_prot.txt')
with f:
for line in f:
lineoutput(prot(line))
def problem_subs():
''' http://rosalind.info/problems/subs/ '''
from solutions.subs import subs
f = readfile('rosalind_subs.txt')
with f:
dna, sub = f.next(), f.next()
listoutput(subs(dna, sub))
def problem_cons():
''' http://rosalind.info/problems/cons/ '''
from solutions.cons import cons
from rutility.parsers import fasta
f = readfile('rosalind_cons.txt')
with f:
iterfasta = fasta(f)
collection = [i.data for i in iterfasta]
consensus, matrix = cons(collection)
lineoutput(consensus)
listoutput(matrix[0], prefix='A: ')
listoutput(matrix[1], prefix='C: ')
listoutput(matrix[2], prefix='G: ')
listoutput(matrix[3], prefix='T: ')
def problem_perm():
''' http://rosalind.info/problems/perm/ '''
from solutions.perm import perm
f = readfile('rosalind_perm.txt')
with f:
n = int(f.next())
total, perms = perm(n)
lineoutput(total)
for p in perms:
listoutput(p)
def problem_grph():
''' http://rosalind.info/problems/grph/ '''
from solutions.grph import grph
from rutility.parsers import fasta
f = readfile('rosalind_grph.txt')
with f:
iterfasta = fasta(f)
gs = grph(iterfasta, 3)
for g in gs:
listoutput(g)
def problem_iev():
''' http://rosalind.info/problems/iev/ '''
from solutions.iev import iev
f = readfile('rosalind_iev.txt')
with f:
lineoutput(iev([int(i) for i in f.next().split()]))
def problem_fib():
''' http://rosalind.info/problems/fib/ '''
from solutions.fib import fib
f = readfile('rosalind_fib.txt')
with f:
n, k = [int(i) for i in f.next().split()]
lineoutput(fib(n, k))
def problem_lcsm():
''' http://rosalind.info/problems/lcsm/ '''
from solutions.lcsm import lcsm
from rutility.parsers import fasta
f = readfile('rosalind_lcsm.txt')
with f:
iterfasta = fasta(f)
collection = [i.data for i in iterfasta]
lineoutput(lcsm(collection))
def problem_lia():
''' http://rosalind.info/problems/lia/ '''
from solutions.lia import lia
f = readfile('rosalind_lia.txt')
with f:
k, n = [int(i) for i in f.next().split()]
lineoutput(lia(k, n))
def problem_mprt():
''' http://rosalind.info/problems/mprt/ '''
from solutions.mprt import mprt
from rutility.parsers import uniprot
f = readfile('rosalind_mprt.txt')
with f:
for line in f:
prot = uniprot(line.strip())
locations = mprt(prot.data, 'N{P}[ST]{P}')
if locations:
lineoutput(line.strip())
listoutput(locations)
def problem_fibd():
''' http://rosalind.info/problems/fibd/ '''
from solutions.fibd import fibd
f = readfile('rosalind_fibd.txt')
with f:
m, n = [int(i) for i in f.next().split()]
lineoutput(fibd(m, n))
def problem_mrna():
''' http://rosalind.info/problems/mrna/ '''
from solutions.mrna import mrna
f = readfile('rosalind_mrna.txt')
with f:
prot = f.next().strip()
lineoutput(mrna(prot) % 1000000)
def problem_orf():
''' http://rosalind.info/problems/orf/ '''
from solutions.orf import orf
from rutility.parsers import fasta
f = readfile('rosalind_orf.txt')
with f:
frames = orf(fasta(f).next().data)
for frame in frames:
lineoutput(frame)
def problem_prtm():
''' http://rosalind.info/problems/prtm/ '''
from solutions.prtm import prtm
f = readfile('rosalind_prtm.txt')
with f:
lineoutput(prtm(f.next().strip()))
def problem_revp():
''' http://rosalind.info/problems/revp/ '''
from solutions.revp import revp
from rutility.parsers import fasta
f = readfile('rosalind_revp.txt')
with f:
iterfasta = fasta(f)
for result in revp(iterfasta.next().data):
listoutput(result)
def problem_splc():
''' http://rosalind.info/problems/splc/ '''
from solutions.splc import splc
from rutility.parsers import fasta
f = readfile('rosalind_splc.txt')
with f:
iterfasta = fasta(f)
dna = iterfasta.next().data
introns = [i.data for i in list(iterfasta)]
lineoutput(splc(dna, introns))
def problem_lexf():
''' http://rosalind.info/problems/lexf/ '''
from solutions.lexf import lexf
f = readfile('rosalind_lexf.txt')
with f:
lex = f.next().strip()
perm = int(f.next())
for p in lexf(lex, perm):
lineoutput(p)