
Helper function to write data to a 10x CellRanger-style h5 file
write_tenx_h5_sc.RdHelper function to write data to a 10x CellRanger-style h5 file
Usage
write_tenx_h5_sc(
f_path,
counts,
barcodes,
features,
version = c("v3", "v2"),
overwrite = TRUE
)Arguments
- f_path
String. Output path.
- counts
Sparse matrix (
dgRMatrixordgCMatrix), cells x features.- barcodes
Character. Cell barcodes, length
nrow(counts).- features
data.table with
idandnameof lengthncol(counts). For v3 may includefeature_type; defaults to"Gene Expression"if absent.- version
One of
"v3"or"v2".- overwrite
Boolean.
Examples
# a CellRanger v3 style h5, ready for load_tenx_h5()
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
)
)
read_tenx_h5_metadata(f_path)$dims
#> obs var
#> 200 40
unlink(f_path)