Beispiel #1
0
        def test_common(self):
            # https://en.wikipedia.org/wiki/Needleman%E2%80%93Wunsch_algorithm
            nw_matrix = {
                ('A', 'A'): 10,
                ('G', 'G'): 7,
                ('C', 'C'): 9,
                ('T', 'T'): 8,
                ('A', 'G'): -1,
                ('A', 'C'): -3,
                ('A', 'T'): -4,
                ('G', 'C'): -5,
                ('G', 'T'): -3,
                ('C', 'T'): 0,
            }
            sim_matrix = textdistance.Matrix(nw_matrix, symmetric=True)
            alg = self.alg(sim_func=sim_matrix)
            # self.assertEqual(alg('AGACTAGTTAC', 'CGAGACGT'), 26)

            alg = self.alg(gap_open=1, gap_ext=1, sim_func=sim_ident)
            self.assertEqual(alg('GATTACA', 'GCATGCU'), 0)
            alg = self.alg(gap_open=1, gap_ext=.5, sim_func=sim_ident)
            self.assertEqual(alg('GATTACA', 'GCATGCU'), 0)
            self.assertEqual(alg('AGACTAGTTAC', 'TGACGSTGC'), 1.5)
            self.assertEqual(alg('AGACTAGTTAC', 'CGAGACGT'), 1)
            alg = self.alg(gap_open=5, gap_ext=5, sim_func=sim_ident)
            self.assertEqual(alg('AGACTAGTTAC', 'CGAGACGT'), -15)
Beispiel #2
0
 def test_common(self):
     # https://en.wikipedia.org/wiki/Needleman%E2%80%93Wunsch_algorithm
     nw_matrix = {
         ('A', 'A'): 10,
         ('G', 'G'): 7,
         ('C', 'C'): 9,
         ('T', 'T'): 8,
         ('A', 'G'): -1,
         ('A', 'C'): -3,
         ('A', 'T'): -4,
         ('G', 'C'): -5,
         ('G', 'T'): -3,
         ('C', 'T'): 0,
     }
     alg = textdistance.Matrix(nw_matrix, symmetric=True)
     self.assertEqual(alg('', ''), 1)
     self.assertEqual(alg('', 'a'), 0)
     self.assertEqual(alg('abcd', 'abcd'), 1)
     self.assertEqual(alg('A', 'C'), -3)
     self.assertEqual(alg('G', 'G'), 7)
     self.assertEqual(alg('A', 'A'), 10)
     self.assertEqual(alg('T', 'A'), -4)
     self.assertEqual(alg('T', 'C'), 0)
     self.assertEqual(alg('A', 'G'), -1)
     self.assertEqual(alg('C', 'T'), 0)
Beispiel #3
0
        def test_common(self):
            # https://en.wikipedia.org/wiki/Needleman%E2%80%93Wunsch_algorithm
            nw_matrix = {
                ('A', 'A'): 10,
                ('G', 'G'): 7,
                ('C', 'C'): 9,
                ('T', 'T'): 8,
                ('A', 'G'): -1,
                ('A', 'C'): -3,
                ('A', 'T'): -4,
                ('G', 'C'): -5,
                ('G', 'T'): -3,
                ('C', 'T'): 0,
            }
            sim_matrix = textdistance.Matrix(nw_matrix, symmetric=True)
            alg = self.alg(gap_cost=5, sim_func=sim_matrix)
            self.assertEqual(alg('AGACTAGTTAC', 'CGAGACGT'), 26)

            sim_ident = lambda x, y: 2 * int(x == y) - 1
            alg = self.alg(sim_func=sim_ident)
            self.assertEqual(alg('GATTACA', 'GCATGCU'), 0)
            alg = self.alg(gap_cost=5, sim_func=sim_ident)
            self.assertEqual(alg('CGATATCAG', 'TGACGSTGC'), 0)
            self.assertEqual(alg('AGACTAGTTAC', 'TGACGSTGC'), 1)
            self.assertEqual(alg('AGACTAGTTAC', 'CGAGACGT'), 0)