-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscutils.R
More file actions
21 lines (19 loc) · 798 Bytes
/
scutils.R
File metadata and controls
21 lines (19 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#' Utils for analyzing single cell RNA-Seq dataset
#' read output_filtered.h5 produced by CellBender
#' return a sparseMatrix of counts (rows: features; columns, barcodes)
read_cellbender_h5 <- function(path_h5){
cb_h5 <- H5File$new(path_h5, mode = 'r')
# when creating sparseMatrix, parameter `i` is 1-based. That's why the `+1`.
# For a sparse matrix, index slot (`m@i` or `h5[["matrix/indices"]]`) is 0-based.
m <- Matrix::sparseMatrix(
i = cb_h5[["matrix/indices"]][] + 1,
p = cb_h5[["matrix/indptr"]][],
x = cb_h5[["matrix/data"]][],
dims = cb_h5[["matrix/shape"]][][],
dimnames = list(
cb_h5[["matrix/features/name"]][],
cb_h5[["matrix/barcodes"]][]),
repr = "C")
cb_h5$close_all()
return(m)
}