def BMMethod(tDNA, eDNA):
    calc = 0
    jamptable = table(eDNA)
    n1 = len(tDNA)
    n2 = len(eDNA)
    hit_ind = list()

    #index DNA1
    indDNA1 = n2 - 1

    while indDNA1 < n1:
        #number of match
        num_mt = -2
        if tDNA[indDNA1] == eDNA[-1]:
            for indDNA2 in range(-2, (-1 * n2 -1), -1):
                if tDNA[indDNA1 + indDNA2 + 1] == eDNA[indDNA2]:
                    num_mt = num_mt - 1
                    if num_mt == (-1 * n2 - 1):
                        hit_ind.append(indDNA1)
                else:
                    jampnum = jamptable[num_mt]
                    
                    calc = calc + 1
                    break
            indDNA1 = jampnum + indDNA1
        else:
            indDNA1 = indDNA1 + 1
            calc = calc + 1

    return [hit_ind, calc]
                    num_mt = num_mt - 1
                    if num_mt == (-1 * n2 - 1):
                        hit_ind.append(indDNA1)
                else:
                    jampnum = jamptable[num_mt]
                    
                    calc = calc + 1
                    break
            indDNA1 = jampnum + indDNA1
        else:
            indDNA1 = indDNA1 + 1
            calc = calc + 1

    return [hit_ind, calc]

if __name__ == '__main__':
    from MakeDNA import SimpleDNA
    tDNA = SimpleDNA(10).getDNA()
    eDNA = SimpleDNA(10).getDNA()

    #print tDNA
    print table(eDNA)
    print eDNA
    [matchp1, count1] = SimpleSearch(tDNA, eDNA)
    print matchp1
    print count1
    [matchp2, count2] = BMMethod(tDNA, eDNA)
    print matchp2
    print count2