forked from mbobesic/algorithms-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenomicRangeQuery.py
More file actions
41 lines (33 loc) · 1.04 KB
/
GenomicRangeQuery.py
File metadata and controls
41 lines (33 loc) · 1.04 KB
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
# link: https://codility.com/demo/take-sample-test/genomic_range_query
# name: Genomic Range Query
def solution(S, P, Q):
# write your code in Python 2.6
help_length = (len(S)+1)
As = [0] * help_length
Cs = [0] * help_length
Gs = [0] * help_length
Ts = [0] * help_length
matching = {'A':As, 'C':Cs, 'G':Gs, 'T': Ts}
for index in range(len(S)):
nucleotid = matching[S[index]]
nucleotid[index+1] += 1
for index in range(help_length):
As[index] += As[index-1]
Cs[index] += Cs[index-1]
Ts[index] += Ts[index-1]
Gs[index] += Gs[index-1]
solution =[]
for (x,y) in zip(P,Q):
if As[y+1] - As[x] > 0:
solution.append(1)
continue
if Cs[y+1] - Cs[x] > 0:
solution.append(2)
continue
if Gs[y+1] - Gs[x] > 0:
solution.append(3)
continue
if Ts[y+1] - Ts[x] > 0:
solution.append(4)
continue
return solution