共识字符串和配置文件矩阵
Consensus string & profile matrix
我已经编写了以下 python 代码来解决 Rosalind 的一个问题 (http://rosalind.info/problems/cons/),出于某种原因,Rosalind 说答案是错误的,但我做了一些抽查并且它似乎正确。
问题如下:
Given: A collection of at most 10 DNA strings of equal length (at most 1 kbp) in FASTA format.
Return: A consensus string and profile matrix for the collection. (If several possible consensus strings exist, then you may return any one of them.)
样本数据集是:
>Rosalind_1
ATCCAGCT
>Rosalind_2
GGGCAACT
>Rosalind_3
ATGGATCT
>Rosalind_4
AAGCAACC
>Rosalind_5
TTGGAACT
>Rosalind_6
ATGCCATT
>Rosalind_7
ATGGCACT
示例解决方案是:
ATGCAACT
A: 5 1 0 0 5 5 0 0
C: 0 0 1 4 2 0 6 1
G: 1 1 6 3 0 1 0 0
T: 1 5 0 0 0 1 1 6
我尝试解决这个问题:
from Bio import SeqIO
A,C,G,T = [],[],[],[]
consensus=""
for i in range(0,len(record.seq)):
countA,countC,countG,countT=0,0,0,0
for record in SeqIO.parse("fasta.txt", "fasta"):
if record.seq[i]=="A":
countA=countA+1
if record.seq[i]=="C":
countC=countC+1
if record.seq[i]=="G":
countG=countG+1
if record.seq[i]=="T":
countT=countT+1
A.append(countA)
C.append(countC)
G.append(countG)
T.append(countT)
if countA >= max(countC,countG,countT):
consensus=consensus+"A"
elif countC >= max(countA,countG,countT):
consensus=consensus+"C"
elif countG >= max(countA,countC,countT):
consensus=consensus+"G"
elif countT >= max(countA,countC,countG):
consensus=consensus+"T"
print("A: "+" ".join([str(i) for i in A]))
print("C: "+" ".join([str(i) for i in C]))
print("G: "+" ".join([str(i) for i in G]))
print("T: "+" ".join([str(i) for i in T]))
print(consensus)
如果有人可以看一下并提出我做错了什么,那就太好了?非常感谢!
对于您的共识字符串,您的代码未处理您有平局的情况,即给定位置的两个核苷酸出现频率相同。您现在编写代码的方式,这种情况将导致在共识字符串
中的那个位置不打印任何内容
这部分
if countA >= max(countC,countG,countT):
consensus=consensus+"A"
elif countC >= max(countA,countG,countT):
consensus=consensus+"C"
elif countG >= max(countA,countC,countT):
consensus=consensus+"G"
elif countT >= max(countA,countC,countG):
consensus=consensus+"T"
改用它,您将正确获得共识序列
if countA[i] >= max(countC[i],countG[i],countT[i]):
consensus+="A"
if countC[i] >= max(countA[i],countG[i],countT[i]):
consensus+="C"
if countG[i] >= max(countA[i],countC[i],countT[i]):
consensus+="G"
if countT[i] >= max(countA[i],countC[i],countG[i]):
consensus+="T"
我已经编写了以下 python 代码来解决 Rosalind 的一个问题 (http://rosalind.info/problems/cons/),出于某种原因,Rosalind 说答案是错误的,但我做了一些抽查并且它似乎正确。
问题如下:
Given: A collection of at most 10 DNA strings of equal length (at most 1 kbp) in FASTA format.
Return: A consensus string and profile matrix for the collection. (If several possible consensus strings exist, then you may return any one of them.)
样本数据集是:
>Rosalind_1
ATCCAGCT
>Rosalind_2
GGGCAACT
>Rosalind_3
ATGGATCT
>Rosalind_4
AAGCAACC
>Rosalind_5
TTGGAACT
>Rosalind_6
ATGCCATT
>Rosalind_7
ATGGCACT
示例解决方案是:
ATGCAACT
A: 5 1 0 0 5 5 0 0
C: 0 0 1 4 2 0 6 1
G: 1 1 6 3 0 1 0 0
T: 1 5 0 0 0 1 1 6
我尝试解决这个问题:
from Bio import SeqIO
A,C,G,T = [],[],[],[]
consensus=""
for i in range(0,len(record.seq)):
countA,countC,countG,countT=0,0,0,0
for record in SeqIO.parse("fasta.txt", "fasta"):
if record.seq[i]=="A":
countA=countA+1
if record.seq[i]=="C":
countC=countC+1
if record.seq[i]=="G":
countG=countG+1
if record.seq[i]=="T":
countT=countT+1
A.append(countA)
C.append(countC)
G.append(countG)
T.append(countT)
if countA >= max(countC,countG,countT):
consensus=consensus+"A"
elif countC >= max(countA,countG,countT):
consensus=consensus+"C"
elif countG >= max(countA,countC,countT):
consensus=consensus+"G"
elif countT >= max(countA,countC,countG):
consensus=consensus+"T"
print("A: "+" ".join([str(i) for i in A]))
print("C: "+" ".join([str(i) for i in C]))
print("G: "+" ".join([str(i) for i in G]))
print("T: "+" ".join([str(i) for i in T]))
print(consensus)
如果有人可以看一下并提出我做错了什么,那就太好了?非常感谢!
对于您的共识字符串,您的代码未处理您有平局的情况,即给定位置的两个核苷酸出现频率相同。您现在编写代码的方式,这种情况将导致在共识字符串
中的那个位置不打印任何内容这部分
if countA >= max(countC,countG,countT):
consensus=consensus+"A"
elif countC >= max(countA,countG,countT):
consensus=consensus+"C"
elif countG >= max(countA,countC,countT):
consensus=consensus+"G"
elif countT >= max(countA,countC,countG):
consensus=consensus+"T"
改用它,您将正确获得共识序列
if countA[i] >= max(countC[i],countG[i],countT[i]):
consensus+="A"
if countC[i] >= max(countA[i],countG[i],countT[i]):
consensus+="C"
if countG[i] >= max(countA[i],countC[i],countT[i]):
consensus+="G"
if countT[i] >= max(countA[i],countC[i],countG[i]):
consensus+="T"