【发布时间】:2012-06-13 15:49:31
【问题描述】:
我正在研究蛋白质序列的匹配算法。我从一个对齐的蛋白质序列开始,我试图将一个未对齐的序列转换为正确对齐的序列。这是一个例子:
原始对齐序列:----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-----
我似乎无法让循环多次正确删除字母之间不需要的破折号,因为其余的循环迭代用于添加破折号/删除破折号对。
这是解决问题的良好开端。
我怎样才能成功地编写这个循环以获得我想要的输出(两个相同的序列)
【问题讨论】:
-
此代码示例中没有循环
-
感谢您指出这一点!我想我在随机播放中丢失了循环命令
标签: python algorithm for-loop pattern-matching sequence