Skip to contents

Runs a single HALS NMF on a chosen subset of cells and genes. For SingleCells, the counts are streamed from disk via the Rust binary files; for MetaCells, the in-memory sparse counts are used.

Usage

nmf_sc(
  object,
  k,
  cell_ids = NULL,
  gene_ids = NULL,
  preprocessing = "none",
  use_second_layer = TRUE,
  nmf_hals_params = params_nmf_hals(),
  seed = 42L,
  .verbose = TRUE
)

Arguments

object

SingleCells or MetaCells class.

k

Integer. Number of latent factors to return.

cell_ids

Optional character. Cell ids (or meta cell ids) to restrict the NMF to. If NULL, uses get_cells_to_keep() for SingleCells and all meta cells for MetaCells.

gene_ids

Optional character. Gene ids to restrict the NMF to. If NULL, uses get_hvg() on the object.

preprocessing

String. One of c("none", "sd", "sqrt_sd").

use_second_layer

Boolean. If TRUE, runs NMF on the normalised counts (recommended); if FALSE, on the raw counts.

nmf_hals_params

List, see params_nmf_hals().

seed

Integer. Random seed for initialisation.

.verbose

Boolean or integer. Verbosity.

Value

An NmfResult object.

Examples

# three factors on the highly variable genes
sc <- demo_single_cells()
res <- nmf_sc(sc, k = 3L, .verbose = FALSE)
res
#> NmfResult (single-run HALS NMF)
#>   Source class:     SingleCells
#>   No genes:         30
#>   No cells:         500
#>   No components:    3
#>   Final loss:       5.941e+04
#>   Iterations:       40
#>   Converged:        TRUE
#>   Preprocessing:    none

unlink(sc@dir_data, recursive = TRUE, force = TRUE)