
Load in a 10x CellRanger h5 file to SingleCells
load_tenx_h5.RdLoads the gene-expression modality from a CellRanger v2/v3 h5 file. The
counts go into the Rust-binarised format (with log normalisation applied on
read) and the barcodes/features into the DuckDB. Non-gene modalities (e.g.
Antibody Capture) are filtered out via feature_type.
Usage
load_tenx_h5(
object,
h5_path,
sc_qc_param = params_sc_min_quality(),
feature_type = "Gene Expression",
streaming = 1L,
batch_size = 1000L,
max_genes_in_memory = 2000L,
cell_batch_size = 100000L,
.verbose = TRUE
)Arguments
- object
SingleCellsclass.- h5_path
File path to the 10x h5 file.
- sc_qc_param
List. Output of
params_sc_min_quality().- feature_type
String. Modality to keep. Defaults to
"Gene Expression". Ignored for v2 (single modality).- streaming
Integer. CSR-to-CSC conversion mode.
0L-> in-memory,1L-> light streaming,2L-> heavy streaming. Defaults to1L.- batch_size
Integer. Cell batch size when
streaming = 1L. Defaults to1000L.- max_genes_in_memory
Integer. Maximum genes held in memory at once when
streaming = 2L. Defaults to2000L.- cell_batch_size
Integer. Cell batch size when
streaming = 2L. Defaults to100000L.- .verbose
Boolean.
Examples
# read back a CellRanger v3 h5, gene expression only
data <- generate_single_cell_test_data(
syn_data_params = params_sc_synthetic_data(n_cells = 200L, n_genes = 40L)
)
f_path <- tempfile(fileext = ".h5")
write_tenx_h5_sc(
f_path = f_path,
counts = data$counts,
barcodes = data$obs$cell_id,
features = data.table::data.table(
id = data$var$gene_id,
name = data$var$ensembl_id,
feature_type = "Gene Expression"
)
)
dir_data <- tempfile("sc_tenx")
dir.create(dir_data, recursive = TRUE)
sc <- load_tenx_h5(
object = SingleCells(dir_data = dir_data),
h5_path = f_path,
sc_qc_param = params_sc_min_quality(
min_unique_genes = 5L,
min_lib_size = 25L,
min_cells = 5L
),
streaming = 0L,
.verbose = FALSE
)
dim(sc)
#> [1] 200 40
unlink(c(f_path, dir_data), recursive = TRUE, force = TRUE)