Exemple #1
0
 def test_from_iterable_with_key_and_keys(self):
     iterable = (x for x in range(4))
     with self.assertRaises(ValueError):
         DissimilarityMatrix.from_iterable(iterable,
                                           lambda a, b: abs(b - a),
                                           key=str,
                                           keys=['1', '2', '3', '4'])
Exemple #2
0
 def test_from_iterable_with_key_and_keys(self):
     iterable = (x for x in range(4))
     with self.assertRaises(ValueError):
         DissimilarityMatrix.from_iterable(iterable,
                                           lambda a, b: abs(b - a),
                                           key=str,
                                           keys=['1', '2', '3', '4'])
Exemple #3
0
    def test_from_iterable_asymmetric_data(self):
        iterable = (x for x in range(4))

        exp = DissimilarityMatrix([[0, 1, 2, 3], [-1, 0, 1, 2], [-2, -1, 0, 1],
                                   [-3, -2, -1, 0]])
        res = DissimilarityMatrix.from_iterable(iterable, lambda a, b: b - a)
        self.assertEqual(res, exp)
Exemple #4
0
    def test_from_iterable_non_hollow_data(self):
        iterable = (x for x in range(4))

        exp = DissimilarityMatrix([[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1],
                                   [1, 1, 1, 1]])
        res = DissimilarityMatrix.from_iterable(iterable, lambda a, b: 1)
        self.assertEqual(res, exp)
Exemple #5
0
    def test_from_iterable_no_key(self):
        iterable = (x for x in range(4))

        exp = DissimilarityMatrix([[0, 1, 2, 3], [1, 0, 1, 2], [2, 1, 0, 1],
                                   [3, 2, 1, 0]])
        res = DissimilarityMatrix.from_iterable(iterable,
                                                lambda a, b: abs(b - a))
        self.assertEqual(res, exp)
Exemple #6
0
    def test_from_iterable_asymmetric_data(self):
        iterable = (x for x in range(4))

        exp = DissimilarityMatrix([[0, 1, 2, 3],
                                   [-1, 0, 1, 2],
                                   [-2, -1, 0, 1],
                                   [-3, -2, -1, 0]])
        res = DissimilarityMatrix.from_iterable(iterable, lambda a, b: b - a)
        self.assertEqual(res, exp)
Exemple #7
0
    def test_from_iterable_non_hollow_data(self):
        iterable = (x for x in range(4))

        exp = DissimilarityMatrix([[1, 1, 1, 1],
                                   [1, 1, 1, 1],
                                   [1, 1, 1, 1],
                                   [1, 1, 1, 1]])
        res = DissimilarityMatrix.from_iterable(iterable, lambda a, b: 1)
        self.assertEqual(res, exp)
Exemple #8
0
    def test_from_iterable_with_key(self):
        iterable = (x for x in range(4))

        exp = DissimilarityMatrix(
            [[0, 1, 2, 3], [1, 0, 1, 2], [2, 1, 0, 1], [3, 2, 1, 0]],
            ['0', '1', '4', '9'])
        res = DissimilarityMatrix.from_iterable(iterable,
                                                lambda a, b: abs(b - a),
                                                key=lambda x: str(x**2))
        self.assertEqual(res, exp)
Exemple #9
0
    def test_from_iterable_no_key(self):
        iterable = (x for x in range(4))

        exp = DissimilarityMatrix([[0, 1, 2, 3],
                                   [1, 0, 1, 2],
                                   [2, 1, 0, 1],
                                   [3, 2, 1, 0]])
        res = DissimilarityMatrix.from_iterable(iterable,
                                                lambda a, b: abs(b - a))
        self.assertEqual(res, exp)
Exemple #10
0
    def test_from_iterable_with_key(self):
        iterable = (x for x in range(4))

        exp = DissimilarityMatrix([[0, 1, 2, 3],
                                   [1, 0, 1, 2],
                                   [2, 1, 0, 1],
                                   [3, 2, 1, 0]], ['0', '1', '4', '9'])
        res = DissimilarityMatrix.from_iterable(iterable,
                                                lambda a, b: abs(b - a),
                                                key=lambda x: str(x ** 2))
        self.assertEqual(res, exp)
Exemple #11
0
    def test_from_iterable_skbio_hamming_metric_with_metadata(self):
        # test for #1254
        seqs = [
            Sequence('ACGT'),
            Sequence('ACGA', metadata={'id': 'seq1'}),
            Sequence('AAAA', metadata={'id': 'seq2'}),
            Sequence('AAAA', positional_metadata={'qual': range(4)})
        ]

        exp = DissimilarityMatrix(
            [[0, 0.25, 0.75, 0.75], [0.25, 0.0, 0.5, 0.5],
             [0.75, 0.5, 0.0, 0.0], [0.75, 0.5, 0.0, 0.0]],
            ['a', 'b', 'c', 'd'])

        dm = DissimilarityMatrix.from_iterable(
            seqs,
            metric=skbio.sequence.distance.hamming,
            keys=['a', 'b', 'c', 'd'])

        self.assertEqual(dm, exp)
Exemple #12
0
    def test_from_iterable_skbio_hamming_metric_with_metadata(self):
        # test for #1254
        seqs = [
            Sequence('ACGT'),
            Sequence('ACGA', metadata={'id': 'seq1'}),
            Sequence('AAAA', metadata={'id': 'seq2'}),
            Sequence('AAAA', positional_metadata={'qual': range(4)})
        ]

        exp = DissimilarityMatrix([
            [0, 0.25, 0.75, 0.75],
            [0.25, 0.0, 0.5, 0.5],
            [0.75, 0.5, 0.0, 0.0],
            [0.75, 0.5, 0.0, 0.0]], ['a', 'b', 'c', 'd'])

        dm = DissimilarityMatrix.from_iterable(
            seqs,
            metric=skbio.sequence.distance.hamming,
            keys=['a', 'b', 'c', 'd'])

        self.assertEqual(dm, exp)
Exemple #13
0
 def test_from_iterable_single(self):
     exp = DissimilarityMatrix([[100]])
     res = DissimilarityMatrix.from_iterable(["boo"], lambda a, b: 100)
     self.assertEqual(res, exp)
Exemple #14
0
 def test_from_iterable_empty(self):
     with self.assertRaises(DissimilarityMatrixError):
         DissimilarityMatrix.from_iterable([], lambda x: x)
Exemple #15
0
 def test_from_iterable_single(self):
     exp = DissimilarityMatrix([[100]])
     res = DissimilarityMatrix.from_iterable(["boo"], lambda a, b: 100)
     self.assertEqual(res, exp)
Exemple #16
0
 def test_from_iterable_empty(self):
     with self.assertRaises(DissimilarityMatrixError):
         DissimilarityMatrix.from_iterable([], lambda x: x)