matrix.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:cellranger 作者: 10XGenomics 项目源码 文件源码
def load_chunk(group, col_start, col_end):
        ''' Load a submatrix specified by the given column (barcode) range from an h5 group
        Args: col_start, col_end - half-open interval of column indices to load'''
        # Check bounds
        shape = getattr(group, cr_constants.H5_MATRIX_SHAPE_ATTR).read()
        assert col_start >= 0 and col_start < shape[1]
        assert col_end >= 0 and col_end <= shape[1]

        # Load genes and barcodes
        genes = GeneBCMatrix.load_genes_from_h5_group(group)
        bcs = GeneBCMatrix.load_bcs_from_h5_group(group)[col_start:col_end]
        matrix = GeneBCMatrix(genes, bcs)

        # Get views into full matrix
        data = getattr(group, cr_constants.H5_MATRIX_DATA_ATTR)
        indices = getattr(group, cr_constants.H5_MATRIX_INDICES_ATTR)
        indptr = getattr(group, cr_constants.H5_MATRIX_INDPTR_ATTR)

        # Determine extents of selected columns
        ind_start = indptr[col_start]
        if col_end < len(indptr)-1:
            # Last index (end-exclusive) is the start of the next column
            ind_end = indptr[col_end]
        else:
            # Last index is the last index in the matrix
            ind_end = len(data)

        chunk_data = data[ind_start:ind_end]
        chunk_indices = indices[ind_start:ind_end]
        chunk_indptr = np.append(indptr[col_start:col_end], ind_end) - ind_start
        chunk_shape = (shape[0], col_end - col_start)

        matrix.m = sp_sparse.csc_matrix((chunk_data, chunk_indices, chunk_indptr), shape=chunk_shape)

        return matrix
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号