Exemple #1
0
 def check_edit_distance(t, w, m, k, index):
   for i in range(max(0, index - m - k), index):
     if distance.distance(
         '#' + t[i + 1:index + 1], w, index - i, m,
         distance.EDIT_DISTANCE) <= k:
       return True
   return False
Exemple #2
0
 def test_random_lcs(self, _, algorithm):
     T, n_1, n_2, A = 100, 7, 7, ['a', 'b']
     for _ in range(T):
         t_1, t_2 = rand.random_word(n_1, A), rand.random_word(n_2, A)
         self.check_lcs(
             t_1, t_2, n_1, n_2,
             distance.distance(t_1, t_2, n_1, n_2, distance.INDEL_DISTANCE),
             algorithm)
 def test_random_edit_distance(self, _, algorithm):
     T, n_1, n_2, A = 100, 15, 15, ['a', 'b']
     for _ in range(T):
         t_1, t_2 = rand.random_word(n_1, A), rand.random_word(n_2, A)
         reference = distance.distance(t_1, t_2, n_1, n_2,
                                       distance.EDIT_DISTANCE)
         self.check_distance(t_1, t_2, n_1, n_2, reference,
                             distance.EDIT_DISTANCE, algorithm)
 def test_all_indel_distance(self, _, algorithm):
     N_1, N_2, A = 4, 4, ['a', 'b']
     for n_1 in range(2, N_1 + 1):
         for t_1 in itertools.product(A, repeat=n_1):
             t_1 = '#' + ''.join(t_1)
             for n_2 in range(2, N_2 + 1):
                 for t_2 in itertools.product(A, repeat=n_2):
                     t_2 = '#' + ''.join(t_2)
                     reference = distance.distance(t_1, t_2, n_1, n_2,
                                                   distance.INDEL_DISTANCE)
                     self.check_distance(t_1, t_2, n_1, n_2, reference,
                                         distance.INDEL_DISTANCE, algorithm)
Exemple #5
0
 def check_hamming_distance(t, w, m, k, index):
   if index + m > len(t):
     return False
   return distance.distance(
       '#' + t[index:index + m], w, m, m, distance.HAMMING_DISTANCE) <= k