trainNMF: train NMF model

View source: R/trainNMF.R

trainNMFR Documentation

train NMF model

Description

This is the training function used by SPOTLight. This function takes in single cell expression data, trains the model and learns topic profiles for each cell type

Usage

trainNMF(
  x,
  y,
  groups = NULL,
  mgs,
  n_top = NULL,
  gene_id = "gene",
  group_id = "cluster",
  weight_id = "weight",
  hvg = NULL,
  model = c("ns", "std"),
  scale = TRUE,
  verbose = TRUE,
  slot_sc = "counts",
  slot_sp = "counts",
  ...
)

Arguments

x, y

single-cell and mixture dataset, respectively. Can be a numeric matrix or SingleCellExperiment.

groups

character vector of group labels for cells in x. When x is a SingleCellExperiment, defaults to colLabels(x). Make sure groups is not a Factor.

mgs

data.frame or DataFrame of marker genes. Must contain columns holding gene identifiers, group labels and the weight (e.g., logFC, -log(p-value) a feature has in a given group.

n_top

integer scalar specifying the number of markers to select per group. By default NULL uses all the marker genes to initialize the model.

gene_id, group_id, weight_id

character specifying the column in mgs containing gene identifiers, group labels and weights, respectively.

hvg

character vector containing hvg to include in the model. By default NULL.

model

character string indicating which model to use when running NMF. Either "ns" (default) or "std".

scale

logical specifying whether to scale single-cell counts to unit variance. This gives the user the option to normalize the data beforehand as you see fit (CPM, FPKM, ...) when passing a matrix or specifying the slot from where to extract the count data.

verbose

logical. Should information on progress be reported?

slot_sc, slot_sp

If the object is of class SingleCellExperiment indicates matrix to use. By default "counts".

...

additional parameters.

Value

base a list where the first element is an NMFfit object and the second is a matrix containing the topic profiles learnt.

Author(s)

Marc Elosua Bayes & Helena L Crowell

Examples

set.seed(321)
# mock up some single-cell, mixture & marker data
sce <- mockSC(ng = 200, nc = 10, nt = 3)
spe <- mockSP(sce)
mgs <- getMGS(sce)

res <- trainNMF(
    x = sce,
    y = spe,
    groups = sce$type,
    mgs = mgs,
    weight_id = "weight",
    group_id = "type",
    gene_id = "gene")
# Get NMF model
res[["mod"]]
# Get topic profiles
res[["topic"]]

MarcElosua/SPOTlight documentation built on March 7, 2024, 4:58 p.m.