Пример #1
0
    def test_block_party_tree(self):
        counts = np.array([[1, 1, 1], [1, 0, 1], [1, 0, 1], [0, 0, 1],
                           [0, 1, 1]])
        tree = TreeNode.read(['(a:1,b:2,c:3);'])
        otu_ids = ['a', 'b', 'c']

        kw = {'tree': tree, 'otu_ids': otu_ids}
        kw_no_a = {'tree': tree.shear(['b', 'c']), 'otu_ids': ['b', 'c']}
        kw_no_b = {'tree': tree.shear(['a', 'c']), 'otu_ids': ['a', 'c']}

        # python >= 3.5 supports {foo: bar, **baz}
        exp = [
            dict(counts=np.array([[1, 1, 1], [1, 0, 1]]), **kw),
            dict(counts=np.array([[1, 1, 1], [1, 0, 1], [1, 0, 1], [0, 0, 1]]),
                 **kw),
            dict(counts=np.array([[1, 1, 1], [1, 0, 1], [0, 1, 1]]), **kw),
            dict(counts=np.array([[1, 1], [0, 1]]), **kw_no_b),
            dict(counts=np.array([[1, 0, 1], [0, 0, 1], [0, 1, 1]]), **kw),
            dict(counts=np.array([[1, 1]]), **kw_no_a)
        ]

        obs = [
            _block_party(counts, rids, cids, **kw)
            for rids, cids in _generate_id_blocks(list(range(5)), 2)
        ]

        for okw, ekw in zip(obs, exp):
            npt.assert_equal(okw['counts'], ekw['counts'])
            npt.assert_equal(okw['otu_ids'], ekw['otu_ids'])
            self.assertEqual(str(okw['tree']), str(ekw['tree']))
Пример #2
0
    def test_block_party_tree(self):
        counts = np.array([[1, 1, 1],
                           [1, 0, 1],
                           [1, 0, 1],
                           [0, 0, 1],
                           [0, 1, 1]])
        tree = TreeNode.read(['(a:1,b:2,c:3);'])
        otu_ids = ['a', 'b', 'c']

        kw = {'tree': tree, 'otu_ids': otu_ids}
        kw_no_a = {'tree': tree.shear(['b', 'c']), 'otu_ids': ['b', 'c']}
        kw_no_b = {'tree': tree.shear(['a', 'c']), 'otu_ids': ['a', 'c']}

        # python >= 3.5 supports {foo: bar, **baz}
        exp = [dict(counts=np.array([[1, 1, 1], [1, 0, 1]]), **kw),
               dict(counts=np.array([[1, 1, 1], [1, 0, 1], [1, 0, 1],
                                     [0, 0, 1]]), **kw),
               dict(counts=np.array([[1, 1, 1], [1, 0, 1], [0, 1, 1]]), **kw),
               dict(counts=np.array([[1, 1], [0, 1]]), **kw_no_b),
               dict(counts=np.array([[1, 0, 1], [0, 0, 1], [0, 1, 1]]), **kw),
               dict(counts=np.array([[1, 1]]), **kw_no_a)]

        obs = [_block_party(counts, rids, cids, **kw) for rids, cids in
               _generate_id_blocks(list(range(5)), 2)]

        for okw, ekw in zip(obs, exp):
            npt.assert_equal(okw['counts'], ekw['counts'])
            npt.assert_equal(okw['otu_ids'], ekw['otu_ids'])
            self.assertEqual(str(okw['tree']), str(ekw['tree']))
Пример #3
0
 def test_block_party_notree(self):
     counts = np.arange(15).reshape(5, 3)
     exp = [{
         'counts': np.array([[0, 1, 2], [3, 4, 5]]),
         'ids': np.array([0, 1])
     }, {
         'counts':
         np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]]),
         'ids':
         np.array([0, 1, 2, 3])
     }, {
         'counts': np.array([[0, 1, 2], [3, 4, 5], [12, 13, 14]]),
         'ids': np.array([0, 1, 4])
     }, {
         'counts': np.array([[6, 7, 8], [9, 10, 11]]),
         'ids': np.array([2, 3])
     }, {
         'counts': np.array([[6, 7, 8], [9, 10, 11], [12, 13, 14]]),
         'ids': np.array([2, 3, 4])
     }, {
         'counts': np.array([[12, 13, 14]]),
         'ids': np.array([4])
     }]
     obs = [
         _block_party(counts, rids, cids)
         for rids, cids in _generate_id_blocks(list(range(5)), 2)
     ]
     npt.assert_equal(obs, exp)
Пример #4
0
 def test_block_party_notree(self):
     counts = np.arange(15).reshape(5, 3)
     exp = [{'counts': np.array([[0, 1, 2], [3, 4, 5]]),
             'ids': np.array([0, 1])},
            {'counts': np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8],
                                 [9, 10, 11]]),
             'ids': np.array([0, 1, 2, 3])},
            {'counts': np.array([[0, 1, 2], [3, 4, 5], [12, 13, 14]]),
             'ids': np.array([0, 1, 4])},
            {'counts': np.array([[6, 7, 8], [9, 10, 11]]),
             'ids': np.array([2, 3])},
            {'counts': np.array([[6, 7, 8], [9, 10, 11], [12, 13, 14]]),
             'ids': np.array([2, 3, 4])},
            {'counts': np.array([[12, 13, 14]]), 'ids': np.array([4])}]
     obs = [_block_party(counts, rids, cids) for rids, cids in
            _generate_id_blocks(list(range(5)), 2)]
     npt.assert_equal(obs, exp)