Esempio n. 1
0
 def test_take(self):
     a = np.rec.array(variant_table_data, dtype=variant_table_dtype)
     vt = VariantChunkedTable(a)
     # take variants not in original order
     # not supported for carrays
     indices = [2, 0]
     with assert_raises(NotImplementedError):
         vt.take(indices)
Esempio n. 2
0
    def test_slice_types(self):
        ra = np.rec.array(variant_table_data, dtype=variant_table_dtype)
        vt = VariantChunkedTable(ra)

        # row slice
        s = vt[1:]
        self.assertNotIsInstance(s, VariantChunkedTable)
        self.assertIsInstance(s, VariantTable)

        # row index
        s = vt[0]
        self.assertNotIsInstance(s, VariantChunkedTable)
        self.assertNotIsInstance(s, VariantTable)
        self.assertIsInstance(s, (np.record, np.void, tuple))

        # col access
        s = vt['CHROM']
        self.assertNotIsInstance(s, VariantChunkedTable)
        self.assertNotIsInstance(s, VariantTable)
        self.assertIsInstance(s, chunked.ChunkedArrayWrapper)

        # bad access
        with assert_raises(IndexError):
            # noinspection PyStatementEffect
            vt[:, 0]
Esempio n. 3
0
    def test_constructor(self):

        # missing data arg
        with self.assertRaises(TypeError):
            # noinspection PyArgumentList
            VariantChunkedTable()

        # recarray
        ra = np.rec.array(variant_table_data, dtype=variant_table_dtype)
        vt = VariantChunkedTable(ra)
        eq(5, len(vt))
        aeq(ra, vt)

        # dict
        d = {n: ra[n] for n in variant_table_names}
        vt = VariantChunkedTable(d, names=variant_table_names)
        eq(5, len(vt))
        aeq(ra, vt)
Esempio n. 4
0
    def test_hdf5_to_zarr(self):
        # https://github.com/cggh/scikit-allel/issues/353
        chrom = [b'chr1', b'chr1', b'chr2', b'chr2', b'chr3']
        pos = [2, 7, 3, 9, 6]
        dp = [35, 12, 78, 22, 99]
        qd = [4.5, 6.7, 1.2, 4.4, 2.8]
        ac = [(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]
        with h5py.File('callset.h5', mode='w') as h5f:
            h5g = h5f.create_group('/3L/variants')
            h5g.create_dataset('CHROM', data=chrom, chunks=True)
            h5g.create_dataset('POS', data=pos, chunks=True)
            h5g.create_dataset('DP', data=dp, chunks=True)
            h5g.create_dataset('QD', data=qd, chunks=True)
            h5g.create_dataset('AC', data=ac, chunks=True)

        callset = h5py.File('callset.h5', mode='r')
        vt = VariantChunkedTable(callset['/3L/variants'],
                                 names=['CHROM', 'POS', 'AC', 'QD', 'DP'])
        vs = vt.eval('DP > 15')[:]
        v = vt.compress(vs, axis=0)
        assert isinstance(v, VariantChunkedTable)
        assert isinstance(v.values, ZarrTable)
Esempio n. 5
0
 def test_zarr_group(self):
     z = zarr.group()
     z.create_dataset('chrom', data=['1', '2', '3'])
     z.create_dataset('pos', data=[2, 4, 6])
     vt = VariantChunkedTable(z)
     assert isinstance(vt.values, zarr.Group)
Esempio n. 6
0
 def setup_instance(self, data, **kwargs):
     data = chunked.storage_registry['default'].table(data)
     return VariantChunkedTable(data, **kwargs)