3
import regex,re


sequence = 'aaaaaaaaaaaabbbbbbbbbbbbcccccccccccc' #being searched
query = 'aaabbbbbbbbbbbbccc' #100% coverage
query_1 = 'aaaabbbbbbbbcbbbcccc' #95% coverage
query_2 = 'aaabbbbcbbbbbcbccc' #90% coverage

threshold = .95
error = len(query_1) - (len(query_1)*threshold) #for query_1 errors must be <= 1

print regex.search(query_1 + '{e<={}}'.format(error),sequence).group(0)

我试图向正则表达式搜索添加其他参数,因此它仅在按顺序搜索一定百分比的查询时才有效。

例如,如果我希望它至少有 95% 的覆盖率,它会起作用,query_1但它不会起作用query_2

4

1 回答 1

1

使用regex模块:

import regex
sequence = 'aaaaaaaaaaaabbbbbbbbbbbbcccccccccccc' #being searched
query = 'aaabbbbbbbbbbbbccc' #100% coverage
query_1 = 'aaaabbbbbbbbcbbbcccc' #95% coverage
query_2 = 'aaabbbbcbbbbbcbccc' #90% coverage
threshold = 0.97
queries = (query, query_1, query_2)
for q in queries:
    error = int(len(q) - (len(q)*threshold))
    m = regex.search(r'(%s){e<=%d}'%(q,error), sequence)
    print 'match' if m else 'nomatch'
于 2013-07-03T20:58:28.973 回答