Python:多个共识序列

标签 python bioinformatics rosalind

从 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具有相同的最高分数,这意味着我必须获得两个共有序列)

是否可以修改这段代码来获取 所有可能的序列,或者您能给我解释一下如何获得正确结果的逻辑(伪代码)吗?

提前非常感谢您!

最佳答案

我确信有更好的方法,但这是一个简单的方法:

bestseqs = [[]]
for i in range(n):
    d = {N:profile[N][i] for N in ['T','G','C','A']}
    m = max(d.values())
    l = [N for N in ['T','G','C','A'] if d[N] == m]
    bestseqs = [ s+[N] for N in l for s in bestseqs ]

for s in bestseqs:
    print(''.join(s))

# output:
ATGGAACT
ATGCAACT

关于Python:多个共识序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38586800/

相关文章:

python - 在 ListCtrl 中放置一个按钮 - wxPython

python - Numba - nopython 模式比对象模式慢?

Python 线程 self._stop() 'Event' 对象不可调用

python - 下载多种生物的蛋白质序列

python - snakemake:规则的可选输入

python - Rosalind 共识和简介 python

Javascript 对 Python 中的相同算法给出了不同的答案

python - Seaborn 错误?热图绘制不一致

c++ - 通过 StringSet 进行在线模式搜索

python - 用元组填充列表