以找到蛋白质序列中已识别模式的位置

问题描述 投票:0回答:1

我正在尝试编写代码以查找蛋白质序列中的模式,然后找到所识别模式的位置(开始和结束)。对于已识别的模式,当我使用.index()搜索索引时,如果存在多个模式,则无法获得正确的开始位置。但是在这里,我需要已识别模式的开始和结束位置。我正在寻找一种简单快捷的方法,而不是进行BLAST。

from Bio import SeqIO

import re

sequence='FWSTQALLPTTLLGASP'
for seqs in SeqIO.parse(sequence, 'fasta'):
        #to find pattern
        p = re.compile('L*') 
        seqstr=str(seqs.seq)
        patternA=p.findall(seqstr)
        print (patternA)
        for t in patternA:
                print (seqstr.index(t))

预期结果:7 LL 812 LL 13预先感谢。

python bioinformatics biopython
1个回答
0
投票
first索引。无论如何,您可以使用re.finderiter() like this:解决此问题

>>> sequence ='FWSTQALLPTTLLGASP' >>> matches = re.finditer(r'(?=(LL))', sequence) >>> [(start+1, end) for start, end in (match.span(1) for match in matches)] [(7, 8), (12, 13)]

© www.soinside.com 2019 - 2024. All rights reserved.