我正在研究 Rosalind 生物信息学网站 ( http://rosalind.info/problems/cons/ ) 上的“共识 nd Profile”问题。我使用网站上的示例输入尝试了我的代码,并且我的输出与示例输出匹配。但是当我尝试更大的数据集时,网站说我的输出是错误的。有人可以帮我确定我的问题出在哪里吗?谢谢!
样本输入:
>Rosalind_1
ATCCAGCT
>Rosalind_2
GGGCAACT
>Rosalind_3
ATGGATCT
>Rosalind_4
AAGCAACC
>Rosalind_5
TTGGAACT
>Rosalind_6
ATGCCATT
>Rosalind_7
ATGGCACT
我已经提取了 dna 字符串并将它们存储在一个名为 strings 的列表中(我对较大数据集的试验在这一步是正确的,所以我在这里省略了我的代码):
['ATCCAGCT', 'GGGCAACT', 'ATGGATCT', 'AAGCAACC', 'TTGGAACT', 'ATGCCATT', 'ATGGCACT']
之后我的代码:
#convert strings into matrix
matrix = []
for i in strings:
matrix.append([j for j in i])
M = np.array(matrix).reshape(len(matrix),len(matrix[0]))
对于示例输入,M 看起来像这样:
[['A' 'T' 'C' 'C' 'A' 'G' 'C' 'T']
['G' 'G' 'G' 'C' 'A' 'A' 'C' 'T']
['A' 'T' 'G' 'G' 'A' 'T' 'C' 'T']
['A' 'A' 'G' 'C' 'A' 'A' 'C' 'C']
['T' 'T' 'G' 'G' 'A' 'A' 'C' 'T']
['A' 'T' 'G' 'C' 'C' 'A' 'T' 'T']
['A' 'T' 'G' 'G' 'C' 'A' 'C' 'T']]
之后我的代码:
#convert string matrix into profile matrix
A = []
C = []
G = []
T = []
for i in range(len(matrix[0])):
A_count = 0
C_count = 0
G_count = 0
T_count = 0
for j in M[:,i]:
if j == "A":
A_count += 1
elif j == "C":
C_count += 1
elif j == "G":
G_count += 1
elif j == "T":
T_count += 1
A.append(A_count)
C.append(C_count)
G.append(G_count)
T.append(T_count)
profile_matrix = {"A": A, "C": C, "G": G, "T": T}
for k, v in profile_matrix.items():
print k + ":" + " ".join(str(x) for x in v)
#get consensus string
P = []
P.append(A)
P.append(C)
P.append(G)
P.append(T)
profile = np.array(P).reshape(4, len(A))
consensus = []
for i in range(len(A)):
if max(profile[:,i]) == profile[0,i]:
consensus.append("A")
elif max(profile[:,i]) == profile[1,i]:
consensus.append("C")
elif max(profile[:,i]) == profile[2,i]:
consensus.append("G")
elif max(profile[:,i]) == profile[3,i]:
consensus.append("T")
print "".join(consensus)
这些代码给出了正确的示例输出:
A:5 1 0 0 5 5 0 0
C:0 0 1 4 2 0 6 1
T:1 5 0 0 0 1 1 6
G:1 1 6 3 0 1 0 0
ATGCAACT
但是当我尝试更大的数据集时,网站说我的答案是错误的......有人能指出我错在哪里吗?(我是初学者,感谢您的耐心等待!)