Ejemplo n.º 1
0
    def test_hamming_dist_timing(self):
        list_of_strings = [string_generator() for i in range(10)]
        print(list_of_strings)

        string_result = []
        string_start = time.process_time_ns()
        for s1 in list_of_strings:
            for s2 in list_of_strings:
                string_result.append(naive_hamming_distance(s1, s2))
        string_end = time.process_time_ns()
        print(f'no of mismatches = {string_result}')
        print("string hamming: {:,}".format(string_end - string_start))

        binary_result = []
        binary_start = time.process_time_ns()
        for s1 in list_of_strings:
            for s2 in list_of_strings:
                binary_result.append(hamming_distance(s1, s2))
        binary_end = time.process_time_ns()
        print("binary hamming: {:,}".format(binary_end - binary_start))

        list_of_preprocessed_binaries = []
        for s in list_of_strings:
            list_of_preprocessed_binaries.append(string_to_hamming_binary(s))

        binary_result_pre = []
        binary_start_pre = time.process_time_ns()
        for s1 in list_of_preprocessed_binaries:
            for s2 in list_of_preprocessed_binaries:
                binary_result_pre.append(binary_hamming_dist_calc(s1, s2))
        binary_end_pre = time.process_time_ns()
        print("prepro hamming: {:,}".format(binary_end_pre - binary_start_pre))
        self.assertEqual(string_result, binary_result)
        self.assertEqual(binary_result_pre, binary_result)
Ejemplo n.º 2
0
def hamming_distance_max_stop(string1, string2, max_dist):
    b1 = string_to_hamming_binary(string1)
    b2 = string_to_hamming_binary(string2)
    return binary_hamming_dist_calc_max_stop(b1, b2, max_dist)
Ejemplo n.º 3
0
 def test_longerererer_string_to_binary(self):
     self.assertEqual(
         0b0100000100101000100000010001001010001000000100010010100010000001010000010010100010000001000100101000100000010001001010001000000101000001001010001000000100010010100010000001000100101000100000010100000100101000100000010001001010001000000100010010100010000001010000010010100010000001000100101000100000010001001010001000000101000001001010001000000100010010100010000001000100101000100000010100000100101000100000010001001010001000000100010010100010000001010000010010100010000001000100101000100000010001001010001000000101000001001010001000000100010010100010000001000100101000100000010100000100101000100000010001001010001000000100010010100010000001010000010010100010000001000100101000100000010001001010001000000101000001001010001000000100010010100010000001000100101000100000010100000100101000100000010001001010001000000100010010100010000001010000010010100010000001000100101000100000010001001010001000000101000001001010001000000100010010100010000001000100101000100000010100000100101000100000010001001010001000000100010010100010000001,
         string_to_hamming_binary(
             'GACTTAACTTAACTTAGACTTAACTTAACTTAGACTTAACTTAACTTAGACTTAACTTAACTTAGACTTAACTTAACTTAGACTTAACTTAACTTAGACTTAACTTAACTTAGACTTAACTTAACTTAGACTTAACTTAACTTAGACTTAACTTAACTTAGACTTAACTTAACTTAGACTTAACTTAACTTAGACTTAACTTAACTTAGACTTAACTTAACTTAGACTTAACTTAACTTAGACTTAACTTAACTTA'
         ))  # 256 chars
Ejemplo n.º 4
0
 def test_two_letters_to_binary(self):
     self.assertEqual(0b00010001, string_to_hamming_binary('AA'))
     self.assertEqual(0b00101000, string_to_hamming_binary('CT'))
     self.assertEqual(0b01000001, string_to_hamming_binary('GA'))
     self.assertEqual(0b10000100, string_to_hamming_binary('TG'))
Ejemplo n.º 5
0
 def test_one_letter_to_binary(self):
     self.assertEqual(0b0000, string_to_hamming_binary('*'))
     self.assertEqual(0b0001, string_to_hamming_binary('A'))
     self.assertEqual(0b0010, string_to_hamming_binary('C'))
     self.assertEqual(0b0100, string_to_hamming_binary('G'))
     self.assertEqual(0b1000, string_to_hamming_binary('T'))