-
Notifications
You must be signed in to change notification settings - Fork 0
/
Find a Profile-most Probable k-mer in a String.py
56 lines (41 loc) · 1.4 KB
/
Find a Profile-most Probable k-mer in a String.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
from reference_tables import bases
def mostProbable(text, n, profile):
def prob(kmer):
p = 1
for j in range(n):
i = bases.find(kmer[j])
p *= profile[i][j]
return p
def findMostProbable():
probability = -1
best = []
for i in range(len(text) - n + 1):
p = prob(text[i:i + n])
if probability < p:
probability = p
best = text[i:i + n]
return best
return findMostProbable()
f = open("C:/Users/iMan/PycharmProjects/RosalindExercises/rosalind_ba2c.txt","r")
text = f.read()
k=7
string = "CGTTCCTTGCAGAGTTTACACAGCATAAAAGGATCCGCACAGAGGATACGTCAGCCAGTGGCAAACGGGCGTCTCTCGTGTCTTCGTCGTACTGACACAGCTATCTCCGTCATAGTAGGTTACTAGGTCCACAGTTACACGGCGAGGCCAGCTGCCAGAGCATCGCAATAACCGAATGCTTGTTAAGGCGTAGAGGGGCG"
T=[]
profileTable = text.split("\n")
rows_0 = profileTable[0].split()
rows_1 = profileTable[1].split()
rows_2 = profileTable[2].split()
rows_3 = profileTable[3].split()
for i in range(0, len(rows_0)):
rows_0[i] = float(rows_0[i])
for i in range(0, len(rows_1)):
rows_1[i] = float(rows_1[i])
for i in range(0, len(rows_2)):
rows_2[i] = float(rows_2[i])
for i in range(0, len(rows_3)):
rows_3[i] = float(rows_3[i])
T.insert(0,rows_0)
T.insert(1,rows_1)
T.insert(2,rows_2)
T.insert(3,rows_3)
print(mostProbable(string,k,T))