Skip to contents

This is a helper function to load in mtx files and corresponding plain text files. It will automatically filter out low quality cells and only keep high quality cells. Under the hood DucKDB and high performance Rust binary files are being used to store the counts.

Usage

load_mtx(
  object,
  sc_mtx_io_param = params_sc_mtx_io(),
  sc_qc_param = params_sc_min_quality(),
  mtx_streaming = deprecated(),
  csc_mem_gb = NULL,
  streaming = deprecated(),
  batch_size = deprecated(),
  max_genes_in_memory = deprecated(),
  cell_batch_size = deprecated(),
  .verbose = TRUE
)

Arguments

object

SingleCells class.

sc_mtx_io_param

List. Please generate this one via params_sc_mtx_io().

sc_qc_param

List. Output of params_sc_min_quality().

mtx_streaming

No longer has an effect: the .mtx file is always read in a single pass with its entries bucketed on disk next to the store. Ignored. [Deprecated]

csc_mem_gb

Optional numeric. Memory in GB for the buffers of the cell-to-gene (CSR to CSC) conversion, at 10 bytes per non-zero. NULL (default) converts in one pass and holds the whole matrix. Set a cap for large data sets; every extra phase re-reads the cell file once.

streaming, batch_size, max_genes_in_memory, cell_batch_size

Replaced by csc_mem_gb and ignored. [Deprecated]

.verbose

Boolean.

Value

The class with updated shape information.

Examples

# read back a CellRanger style .mtx trio
data <- generate_single_cell_test_data(
  syn_data_params = params_sc_synthetic_data(n_cells = 200L, n_genes = 40L)
)
dir_src <- tempfile("cellranger")
dir.create(dir_src, recursive = TRUE)
write_cellranger_output(
  dir_src, data$counts, data$obs, data$var,
  rows = "cells", format_type = "csv", .verbose = FALSE
)

dir_data <- tempfile("sc_mtx")
dir.create(dir_data, recursive = TRUE)
sc <- load_mtx(
  object = SingleCells(dir_data = dir_data),
  sc_mtx_io_param = params_sc_mtx_io(
    path_mtx = file.path(dir_src, "matrix.mtx"),
    path_obs = file.path(dir_src, "barcodes.csv"),
    path_var = file.path(dir_src, "features.csv"),
    cells_as_rows = TRUE,
    has_hdr = TRUE
  ),
  sc_qc_param = params_sc_min_quality(
    min_unique_genes = 5L,
    min_lib_size = 25L,
    min_cells = 5L
  ),
  .verbose = FALSE
)
dim(sc)
#> [1] 200  40

unlink(c(dir_src, dir_data), recursive = TRUE, force = TRUE)