python - 蛋白质序列模式匹配python

标签 python algorithm for-loop pattern-matching sequence

我正在研究蛋白质序列的匹配算法。我从对齐的蛋白质序列开始,我试图将错误对齐的序列转换为正确对齐的序列。这是一个例子:

原始比对序列:----AB--C-D-----

错位序列:--A--BC---D-

预期的输出应该是这样的:

原始比对序列:----AB--C-D-----

错误对齐的序列:----AB--C-D-----(两者现在相同)

有人告诉我要非常具体地说明我的问题,但我尝试匹配的序列长度超过 4000 个字符,粘贴到此处时看起来很可笑。不过,我将发布两个代表我的问题的序列,这应该可以。

seq="---A-A--AA---A--"
newseq="AA---A--A-----A-----"
seq=list(seq) #changing maaster sequence from string to list
newseq=list(newseq) #changing new sequence from string to list
n=len(seq) #obtaining length of master sequence
newseq.extend('.') #adding a tag to end of new sequence to account for terminal gaps

print(seq, newseq,n) #verification of sequences in list form and length

for i in range(n)
    if seq[i]!=newseq[i]:
        if seq[i] != '-': #gap deletion
            del newseq[i]

        elif newseq[i] != '-':
            newseq.insert(i,'-') #gap insertion


        elif newseq[i] == '-':
            del newseq[i]


old=''.join(seq) #changing list to string
new=''.join(newseq) #changing list to string
new=new.strip('.') #removing tag

print(old) #verification of master-sequence fidelity
print(new) #verification of matching sequence

我从这个特定代码和序列集得到的输出是:

---A-A--AA---A--

---A-A--A----A-----A-----

我似乎无法让循环多次正确删除字母之间不需要的破折号,因为循环迭代的其余部分用于添加破折号/删除破折号对。
这是解决此处问题的良好开端。

我怎样才能成功地编写这个循环以获得我想要的输出(两个相同的序列)

最佳答案

序列比对的问题是众所周知的,其解决方案也有很好的描述。有关介绍性文本,请参阅 Wikipedia .我知道的最佳解决方案涉及动态编程,您可以在 this site 查看 Java 中的示例实现。 .

关于python - 蛋白质序列模式匹配python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11018666/

相关文章:

python - 错误 : Argument must be a dense tensor: range(2, 3) - 得到形状 [1],但想要 []

image - 比较图像和文件中的数据

c - 二维数组中的意外输出

python - 如何在 pandas 中优化此类搜索和替换

python - 将每个实例蒙版合并回原始图像 Python

python - Flask Button 在不刷新页面的情况下运行 Python?

php - 显示从最小值到最大值的轴 - 计算比例和标签

c++ - 有限空间内的图可达性

for-loop - 替换列中的某些单元格值

for-loop - GO - for 循环中的子例程行为