-
Notifications
You must be signed in to change notification settings - Fork 0
/
5.py
47 lines (40 loc) · 3.25 KB
/
5.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
with open('E_coli.txt', 'r') as file:
E_coli_Genome = file.read().rstrip()
def FrequencyTable(Text, k):
freqMap = {}
n = len(Text)
# print(f"n = {n}")
for i in range(n-k):
Pattern = Text[i:i+k] #← Text(i, k)
# print(f"Pattern: {Pattern}")
if Pattern not in freqMap: #freqMap[Pattern] doesn't exist
freqMap[Pattern] = 1
else:
freqMap[Pattern] = freqMap[Pattern]+1
return freqMap
def BetterFrequentWords(Text, k):
FrequentPatterns = []
freqMap = FrequencyTable(Text, k)
# max ← MaxMap(freqMap)
maxVal = max(freqMap.values())
for Pattern in freqMap:
if freqMap[Pattern] == maxVal:
FrequentPatterns.append(Pattern)
return FrequentPatterns
def FindClumps(Text, k, L, t):
Patterns = [] # an array of strings of length 0
n = len(Text)
ran = n-L
for i in range(ran):
Window = Text[i: i+L]
freqMap = FrequencyTable(Window, k)
for s in freqMap.keys():
if freqMap[s] >= t:
Patterns.append(s)
# remove duplicates from Patterns
Patterns = list(set(Patterns))
return Patterns
# print(FindClumps('CGGACTCGACAGATGTGAAGAACGACAATGTGAAGACTCGACACGACAGAGTGAAGAGAAGAGGAAACATTGTAA', 5, 50, 4))
# sample = 'AACCCTGTACGTTCGCTGACTTACGTCCGCTTTGTAGGTGATTGGTACTCCTCAGGCATCACGGCCGGTCGATGAGGTAGATCGAAGCCCATGCAGAACTGGCCATTATCGTCACCAAGTGCGTAGTGCAAGAAACACTGCCGGCCTACCAACACAAAATGTTTCTACCGGAGACCTGGTATGTGGAGGAATTCTTTTGCCAAACACCGAGCAATACCGGAAGACTGCAGTACTTTAACGTGTTTAATGAGTACGATATCCTTGCGGCAGGGACACCCTCCCCTCTAACCAAGAGCGTAGGGACCGCCTGAACTTACAATTAGTGTGCAAGCGGTCAATTGCCTTGGCCCAGCATTGTTAAAGGCTCTGACGGCAAACTCGTCACTAGGCGAAAGCTAGAGTAATTCTAGCAGGAATGATGGGAATGTGTCGCACATCTAGATCGCAGGGTACTTATGTTGGACATTATTAGGAAGTGTCAGAGCTCCTGGCTACGACCTGGCTACTGGCTACGACGGGTCTCCTGGGCAGACAAGTAGGGGACCCAATCACAAGTGTAGTGGAAAAACGTGGTCGAGGACAGTATCTATCGCCAACGAATCTCGGTCAAGTTGGGCTGCGCACATCAGCTATGTTACTATAGGCAAGGATGGTGACCGGGTTTATAGCTATTTTAAAGCAATGTAGAGCCTAACGCCTGAGCGGGCCCTGGAAAAAAGAAAACATACACTTCTCCCTAAATGGCACGTGGACGCGACAAATGACATACCTTCATATTCTTTAAGCTGAGATCTTTTTTAAGCTGATGAGTGTTGTCCGTTGAGGTGAGTACAGGCTGGGACGGGACGACGCTGGGACCAAACATTACATTGTAGTCGTTTAAGTTTTTAAGTTTAGGGAAACACGAGTGCCCGACTAAAGATCCGCATCGATGGTGCACATATTGCAACGCTCCCTTCGTGTACAATTGTACAATGGAATGGCAATGGCGCGTCCCTCGCGACGTATTGAAGGCTATACAGTCACTCCACTCCTAATCTCCACTCCTAATTTGCAGCTCTCGTAGAATCAAGTCTTCCCTTCCGTAAGCTCTCTAACCATTGAGATTCCGAAATTGAGATTCGTGCACAGGTTCGTCCGTCGATTGTACGCACGCAGGGTACGGGTACTACGGTTAACTTGCAACGCCTTCTTGAGTCTACTGTGGGTATTGACGCCGTGTAATGATTTATAGACGCTAAAGTCGCCTCTGGTCATACTAGGACGAAATATTCTAGCCGCGCACCAATAGCAGCTAAGAAACCACTTAAGCAACTTAGCGATGGGTTTCACAGCGGGTTGGCTAACGATGGCTTACAAAGAATTTTTGTTCTCTTTTGTTGACGACTTTATGGGTATGGGACTTTATGGTGATTGCTCTGACTACTGCTGACCTGACTATGGGGGCCTGATTGACCCATGCATTCCCTGTCCATCCACTCCGGTGGTGAAGGAGCGGCTACACACCTGTACAATTAATATCGAGCGATTTATTTATAGCGATTTATTATCGGCGCAGCGGTCTCCTGATGAAGACAGGGGACAGGAAGACAGGGCCCTCGAACTCGAAAGATTTTTACCAGAGTTTAGAACGCGGATAAGGGCAAGAAAGGATTGTAATGTCCATTTGTCCTCTCCGTAATCGCCCCAACCGCGAATGACGGGAGCCAACGGAACGGGAGCCACACACCACAAAACGTCATTCTCCCCACTATGTAATACGTTAGCACCCCCCCTATTGCATGTCTCCTAAAGGTGTAACCAAGAGGACTGCTTTTGACTGCTTTTGACTGCTTTTGACTGCTTTTAGACTGCTTTTAGTTAACGGGAGTTAACGGGAGTTAACGGGAGTTAACGGGATGTCGCTGTCGCAGTGTGTCGCAGTGGTGAGTTAACGGG'
# print(FindClumps(sample, 10, 25, 4))
print(FindClumps(E_coli_Genome, 9, 500, 3))