gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:44:40 25 4
gpt4 key购买 nike

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

原始比对序列:----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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com