Exemple #1
0
    def test_count_alleles(self):

        hdf5 = VariationsH5(join(TEST_DATA_DIR, '1000snps.hdf5'), mode='r')
        chunk = first(hdf5.iterate_chunks())
        genotypes = chunk['/calls/GT']
        expected = [[3, 3, 0], [5, 1, 0], [0, 2, 4], [6, 0, 0], [2, 3, 1]]
        counts = counts_by_row(genotypes, missing_value=-1)
        assert numpy.all(expected == counts)
        hdf5 = VariationsH5(join(TEST_DATA_DIR, 'ril.hdf5'), mode='r')
        chunks = hdf5.iterate_chunks(kept_fields=['/calls/GT'])
        chunks = (chunk['/calls/GT'] for chunk in chunks)
        matrix = first(chunks)
        for _ in range(20):
            extend_matrix(matrix, chunks)

        counts = counts_by_row(matrix, missing_value=-1)

        gts = [[[-1, -1], [-1, -1], [-1, -1], [0, 0], [0, 0], [0, 0]]]
        gts = numpy.array(gts)
        counts = counts_by_row(gts, missing_value=-1)
        assert numpy.all(counts == [[6]])

        gts = [[[0, 0], [0, 0], [0, 0]], [[0, 0], [0, 0], [0, 0]]]
        gts = numpy.array(gts)
        counts = counts_by_row(gts, missing_value=-1)
        assert numpy.all(counts == [[6, 6]])
    def test_count_alleles(self):

        hdf5 = VariationsH5(join(TEST_DATA_DIR, '1000snps.hdf5'), mode='r')
        chunk = first(hdf5.iterate_chunks())
        genotypes = chunk['/calls/GT']
        expected = [[3, 3, 0],
                    [5, 1, 0],
                    [0, 2, 4],
                    [6, 0, 0],
                    [2, 3, 1]]
        counts = counts_by_row(genotypes, missing_value=-1)
        assert numpy.all(expected == counts)
        hdf5 = VariationsH5(join(TEST_DATA_DIR, 'ril.hdf5'), mode='r')
        chunks = hdf5.iterate_chunks(kept_fields=['/calls/GT'])
        chunks = (chunk['/calls/GT'] for chunk in chunks)
        matrix = first(chunks)
        for _ in range(20):
            extend_matrix(matrix, chunks)

        counts = counts_by_row(matrix, missing_value=-1)

        gts = [[[-1, -1], [-1, -1], [-1, -1], [0, 0], [0, 0], [0, 0]]]
        gts = numpy.array(gts)
        counts = counts_by_row(gts, missing_value=-1)
        assert numpy.all(counts == [[6]])

        gts = [[[0, 0], [0, 0], [0, 0]],
               [[0, 0], [0, 0], [0, 0]]]
        gts = numpy.array(gts)
        counts = counts_by_row(gts, missing_value=-1)
        assert numpy.all(counts == [[6, 6]])
Exemple #3
0
 def test_extend(self):
     mats = [
         numpy.array([[1, 1], [2, 2]]),
         numpy.array([[3, 3], [4, 4]]),
         numpy.array([[5, 5]])
     ]
     expected = ([[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]])
     array = numpy.zeros([1, 2], dtype=numpy.int)
     extend_matrix(array, mats)
     assert numpy.all(array == expected)
Exemple #4
0
 def test_extend(self):
     mats = [numpy.array([[1, 1], [2, 2]]), numpy.array([[3, 3], [4, 4]]),
             numpy.array([[5, 5]])]
     expected = ([[0, 0],
                  [1, 1],
                  [2, 2],
                  [3, 3],
                  [4, 4],
                  [5, 5]])
     array = numpy.zeros([1, 2], dtype=numpy.int)
     extend_matrix(array, mats)
     assert numpy.all(array == expected)