SpaNormPCA

GLM-based (SpaNorm) PCA

Description

GLM-based PCA using the SpaNorm model. The null model is considered to consist of the library size effects, batch effects, and the gene mean. GLM-PCA is approximated by regressing the null model from the data, and performing PCA on the residuals (Pearson or deviance).

Usage

SpaNormPCA(
  spe,
  nsvgs = 3000,
  ncomponents = 50,
  svg.fdr = 1,
  BSPARAM = bsparam(),
  BPPARAM = SerialParam(),
  residuals = c("deviance", "pearson"),
  name = "PCA"
)

## S4 method for signature 'SpatialExperiment'
SpaNormPCA(
  spe,
  nsvgs = 3000,
  ncomponents = 50,
  svg.fdr = 1,
  BSPARAM = bsparam(),
  BPPARAM = SerialParam(),
  residuals = c("deviance", "pearson"),
  name = "PCA"
)

## S4 method for signature 'Seurat'
SpaNormPCA(
  spe,
  nsvgs = 3000,
  ncomponents = 50,
  svg.fdr = 1,
  BSPARAM = bsparam(),
  BPPARAM = SerialParam(),
  residuals = c("deviance", "pearson"),
  name = "PCA"
)

Arguments

spe a SpatialExperiment or Seurat object, with the count data stored in ‘counts’ or ‘data’ assays respectively, and a SpaNorm model fit.
nsvgs the number of SVGs to use for PCA.
ncomponents the number of components to compute.
svg.fdr the FDR threshold for SVG calling.
BSPARAM a BiocSingularParam object specifying which algorithm should be used to perform the PCA.
BPPARAM a BiocParallelParam object specifying whether the PCA should be parallelized.
residuals the type of residuals to use for PCA. Either "deviance" (default) or "pearson".
name the name of the reducedDim to store the PCA results.

Details

SpaNorm PCA works by using the SpaNorm model fit for data normalisation to approximate a GLM-based PCA as described in Townes et al. (Genome Biology, 2019). The model used for normalisation represents the library size effects and the gene mean. Regressing these covariates, we remain with the deviance or Pearson residuals, upon which PCA can be performed to approximate the GLM-PCA.

Value

a SpatialExperiment or Seurat object with PCA results. For SpatialExperiment objects, these are stored in the reducedDims.

Examples

Note

The code below runs when the site is built, on a small pre-fitted subset of HumanDLPFC (301 genes x 4015 spots; SpaNorm(sample.p = 0.05, df.tps = 2), SpaNormSVG() and SpaNormPCA() already applied) that is fitted once per build. The outputs are those of the code shown.

library("SpaNorm")


library(SpatialExperiment)
library(ggplot2)

data(HumanDLPFC)

HumanDLPFC = SpaNorm(HumanDLPFC, sample.p = 0.05, df.tps = 2, tol = 1e-2)
(1/2) Retrieve precomputed SpaNorm model
(2/2) Normalising data
HumanDLPFC = SpaNormSVG(HumanDLPFC)
(1/3) Retrieving SpaNorm model
(2/3) Retrieving Null SpaNorm model
(3/3) Finding SVGs
102 SVGs found (FDR < 0.05)
HumanDLPFC = SpaNormPCA(HumanDLPFC)
reducedDims(HumanDLPFC)
List of length 1
names(1): PCA