-
Notifications
You must be signed in to change notification settings - Fork 1
/
naive_algo.py
52 lines (45 loc) · 1.29 KB
/
naive_algo.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
# Exact Matching Naive Algorithm
def naive(p, t):
occurrences = []
for i in range(len(t) - len(p) + 1):
match = True
for j in range(len(p)):
if t[i+j] != p[j]:
match = False
break
if match:
occurrences.append(i)
return occurrences
# Also Counting Matching Complement Pairs (only once if complement is same)
def naive_with_rc(p, t):
occurrences = []
r = reverseComplement(p)
for i in range(len(t) - len(p) + 1):
match = True
for j in range(len(p)):
if t[i+j] != p[j]:
match = False
break
if r != p:
for k in range(len(r)):
if t[i+k] != r[k]:
match = False
break
if match:
occurrences.append(i)
return occurrences
# Allowing Upto 2 mistmatches per occurance
def naive_2mm(p, t):
occurrences = []
for i in range(len(t) - len(p) + 1):
match = True
unmatch = 0
for j in rangei(len(p)):
if t[i+j] != p[j]:
unmatch += 1
if unmatch > 2:
match = False
break
if match:
occurrences.append(i)
return occurrences