-
Notifications
You must be signed in to change notification settings - Fork 3
/
BA1E.py
72 lines (63 loc) · 9.67 KB
/
BA1E.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def patternToNumber(pattern):
if len(pattern) == 0:
return 0
return 4 * patternToNumber(pattern[0:-1]) + symbolToNumber(pattern[-1:])
def symbolToNumber(symbol):
if symbol == "A":
return 0
if symbol == "C":
return 1
if symbol == "G":
return 2
if symbol == "T":
return 3
def numberToPattern(x, k):
if k == 1:
return numberToSymbol(x)
return numberToPattern(x // 4, k-1) + numberToSymbol(x % 4)
def numberToSymbol(x):
if x == 0:
return "A"
if x == 1:
return "C"
if x == 2:
return "G"
if x == 3:
return "T"
def computingFrequencies(text, k):
a = [0] * 4**k
for i in range(len(text)-k+1):
pattern = text[i:i+k]
j = patternToNumber(pattern)
a[j] = a[j] + 1
return a
def betterClumpFinding(genome, k, t, l):
frequentPatterns = []
clump = [0] * 4**k
text = genome[0:L]
a = computingFrequencies(text, k)
for i in range(0, 4**k):
if a[i] >= t:
clump[i] = 1
for i in range(1, len(genome)-l):
firstPattern = genome[i-1:i-1+k]
x = patternToNumber(firstPattern)
a[x] = a[x] - 1
lastPattern = genome[i+L-k:i+L]
x = patternToNumber(lastPattern)
a[x] = a[x] + 1
if a[x] >= t:
clump[x] = 1
for i in range(len(clump)):
if clump[i] == 1:
frequentPatterns.append(numberToPattern(i,k))
return frequentPatterns
g = "GAGCCAGAGCTGTTCTGATCATTTCACCACTGTTCGTTTTTAAATGCACAAGAATGGAAAGTTCCTCAACTCCTCAGACCTCGCAACCACTAATCCCGTGTGCCCGACTAGGTACTGCATTATGAGCGATGGGCAGAGACATGACTTGATGGTACAACCATATTCACCATGGTCAGTAGACAAGTGAGAAACTTAGTTACAGCCGTCATCGCGCTACCTTGTCGGACTGGCTTACTGGGGGTCCATCGACACTCCTACGAGCCCAAGCTATAGTAGTCGGCCCGGCCAATTGATTCAGCCGCTTGAGAGTGGAGGTCTGGCTGCCCCTGCGAGAGGCTTGCACATCGGATAGCGCCATCCCACCGGTTAGATCGGACGAACAAAGAGAGGAGCGCCCGCTTGTCCTTTTGATAGGAGGAACCCGATTACTACTACGTAACATATATTGTGACCAGCCCTCCGTGAACCAGCGTCTGGTCATGTGATCTTAAGGTATACTAGTACAAGATGTCCCGTTTGAGTCGTCCCCAACGACCTCGCTTGAGGGCTCTCCAGGGATTGCATCAGACCCAACAGAGGAGGTACGCCCGACAATGAGGAGTCAAGGTGCGGTGCTTGCGAACTAGAGGCCTTGGTCGCACCTCATACAATTTACGGCCCCGCTCCTTGGCAATCCTACATAGGAGCCAGCGGATATCCAATACAAAGCTAAGGAACAATACTATGGACCATCCTTGATAGTGTACTCTAATTATTCTTAGTTAGAAATAATGTTGCGCTGCTTAGGAGCGGCCTGGTTGAGTGAGGCCAGTTCTTCGCGGTAGAACACGCATTGAATTGAGTGAGGGTCAGGGATAGTTCGGCTTTGATGCGTAAGTAGTGAGTGAGGCTGAGTGAGGGCTTGACCGTGTGGATGAGTGAGGAGGTTGAGTGAGGTGAGTGAGTGAGGGAGGATAGACAAGATCTTACGGATGAGTGAGGGGATAAGTGAGTGAGGGAGGTGAGTGAGGCCGAAACGGGGTTTACTGAGTGAGGGATGAGTGAGGAGAGTAAGAAGTGAGTGAGGATGAGTGAGGTGAGTGAGGAGTGAGGAGGAGGGGTGAGTGAGGGAGGCGTCTCAATGAAGGTCCTGAGTGAGTGAGGATAGTTGATGAGTGAGGGTTTTGCGACCCTGATATGAGTGAGGCTTCTGGAGTGTCCTCCCTTCGACGACCATATGTAGAACACACCGCGAACAGAGTACGATGTCTACCCACAGCCCCGGCCGCGAATCCGCATTCATGAGTTGAGTGAGGTGAGTGTGAGTGAGGCCATTAACAACGCGACAAATAGCAAAACAAAACAACGCGCGCTCACAACATTGAGTGAGGAACAACGCGTTGAAATGCGGGTAGATTCTGCTTAAACAACGCGTGCGGGTGACGGTATTAAAATGCGAACAACGCGTTACTGAACAACGCGGCGTGAACAAAACAACGCGGAACAACGCGACAACAACAAAACAACAACGCGCAACGCGTGGTAACAACGCGGGTCCGCGACAACAACGCGCCCGACCCCAACAACGCGAACAACGCGTGCAATGCAACAACGCGCAAACAACGCGTGAATTAACAACGCGTTTGCCTTCGAATGCGCTGTTCCAGCAAAACAACGCGTAACAACGCGCACAATGCGGGTTGCACTTCGCTTGTATACATGGAGCTCATCGATAAATGCGGGAACAACTTCGCTTCGCTTAAGAAATGCGGGTCACTTCGCTTGAGATGAACAACGCGGCACTTCGCTTACTTCGCTTAACGCGATACTACTTCGCTTTCGCTTGCGACAACTTCGCTTTACTTCGCTTCGCTTGTCCTGTTTGTCCTGAATAACAACGCGTTAACTTCGCTTAACGCGTAGTCGTGAATGCACTTCGCTACTTCGCTTGGAACTTCGCTTTCGCTTTAACTTCGCTTATCAGTAGTACAGGGGATAAACAGGGGATAGGGTCAGGGGATAAGGGGATAGACTTCGCTTCTACTTCGCTTCGCAGGGGACTTCGCTTGACCCGGACTTCACTTCGCTTGATAAGCAGGGGATAAGGGGATATATCAGACTTCGCTTGGGGACTTCGCTTGCCGGGCCGGGGACTTCGCACTTCGCTTACCCGGTACCCCCGGCCGGGCCGGGGAACTTCGCTTTCGCTTCGGGCCCGGGCCGGTAGGATACACCCCGGGACTTCGCTTCCCGGTCCACACTTCGCTTGGACTTCGCTTTCACTTCGCTTATACGCACACAAGGACCCGGGCCGGGGGCCGGACCGAAGCAAACCCCAGGGGATAGCCGGGCCGGAATGTACACTATGTACACTTCCATCGACCGCCGGCCATGTACATGTTCCATCGACATGTCCATCGACACATCCATCGACCACTCCCGGTCGCGCCGGGCCATGTACACTGCCGGGCCGTCCATCGACCCGGCTTCCGGGCCGGGATGTACACTCTCCATCGACCGGGCCGGCGATCCATCGACGATGATAATGTACATCCATCGACGGCCTCCATCGACCGACCACTGAATCTGCCCGGCCGGTCCATCGACCGACCACTGCTAACCGGGCCGGCCCCGATGTACACTGTATGTACACTCCTTATTCCATCGACTCCATCGACCCAGGTCCATCGACTTGCTGCTTCCCATGTATGTACACTGTCCATCGACACTCTTACGATGTACACTCCGCTTCCATCGACACCATCGACATCGACCACTATTGGAATGTCCATCGACGTACACTATCCATCGACTATCCATCGACGTATGTACACTTGCAAGATTCCATCGACCCTTAAACAATCCTTCCATCGACATTTCCATCGACATCGACACCCTTAAACTCCATCGTCCATCGACCCCTTAAACCTTCTCTCCCGCTTTGTACCAAATGTCCTCCATCGACTTCCTCCTTAAACACCGTTATTTGCTCCACCCAACTTCTTCCTTATCCTTAAACCCTTAAACCCTAGGTGCTAGGCCTACGCGTAGGCGTCTCCTTAAACCCTTATCCTTAAACTACTCCTTAAACATCCTTAAACTCTCCTTAAACATCTCTTCCTTATCCTTAAACATTTCTTCCGACGTTAGCAAATTTCCTTAAACTTCCGACGACAGGCCGTAAGCACTTCCGACGTCACCATGCCCTTCCGACGGACCATCGTCCTTAAACACGACGCTCCTTAGCGGATGGCAAGCCCTTCCTTAAACTCCGATCCTTAAACCTCTCTTCCGACGCTTCCGACGTAATCCTTAAACCGCACTACTTCCGACGTACTCCTTTCCTTAAACCCTTTCCTTAAACATCGTTTCCACCTTCCGACGGCTTGTAATTTATCTTCCTTAAACGCTCCTTAAACACAACCGCACTTCCGACTCCTTAAACGCGGAAGGCGCTAAGACTTCCGACGCTCAGAATTCTTCCCTTCCGACGTAACTCTTCCGACGGAGATCTGTCTTCCGACGCTTCCGACGGCGATTGGATCTTCCCTTCCGACGTTCCGACGTGCGAATGGGTCGACACTTCCCTTCCGACGAAGTAAGTGGAGCGCTCAAGTGGAGCTGGAGCAAGTGGAGCCGGGAGAGAATTACTGGATTCGAAAAGTGGAGCCAAAGTGAAGTGGAGCGGCTAAAGTGGAGCACGAAGTGGAAGTGGAGCTGCCCAGCAAGTGGAGCAGTGGAGCTAAGTTAGTGGGACAG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TAAGTGCCAGCGCTAATGTTCTGCCTACAAGCGTACAACCTGCCAGCTGCCAGCGCCGCCAGGTGCGGAACCATGCCATGCCAGCGCGTATACCTTCGTCGGTGCCAGCGCAGCGCGCACTTTCCCGGCAAAAAATGTAGGGTAAGTCAAAAGGGAGTGTACTGGAGACTATATGTGTGCCAGCGCTGTTCCGAAGCAATGGCGGTGATGGAACCTTTGATGATGAGCATGATTACCAATCCCACATGCGGTGAGGAAGCGCCCGTTGGATACGAGCTTGTCTCCGTTCTAATCCCGGGTATATGGATCCCCTAGATCCAGTAGGCGTGCGTGCAATCTAGTCAACGTCGTTGTCGGGTCCTCCGCGCCGCACTTTCGATTAACGCTCCGCGACTGCGACAGTTCGTCGTTCGTTTTTGCCGCGGCCACGCTTGTCCGGCTCTAAGAATACGTTACACTGTCTAAGTTTCTGCATTTATAAGTTCTGTGTAAGTGGGCCCTCGAATTGAGGTGGCTGGTCTCTGTGTAATAAACCTTATTGTCTGTGTAACCAAACCTGGGTTTCTTACACCAGCTCTGTCTGTGTAACGTGGTTCTGTGTAATAGGTAGGATCCTCTGTGTAAATCTGTGTAACTTGTAGCTCTGTGTAAATTGTCCATCTTCTGTGTAATGTGTTCTGTGTAACTTGTCTGTGTAAGCTGGCATCTGTGTAAGGAGATAAGTAGTCCAAAACCCCCCCCGCCCGTTTTCTGTGTAAGTCTGTGTAAACGGAAGTCTTCATATACGTCCCAACAGTCTGTGTAATCTGTGTAAGTCTGTGTAACTGTGTCTGTGTAAGTGGTCTGTGTATCTGTGTAATCCGAGTCTGTGTAACTGTGTATCTGTGTAAGCTTGTGAAGTCCACTCCGGTATGCTAGGTGTCTGTGTAAGTTGTTTATTCAGTACGCCTCCTCTGTGTAAGTGTAATGAACCAGGGCGCAGCAATTCTGTGTAAAACTCTGTGTAATACCGGACACTTAGGGTGGAAAGACCTTGGAAATCATGACCACAGGACAAGGCGTTTGGGAGATCTCGTATATTTTTTACGATGTTTACCCACTTCGGGATACGCTGTTCACCTCTGCAAGCTCGGGCTCACCCCTTAATGCTCGGGCTCTTTCCTACATTCGGGTGTGATCGTTGCTCGGGCTGCCGCTGGCATCGCCACAACTTTCGCTCGCTCGGGCTGCGAACCCCAACCATTAGTATTCCCGCTCGGGCTACGATGAAACGAGACCTAAACGCAAATCAGCAATAGCCGACCCTGCTATTCGGGAGGTCACATCTGTTCTAATATCTGCGAGGATGTGCTCGGGCTGGATGCGGGTGTGCAGCTCGGGCGCTCGGGCTGGCTTTCCTACACTGCGAGGAGTTTGGGCGCTCGGGCTGCTTCATCCGCTCGGGCTCGACTGCGAGGCTCGGGCGCTCGGGCTCTGCTCGGGCTGCTCGTCCGGCTCGGGCTCGGGCTTATCGCTCGCTCGGGCTCTCGGGCTGGATAAAACAGTACGCGAGAAGGAGCACTGCGAGGCTGCGAGGAGAGGACCTTCTATCTCTGGCTCGGGCTCGCTCGGGCTTTCTGCGAGCTCGGGCTTCGGGCTCATCTGCGAGCTCGGGCTGGCTACTGCGAGCTCGGGCTATCTCAGCTCGGGCTTCGGGCTGCGAGGAAGGACGGATGCTGCGAGGAGGAAAAAACACTGAATGATCCCTGCGAGGAATTCTGCGAGGAGCATCAGACTGCGAGGAGAGCCGGCCTCAGATTATTAGGAAGATGCGGGGTGCTGCCTGCGAGGAAAGTTATGTGTGGCAGCGAGACCGGTAGAGGAGGCTGCGAGGAATTGACGATACTGCGAGGACCTGAATTGCACTGCGAGGAGAGGAAGTCTGCGAGGAGCATAGGTTCTAATTGATGTGTAGCGTTAATCACTGTCGGTGAATCTGTCAACTCTATACGCGACGTATGTGCACTAAAAACCAGAGATCGATTGAAAGATGGCTCGTTGCCACCCAGGTAAATTGCTAACGGTACCAAATCGCCACAGATGGTTTGACTCCCATCTCCCACGCCATCGGTAATAGAGTGGCGTCTTAAATACTCTGACTAGCGTCCCACCCGAATGGGATCGGCGAGGAGGCGTTAGTTAGACTACCCACCGGTAAGCCTCAGGAACCGTTACTGACGTTAATGGTTTCTCCTCCACTTAACCATAAAGTGCCCAGACAATCAGATCGGCACCACAACCACGAATGCTATACGACTGTCTGCACCCTAAGTGTAAGTCCTACAGACACCCTTTTCATCCTCATGTGAGATCACCGATATAAGTGGTCTGGATAGCAAATATGGGCGAATGCTCCTGAAGTTGCTGTCCCTTTTCGTCTTGGTGATGCGCGTCCGCGGGAGAAACGTATAAGATCTTCTCATGCGTTAAATCCTTTCGGGCACCCGAAATGTATGCATTCCGAGTCGTAGGCCTGCCGGCTCCCATCTTATTTAGAGGGGAAAAGAACCCATGTCCCATTGTGAAACTCTATAATTAATGCGCTCGGATCAGCATTAACTCGTTAGCTCGTATGCCTCTGCTATCACGACTATAATGCTCAATACCTAGCTGGACATTGTACATATCGTCGTTGTAAAGAAGCGATCACACTCTTGAATGAATACGTGGCTATAGCGCAACAGACTCAAGTCGCCTTCTTATTGGTACGCTGGGAGACCCCGACGATTCAGCCTAAACAATCATACTTAGCTCTTTTCTTATTCGGCCAGGTTGGGTTAACACTATAGAGACGTGTTTTGCTGCAAGATAGCCTAGCTATCGAGATTAAAAGCCTTTAAACTCTTCCTCCTATCGTCCGATGCCGTAATTACACTCCCCTGTGGCGACGGATAGCTCCGGCTACGTACCGGCAGAGGATTTAAACAGTGACCTATGGTACATAGGGAAGGCAGTGTGCCAAAAGACGCGGATGCATCCGTAGCAGACGCGGGTTACCCTTACTGGCATTTGATTAGGTTCGAATGAGCTGTCAAGCCGTCGTGTTAAGATAAGCGGCACGGCTACCATGTGTGTGTAACAAGTTCATTTAATACGGCGATAGCCGTTCAGAATTACTGGAGCGCTTTACACACAAACAACCCATAAGACCCCATTATTAGCAAAGCTCGGTCCAAAGCCCAACAGAGTTAGCGGTAGGTGTCACGAACTGCACGAATTCGCGTCTGGACCCTGACTTTCTTTTAAATAATAGTTCTCAGTAGGCTCAGATAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGTAAGATCCGT"
k = 9
L = 564
t = 20
a = betterClumpFinding(g, k, t, L)
p = ""
for i in a:
p += i + " "
print(p)