我试图搜索的核苷酸序列为用户定义的图案,使用正则表达式(仅A,C,G,T组成)搜索模式:的Python:使用字符串变量如在正则表达式
相关代码如下:
match = re.match(r'{0}'.format(pattern), sequence)
比赛总是返回None,在我需要它返回用户查询相匹配的序列的一部分...
我在做什么错?
编辑:这是我构建的搜索模式:
askMotif = raw_input('Enter a motif to search for it in the sequence (The wildcard character ‘?’ represents any nucleotide in that position, and * represents none or many nucleotides in that position.): ')
listMotif= []
letterlist = ['A','C','G','T', 'a', 'c','g','t']
for letter in askMotif:
if letter in letterlist:
a = letter.capitalize()
listMotif.append(a)
if letter == '?':
listMotif.append('.')
if letter == '*':
listMotif.append('*?')
pattern = ''
for searcher in listMotif:
pattern+=searcher
不是很Python的,我知道......
你可以发布你的测试用例吗? – letsc 2015-04-01 22:52:11
你是指我在寻找的序列吗?它真的很长......就像超过1000个字符 – user3472351 2015-04-01 22:53:12
当你对模式进行硬编码时会发生什么? – 2015-04-01 22:53:26