-
Notifications
You must be signed in to change notification settings - Fork 0
/
17.py
44 lines (39 loc) · 2.15 KB
/
17.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
def Pr(Text, Profile):
pro = 1
for i in range(len(Text)):
base = Text[i]
pr_base = Profile[base][i]
pro = pro*pr_base
return pro
def ProfileMostProbableKmer(text, k, profile):
maxi = -1
x = 0
for i in range(len(text)-k+1):
out = Pr(text[i:i+k], profile)
print(out)
if out > maxi:
maxi = out
x = i
ans = text[x:x+k]
print(Pr(ans, profile))
return ans
# test = 'ACCTGTTTATTGCCTAAGTTCCGAACAAACCCAATATAGCCCGAGGGCCT'
# k = 5
# pro = {
# 'A':[0.2, 0.2, 0.3, 0.2, 0.3],
# 'C':[0.4 ,0.3, 0.1, 0.5, 0.1],
# 'G':[0.3, 0.3 ,0.5, 0.2, 0.4],
# 'T':[0.1, 0.2, 0.1, 0.1, 0.2]
# }
# res = ProfileMostProbableKmer(test, k, pro)
# print(res)
test = 'AAATCAGCCCACCTGGTAAGCACTATAGATGTACTCCCAGCCTCACTTTTGAGAATGATCGTGATCAAGTCCACCTCGGGCAGGAAAGCTCAATAATGGGTCAAACATTATTGCACGTACCGTTTCCAGGGACTAGGGAAAGTCACTCGATTCCACAAGAAGACATCCCGGTAGGATAGACAATAGACGGTTCCCGGTGCACTTCGCAGGGCGGTCCTGACAAACGGTCAATTCGCGCCAGACGAACACATCATAGGGCCGATACAAGCAGGTGGTCGCCCATGGAGACCCAAGGTATCAATAGAGCCGGATCAGGCTACCACTCAATGCCTGGCGAGATTCTATGGATCAGGAGTCTGTACGTGCAACTGGTCTAGGCGGAAACCTTGAGCTCAGTTTTACGCGGTGTTACAGGTACCGAGCAATCTCGGACGGGGCAACACGGGCCCCAACGTATTCGTTAAAGCACAGTATCGAGTGGTCGGGGCGAATATTGTTTTACTCCTTTTATTTAGACGTTGCTGTTTCGTGCTCCCACGACGATGGGCAGTCTAATTGTCACCGTCGATAGCTTTTACAAGTACTTCAGTAGTACCTCGACATTCGGAACATCAGACCCTCTCGTGAGTTACCTATGACCAAACCTCGTGGCGGAGGAGGCATGGTTAACGAAAATACGCAGCCAAAGATGTGCAATGGAAGCCAATATTTGCACTACTAGTAGGGCATTAATCTAACACTACGCCGTGGCTGATTCTTAGGCGACCATCCATTGCCAGGTACGTTACCCCCACGAATAAATTGGGAGCGCACAGTCTGCTAGGGATATGCTGAGGTCCTCGGGGGGCATTTCGGAGAAGCTCACCCTTGCATCGCTGGTTCAGGAGAGCCGGCATACTGTGCTCCGCTACCTCGATGTGGTCCTCGGATTCACAACAAGACGCCCCAAGATTCGTCGCTTAACCGATGTATTGACGTCTCCTCGATTGTTTACATGAGT'
k = 13
pro = {
'A':[0.145, 0.197, 0.25, 0.211, 0.25, 0.289, 0.355, 0.224, 0.211, 0.276, 0.329, 0.289, 0.184],
'C':[0.395, 0.289, 0.25, 0.237, 0.184, 0.211, 0.289, 0.25, 0.224, 0.158, 0.171, 0.25, 0.25],
'G':[0.276, 0.355, 0.303, 0.303, 0.25, 0.211, 0.224, 0.289, 0.342, 0.263, 0.316, 0.237, 0.237],
'T':[0.184, 0.158, 0.197, 0.25, 0.316, 0.289, 0.132, 0.237, 0.224, 0.303, 0.184, 0.224, 0.329]
}
res = ProfileMostProbableKmer(test, k, pro)
print(res)