从 dna 序列列表开始,我必须返回所有可能的共有序列(在每个位置具有最高核苷酸频率的结果序列)序列。如果在某些位置核苷酸具有相同的最高频率,我必须获得具有最高频率的所有可能组合。我还必须返回配置文件矩阵(每个序列的每个核苷酸频率的矩阵)。
到目前为止,这是我的代码(但它只返回一个共识序列):
seqList = ['TTCAAGCT','TGGCAACT','TTGGATCT','TAGCAACC','TTGGAACT','ATGCCATT','ATGGCACT']
n = len(seqList[0])
profile = { 'T':[0]*n,'G':[0]*n ,'C':[0]*n,'A':[0]*n }
for seq in seqList:
for i, char in enumerate(seq):
profile[char][i] += 1
consensus = ""
for i in range(n):
max_count = 0
max_nt = 'x'
for nt in "ACGT":
if profile[nt][i] > max_count:
max_count = profile[nt][i]
max_nt = nt
consensus += max_nt
print(consensus)
for key, value in profile.items():
print(key,':', " ".join([str(x) for x in value] ))
TTGCAACT
C : 0 0 1 3 2 0 6 1
A : 2 1 0 1 5 5 0 0
G : 0 1 6 3 0 1 0 0
T : 5 5 0 0 0 1 1 6
(如你所见,在位置四,C和G得分相同,这意味着我必须获得两个共识序列)
是否可以修改此代码以获得所有可能的序列,或者您能否解释一下逻辑(伪代码)如何获得正确的结果?
非常感谢您!