我試圖搜索的核苷酸序列爲用戶定義的圖案,使用正則表達式(僅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