-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenomicRangeQuery.py
32 lines (30 loc) · 958 Bytes
/
GenomicRangeQuery.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
def solution(S, P, Q):
A_prefix = prefixSum(S, 'A')
C_prefix = prefixSum(S, 'C')
G_prefix = prefixSum(S, 'G')
min_impact_factor = []
for i in range(len(P)):
inner_sum_A =A_prefix[Q[i]+1] - A_prefix[P[i]]
if inner_sum_A != 0:
min_impact_factor.append(1)
continue
inner_sum_C = C_prefix[Q[i]+1] - C_prefix[P[i]]
if inner_sum_C != 0:
min_impact_factor.append(2)
continue
inner_sum_G = G_prefix[Q[i]+1] - G_prefix[P[i]]
if inner_sum_G != 0:
min_impact_factor.append(3)
continue
else:
min_impact_factor.append(4)
return min_impact_factor
def prefixSum(S, char):
prefix_sum = [0]
current_sum = 0
for character in S:
if character == char:
current_sum += 1
prefix_sum.append(current_sum)
return prefix_sum
print(solution('CAGCCTA', [2, 5, 0], [4, 5, 6]))