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 = TRUE,
  streaming = 1L,
  batch_size = 1000L,
  max_genes_in_memory = 2000L,
  cell_batch_size = 100000L,
  .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

Boolean. Shall the .mtx file ingestion itself be streamed (via temp-file bucketing). Recommended for large mtx files. Defaults to TRUE.

streaming

Integer. CSR-to-CSC conversion mode. 0L -> in-memory, 1L -> light streaming, 2L -> heavy streaming with memory upper boundaries. Defaults to 1L.

batch_size

Integer. Cell batch size when streaming = 1L. Defaults to 1000L.

max_genes_in_memory

Integer. Maximum genes held in memory at once when streaming = 2L. Defaults to 2000L.

cell_batch_size

Integer. Cell batch size when streaming = 2L. Defaults to 100000L.

.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
  ),
  streaming = 0L,
  .verbose = FALSE
)
dim(sc)
#> [1] 200  40

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