def approximate_pattern_match(pattern,text,d):
	idx = []
	k = len(pattern)
	for i in range(len(text)-k+1):
		if hd.hamming_distance(text[i:i+k],pattern) <= d:
			idx.append(i)
	return idx
def approximate_pattern_match(pattern, text, d):
    idx = []
    k = len(pattern)
    for i in range(len(text) - k + 1):
        if hd.hamming_distance(text[i:i + k], pattern) <= d:
            idx.append(i)
    return idx
def neighbors(pattern, d):
    if d == 0:
        return pattern
    if len(pattern) == 1:
        return ["A", "C", "G", "T"]

    neighborhood = []
    suffixNeighbors = neighbors(pattern[1:], d)
    for text in suffixNeighbors:
        if hd.hamming_distance(pattern[1:], text) < d:
            for x in ["A", "C", "G", "T"]:
                neighborhood.append(x + text)
        else:
            neighborhood.append(pattern[:1] + text)
    neighborhood = list(set(neighborhood))
    return neighborhood
def neighbors(pattern, d):
    if d == 0:
        return pattern
    if len(pattern) == 1:
        return ['A', 'C', 'G', 'T']

    neighborhood = []
    suffixNeighbors = neighbors(pattern[1:], d)
    for text in suffixNeighbors:
        if hd.hamming_distance(pattern[1:], text) < d:
            for x in ['A', 'C', 'G', 'T']:
                neighborhood.append(x + text)
        else:
            neighborhood.append(pattern[:1] + text)
    neighborhood = list(set(neighborhood))
    return neighborhood
def approximatePatternCount(text, pattern, d):
    count = 0
    for i in range(len(text) - len(pattern) + 1):
        if hd.hamming_distance(text[i : i + len(pattern)], pattern) <= d:
            count += 1
    return count
Пример #6
0
def approximatePatternCount(pattern, text, d):
    count = 0
    for i in range(len(text) - len(pattern) + 1):
        if hd.hamming_distance(text[i:i + len(pattern)], pattern) <= d:
            count += 1
    return count