Finish Week 2 Tasks
This commit is contained in:
16
Code/ApproximatePatternCount.py
Normal file
16
Code/ApproximatePatternCount.py
Normal file
@@ -0,0 +1,16 @@
|
||||
def ApproximatePatternCount(Pattern, Text, d):
|
||||
count = 0
|
||||
for i in range(len(Text)-len(Pattern)+1):
|
||||
if Text[i:i+len(Pattern)] == Pattern:
|
||||
count += 1
|
||||
elif HammingDistance(Text[i:i+len(Pattern)], Pattern) <= d:
|
||||
count += 1
|
||||
return count
|
||||
|
||||
|
||||
def HammingDistance(p, q):
|
||||
count = 0
|
||||
for i in range(0, len(p)):
|
||||
if p[i] != q[i]:
|
||||
count += 1
|
||||
return count
|
||||
16
Code/ApproximatePatternMatching.py
Normal file
16
Code/ApproximatePatternMatching.py
Normal file
@@ -0,0 +1,16 @@
|
||||
def ApproximatePatternMatching(Text, Pattern, d):
|
||||
positions = []
|
||||
for i in range(len(Text)-len(Pattern)+1):
|
||||
if Text[i:i+len(Pattern)] == Pattern:
|
||||
positions.append(i)
|
||||
elif HammingDistance(Text[i:i+len(Pattern)], Pattern) <= d:
|
||||
positions.append(i)
|
||||
return positions
|
||||
|
||||
|
||||
def HammingDistance(p, q):
|
||||
count = 0
|
||||
for i in range(0, len(p)):
|
||||
if p[i] != q[i]:
|
||||
count += 1
|
||||
return count
|
||||
20
Code/FasterSymbolArray.py
Normal file
20
Code/FasterSymbolArray.py
Normal file
@@ -0,0 +1,20 @@
|
||||
def FasterSymbolArray(Genome, symbol):
|
||||
array = {}
|
||||
n = len(Genome)
|
||||
ExtendedGenome = Genome + Genome[0:n//2]
|
||||
array[0] = PatternCount(symbol, Genome[0:n//2])
|
||||
for i in range(1, n):
|
||||
array[i] = array[i-1]
|
||||
if ExtendedGenome[i-1] == symbol:
|
||||
array[i] = array[i]-1
|
||||
if ExtendedGenome[i+(n//2)-1] == symbol:
|
||||
array[i] = array[i]+1
|
||||
return array
|
||||
|
||||
|
||||
def PatternCount(Text, Pattern):
|
||||
count = 0
|
||||
for i in range(len(Text)-len(Pattern)+1):
|
||||
if Text[i:i+len(Pattern)] == Pattern:
|
||||
count = count+1
|
||||
return count
|
||||
6
Code/HammingDistance.py
Normal file
6
Code/HammingDistance.py
Normal file
@@ -0,0 +1,6 @@
|
||||
def HammingDistance(p, q):
|
||||
count = 0
|
||||
for i in range(0, len(p)):
|
||||
if p[i] != q[i]:
|
||||
count += 1
|
||||
return count
|
||||
21
Code/MinimumSkew.py
Normal file
21
Code/MinimumSkew.py
Normal file
@@ -0,0 +1,21 @@
|
||||
def MinimumSkew(Genome):
|
||||
positions = []
|
||||
skew = SkewArray(Genome)
|
||||
minimum = min(skew)
|
||||
for i in range(0, len(Genome)):
|
||||
if skew[i] == minimum:
|
||||
positions.append(i)
|
||||
return positions
|
||||
|
||||
|
||||
def SkewArray(Genome):
|
||||
Skew = []
|
||||
Skew.append(0)
|
||||
for i in range(0, len(Genome)):
|
||||
if Genome[i] == "G":
|
||||
Skew.append(Skew[i] + 1)
|
||||
elif Genome[i] == "C":
|
||||
Skew.append(Skew[i] - 1)
|
||||
else:
|
||||
Skew.append(Skew[i])
|
||||
return Skew
|
||||
11
Code/SkewArray.py
Normal file
11
Code/SkewArray.py
Normal file
@@ -0,0 +1,11 @@
|
||||
def SkewArray(Genome):
|
||||
Skew = []
|
||||
Skew.append(0)
|
||||
for i in range(0, len(Genome)):
|
||||
if Genome[i] == "G":
|
||||
Skew.append(Skew[i] + 1)
|
||||
elif Genome[i] == "C":
|
||||
Skew.append(Skew[i] - 1)
|
||||
else:
|
||||
Skew.append(Skew[i])
|
||||
return Skew
|
||||
15
Code/SymbolArray.py
Normal file
15
Code/SymbolArray.py
Normal file
@@ -0,0 +1,15 @@
|
||||
def SymbolArray(Genome, symbol):
|
||||
array = {}
|
||||
n = len(Genome)
|
||||
ExtendedGenome = Genome + Genome[0:n//2]
|
||||
for i in range(n):
|
||||
array[i] = PatternCount(ExtendedGenome[i:i+(n//2)], symbol)
|
||||
return array
|
||||
|
||||
|
||||
def PatternCount(Text, Pattern):
|
||||
count = 0
|
||||
for i in range(len(Text)-len(Pattern)+1):
|
||||
if Text[i:i+len(Pattern)] == Pattern:
|
||||
count = count+1
|
||||
return count
|
||||
Reference in New Issue
Block a user