Ejemplo n.º 1
0
    def test_smith_waterman_sim(self):
        """Test abydos.distance.SmithWaterman.sim."""
        self.assertEqual(SmithWaterman().sim('', ''), 1.0)

        # https://en.wikipedia.org/wiki/Needleman–Wunsch_algorithm
        self.assertEqual(
            SmithWaterman(1, _sim_nw).sim('GATTACA', 'GCATGCU'), 0)
        self.assertEqual(
            SmithWaterman(5, _sim_wikipedia).sim('AGACTAGTTAC', 'CGAGACGT'),
            0.3241905342349807,
        )

        sw5 = SmithWaterman(5, _sim_nw)
        self.assertEqual(sw5.sim('CGATATCAG', 'TGACGSTGC'), 0)
        self.assertEqual(sw5.sim('AGACTAGTTAC', 'TGACGSTGC'),
                         0.10050378152592121)
        self.assertEqual(sw5.sim('AGACTAGTTAC', 'CGAGACGT'), 0)
Ejemplo n.º 2
0
    def test_smith_waterman_sim_score(self):
        """Test abydos.distance.SmithWaterman.sim_score."""
        self.assertEqual(SmithWaterman().sim_score('', ''), 0)

        # https://en.wikipedia.org/wiki/Needleman–Wunsch_algorithm
        self.assertEqual(
            SmithWaterman(1, _sim_nw).sim_score('GATTACA', 'GCATGCU'), 0)
        self.assertEqual(
            SmithWaterman(5, _sim_wikipedia).sim_score('AGACTAGTTAC',
                                                       'CGAGACGT'),
            26,
        )

        sw5 = SmithWaterman(5, _sim_nw)
        self.assertEqual(sw5.sim_score('CGATATCAG', 'TGACGSTGC'), 0)
        self.assertEqual(sw5.sim_score('AGACTAGTTAC', 'TGACGSTGC'), 1)
        self.assertEqual(sw5.sim_score('AGACTAGTTAC', 'CGAGACGT'), 0)
    def test_smith_waterman_dist_abs(self):
        """Test abydos.distance.SmithWaterman.dist_abs."""
        self.assertEqual(SmithWaterman().dist_abs('', ''), 0)

        # https://en.wikipedia.org/wiki/Needleman–Wunsch_algorithm
        self.assertEqual(
            SmithWaterman(1, _sim_nw).dist_abs('GATTACA', 'GCATGCU'), 0
        )
        self.assertEqual(
            SmithWaterman(5, _sim_wikipedia).dist_abs(
                'AGACTAGTTAC', 'CGAGACGT'
            ),
            26,
        )

        sw5 = SmithWaterman(5, _sim_nw)
        self.assertEqual(sw5.dist_abs('CGATATCAG', 'TGACGSTGC'), 0)
        self.assertEqual(sw5.dist_abs('AGACTAGTTAC', 'TGACGSTGC'), 1)
        self.assertEqual(sw5.dist_abs('AGACTAGTTAC', 'CGAGACGT'), 0)

        # Test wrapper
        self.assertEqual(
            smith_waterman('AGACTAGTTAC', 'CGAGACGT', 5, _sim_wikipedia), 26
        )
Ejemplo n.º 4
0
class SmithWatermanTestCases(unittest.TestCase):
    """Test Smith-Waterman functions.

    abydos.distance.SmithWaterman
    """

    cmp = SmithWaterman()

    def test_smith_waterman_dist_abs(self):
        """Test abydos.distance.SmithWaterman.dist_abs."""
        self.assertEqual(self.cmp.dist_abs('', ''), 0)

        # https://en.wikipedia.org/wiki/Needleman–Wunsch_algorithm
        self.assertEqual(self.cmp.dist_abs('GATTACA', 'GCATGCU', 1, _sim_nw),
                         0)
        self.assertEqual(
            self.cmp.dist_abs('AGACTAGTTAC', 'CGAGACGT', 5, _sim_wikipedia),
            26)

        self.assertEqual(
            self.cmp.dist_abs('CGATATCAG', 'TGACGSTGC', 5, _sim_nw), 0)
        self.assertEqual(
            self.cmp.dist_abs('AGACTAGTTAC', 'TGACGSTGC', 5, _sim_nw), 1)
        self.assertEqual(
            self.cmp.dist_abs('AGACTAGTTAC', 'CGAGACGT', 5, _sim_nw), 0)

        # Test wrapper
        self.assertEqual(
            smith_waterman('AGACTAGTTAC', 'CGAGACGT', 5, _sim_wikipedia), 26)

    def test_smith_waterman_dist_abs_nialls(self):
        """Test abydos.distance.SmithWaterman.dist_abs (Nialls set)."""
        sw_vals = (5, 1, 1, 3, 2, 1, 1, 0, 0, 1, 1, 2, 2, 1, 0, 0)
        for i in range(len(NIALL)):
            self.assertEqual(self.cmp.dist_abs(NIALL[0], NIALL[i], 2, _sim_nw),
                             sw_vals[i])
Ejemplo n.º 5
0
 def test_smith_waterman_sim_score_nialls(self):
     """Test abydos.distance.SmithWaterman.sim_score (Nialls set)."""
     sw_vals = (5, 1, 1, 3, 2, 1, 1, 0, 0, 1, 1, 2, 2, 1, 0, 0)
     sw2 = SmithWaterman(2, _sim_nw)
     for i in range(len(NIALL)):
         self.assertEqual(sw2.sim_score(NIALL[0], NIALL[i]), sw_vals[i])
 def test_smith_waterman_dist_abs_nialls(self):
     """Test abydos.distance.SmithWaterman.dist_abs (Nialls set)."""
     sw_vals = (5, 1, 1, 3, 2, 1, 1, 0, 0, 1, 1, 2, 2, 1, 0, 0)
     sw2 = SmithWaterman(2, _sim_nw)
     for i in range(len(NIALL)):
         self.assertEqual(sw2.dist_abs(NIALL[0], NIALL[i]), sw_vals[i])