This function uses pretrained NMF models to recover cell states / spatial ecotypes. It takes a factorization matrix W representing a pretrained NMF model and a numeric gene expression matrix.
Arguments
- W
Matrix representing the factorization matrix W of a pretrained NMF model.
- testdat
Numeric matrix containing the new data for which NMF scores are to be predicted.
- scale
Logical indicating whether to scale the input data.
- ncell.per.run
Integer specifying the maximum number of cells per NMF prediction run to avoid memory issues.
- sum2one
Logical. If `TRUE`, normalizes the predicted scores so that they sum to 1 for each sample.
- ncores
Integer specifying the number of CPU cores to use for parallel processing.
Value
A matrix representing the NMF prediction scores, with rows as samples/cells and columns as SE groups.
Examples
library(data.table)
library(SpatialEcoTyper)
bulkdata <- fread("https://spatialecotyper.stanford.edu/inc/inc.public.vignettes.php?file=SKCM_RNASeqV2.geneExp.tsv",
sep = "\t", header = TRUE, data.table = FALSE)
#> Warning: URL 'https://spatialecotyper.stanford.edu/inc/inc.public.vignettes.php?file=SKCM_RNASeqV2.geneExp.tsv': Timeout of 60 seconds was reached
#> Error in download.file(file, tmpFile, method = method, mode = "wb", quiet = !showProgress): download from 'https://spatialecotyper.stanford.edu/inc/inc.public.vignettes.php?file=SKCM_RNASeqV2.geneExp.tsv' failed
rownames(bulkdata) = bulkdata[, 1]
#> Error in eval(expr, envir, enclos): object 'bulkdata' not found
bulkdata = as.matrix(bulkdata[, -1])
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'as.matrix': object 'bulkdata' not found
W <- readRDS(file.path(system.file("extdata", package = "SpatialEcoTyper"), "Bulk_SE_Recovery_W.rds"))
# Predict SE abundances in bulk tumors
preds <- NMFpredict(W = W, bulkdata, scale = TRUE)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'colSums': object 'bulkdata' not found
head(preds[, 1:5])
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'head': object 'preds' not found
