-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNaiveExactPatternMatching.py
More file actions
36 lines (30 loc) · 1.02 KB
/
NaiveExactPatternMatching.py
File metadata and controls
36 lines (30 loc) · 1.02 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
def NaiveExactPatternMatching(Pattern, Genome):
positions = []
k = len(Pattern)
for index in range(len(Genome) - k + 1):
currentKmer = Genome[index:index + k]
kmer_match = True
for i in range(len(currentKmer)):
if currentKmer[i] != Pattern[i]:
kmer_match = False
break
if kmer_match:
positions.append(index)
return positions
def NaiveExactPatternMatchingWithCounts(Pattern, Genome):
positions = []
num_alignments = 0
num_character_comparisons = 0
k = len(Pattern)
for index in range(len(Genome) - k + 1):
currentKmer = Genome[index:index + k]
kmer_match = True
num_alignments += 1
for i in range(len(currentKmer)):
num_character_comparisons += 1
if currentKmer[i] != Pattern[i]:
kmer_match = False
break
if kmer_match:
positions.append(index)
return positions, num_alignments, num_character_comparisons