我正在Rosalind生物信息學網站(http://rosalind.info/problems/cons/)上處理「Consensus nd Profile」問題。我使用網站上的示例輸入嘗試了我的代碼,輸出與示例輸出相匹配。但是當我嘗試更大的數據集時,網站表示我的輸出是錯誤的。有人能幫我確定我的問題在哪裏嗎?謝謝!Rosalind共識和個人檔案python
樣品輸入:
>Rosalind_1
ATCCAGCT
>Rosalind_2
GGGCAACT
>Rosalind_3
ATGGATCT
>Rosalind_4
AAGCAACC
>Rosalind_5
TTGGAACT
>Rosalind_6
ATGCCATT
>Rosalind_7
ATGGCACT
我已經提取的DNA串,並將它們存儲在列表稱爲字符串(我用更大的數據集試驗是在這一步正確的,所以我在這裏上遺漏了我的代碼):
['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]))
中號看起來像這樣的樣本輸入:
[['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
但當我更大的數據集的網站說,我的答案是錯的...有人能指出我錯在哪裏嗎? (我是初學者,感謝您的耐心!)
確保您的格式與樣本輸出完全匹配。這意味着在每行的冒號後加一個空格,將共有字符串放在頂部,並按照「ACGT」的順序排列核苷酸。 –
你見過這個嗎? http://stackoverflow.com/questions/38586800/python-multiple-consensus-sequences/ –
@C_Z_哦,我沒有注意到之前...謝謝你的提示! – largecats