-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScore.py
47 lines (41 loc) · 1.13 KB
/
Score.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
def Count(Motifs):
count = {}
k = len(Motifs[0])
for symbol in "ACGT":
count[symbol] = []
for j in range(k):
count[symbol].append(0)
t = len(Motifs)
for i in range(t):
for j in range(k):
symbol = Motifs[i][j] # range over all elements symbol = Motifs[i][j] of the count matrix
count[symbol][j] += 1 # add 1 to count[symbol][j].
return count
def Consensus(Motifs):
consensus = ""
count = Count(Motifs)
k = len(Motifs[0])
for j in range(k):
m = 0
frequentSymbol = ""
for symbol in "ACGT":
if count[symbol][j] > m:
m = count[symbol][j]
frequentSymbol = symbol
consensus += frequentSymbol
return consensus
def Score(Motifs):
count = Count(Motifs)
consensus = Consensus(Motifs)
score = 0
i = 0
r = len(Motifs)
for char in consensus:
p = count[char][i]
x = r - p
score += x
i = i+1
return score
a = []
a = ["AACGTA", "CCCGTT", "CACCTT", "GGATTA", "TTCCGG"]
print(Score(a))