-
Notifications
You must be signed in to change notification settings - Fork 0
/
Motifs1.py
69 lines (62 loc) · 1.48 KB
/
Motifs1.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
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]
count[symbol][j] += 1
return count
A = 'A'
C = 'C'
T = 'T'
G = 'G'
Motifs = [[A,A,C,G,T,A],
[C,C,C,G,T,T],
[C,A,C,C,T,T],
[G,G,A,T,T,A],
[T,T,C,C,G,G],
]
def Profile(Motifs):
profile = {}
t = len(Motifs)
k = len(Motifs[0])
CountMotifs = Count(Motifs)
for symbol in "ACGT":
profile[symbol] = []
for x in CountMotifs:
for y in CountMotifs[x]:
z = y/float(t)
profile[x].append(z)
return profile
def Consensus(Motifs):
k = len(Motifs[0])
count = Count(Motifs)
consensus = ""
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 = 0
k = len(Motifs[0])
t = len(Motifs)
ConsensusMotif = Consensus(Motifs)
for i in range(t):
for j in range(k):
if Motifs[i][j] != ConsensusMotif[j]:
count += 1
return count
print(Count(Motifs))
print(Profile(Motifs))
print(Consensus(Motifs))
print(Score(Motifs))