Skip to contents

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.

Usage

NMFpredict(W, testdat, scale = FALSE, ncell.per.run = 500)

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.

Value

A matrix representing the NMF prediction scores.

Examples

library(googledrive)
drive_deauth() # no Google sign-in is required
drive_download(as_id("14QvmgISxaArTzWt_UHvf55aAYN2zm84Q"), "SKCM_RNASeqV2.geneExp.rds",
                    overwrite = TRUE)
#> File downloaded:
#>SKCM_RNASeqV2.geneExp.rds <id: 14QvmgISxaArTzWt_UHvf55aAYN2zm84Q>
#> Saved locally as:
#>SKCM_RNASeqV2.geneExp.rds
bulkdata <- readRDS("SKCM_RNASeqV2.geneExp.rds")
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)
head(preds[, 1:5])
#>       TCGA-3N-A9WB-06 TCGA-3N-A9WC-06 TCGA-3N-A9WD-06 TCGA-BF-A1PU-01
#> nonSE      0.10378493     0.031103139     0.469932888      0.12913097
#> SE1        0.08326065     0.063022079     0.151414386      0.18470256
#> SE2        0.25368726     0.051110136     0.068248720      0.09710288
#> SE3        0.09417615     0.173416088     0.004969678      0.06966202
#> SE4        0.07931696     0.028829349     0.056418588      0.16008800
#> SE5        0.05088193     0.003203951     0.056310297      0.05303787
#>       TCGA-BF-A1PV-01
#> nonSE      0.10221472
#> SE1        0.05277487
#> SE2        0.05740510
#> SE3        0.15960054
#> SE4        0.12876903
#> SE5        0.12002292