Profile-most Probable k-mer Problem: Find a Profile-most probable k-mer in a string.
Input: A string Text, an integer k, and a 4 × k matrix Profile.
Output: A Profile-most probable k-mer in Text.
Input: A string Text, an integer k, and a 4 × k matrix Profile.
Output: A Profile-most probable k-mer in Text.
CODE CHALLENGE: Solve the Profile-most Probable k-mer Problem.
Sample Input:
ACCTGTTTATTGCCTAAGTTCCGAACAAACCCAATATAGCCCGAGGGCCT
5
0.2 0.2 0.3 0.2 0.3
0.4 0.3 0.1 0.5 0.1
0.3 0.3 0.5 0.2 0.4
0.1 0.2 0.1 0.1 0.2
ACCTGTTTATTGCCTAAGTTCCGAACAAACCCAATATAGCCCGAGGGCCT
5
0.2 0.2 0.3 0.2 0.3
0.4 0.3 0.1 0.5 0.1
0.3 0.3 0.5 0.2 0.4
0.1 0.2 0.1 0.1 0.2
Sample Output:
CCGAG
Вот такое кривое решение с инпутом через нижнюю чакру:CCGAG
def greedy_alg(genome, k, A, C, G, T):
kmer_res = []
max = 0
for i in range(len(genome) - k):
kmer = genome[i:i+k]
prob_res = 1
for j in range(len(kmer)):
if kmer[j] == "A":
probability = A[j]
elif kmer[j] == "C":
probability = C[j]
elif kmer[j] == "G":
probability = G[j]
elif kmer[j] == "T":
probability = T[j]
prob_res *= probability
if prob_res > max:
max = prob_res
kmer_res.append(kmer)
kmer_out = kmer
print (kmer_res)
return kmer_out
print (greedy_alg("ACCTGTTTATTGCCTAAGTTCCGAACAAACCCAATATAGCCCGAGGGCCT", 5, [0.2, 0.2, 0.3, 0.2, 0.3], [0.4, 0.3, 0.1, 0.5, 0.1], [0.3, 0.3, 0.5, 0.2, 0.4], [0.1, 0.2, 0.1, 0.1, 0.2]))
Для решения квиза надо переделать формат инпута. Это челенж, я устала
Немає коментарів:
Дописати коментар