Spatially variable gene (SVG) calling using the SpaNorm model.
Arguments
- spe
a SpatialExperiment or Seurat object, with the count data stored in 'counts' or 'data' assays respectively, and a SpaNorm model fit.
- backend
a character, specifying the backend to use for computations. Options are "auto" (default), "cpu", or "gpu". If "auto", it will use GPU if available, otherwise CPU.
- verbose
a logical, specifying whether to show update messages (default TRUE).
Value
a SpatialExperiment or Seurat object with F-statistics, false discovery rates (FDRs). For SpatialExperiment objects, these are stored in the rowData.
Details
SpaNorm SVG calling works by using the SpaNorm model fit for data normalisation to perform a likelihood ratio test (LRT). The model used for normalisation is considered to be the full model. A second nested model is fit without the splines representing biology. These nested models are then compared using a LRT to identify genes where the splines representing biology contain strong signal.
Examples
library(SpatialExperiment)
library(ggplot2)
data(HumanDLPFC)
HumanDLPFC = SpaNorm(HumanDLPFC, sample.p = 0.05, df.tps = 2, tol = 1e-2)
#> (1/2) Fitting SpaNorm model
#> 201 cells/spots sampled to fit model
#> iter: 1, estimating gene-wise dispersion
#> iter: 1, log-likelihood: -1188651.839051
#> iter: 1, fitting NB model
#> iter: 1, iter: 1, log-likelihood: -1188651.839051
#> iter: 1, iter: 2, log-likelihood: -838534.577238
#> iter: 1, iter: 3, log-likelihood: -746271.504655
#> iter: 1, iter: 4, log-likelihood: -729897.735928
#> iter: 1, iter: 5, log-likelihood: -727408.241156
#> iter: 1, iter: 6, log-likelihood: -727021.233884
#> iter: 1, iter: 7, log-likelihood: -726948.410401
#> iter: 1, iter: 8, log-likelihood: -726929.357994 (converged)
#> iter: 2, estimating gene-wise dispersion
#> iter: 2, log-likelihood: -726617.561752
#> iter: 2, fitting NB model
#> iter: 2, iter: 1, log-likelihood: -726617.561752
#> iter: 2, iter: 2, log-likelihood: -726494.458843
#> iter: 2, iter: 3, log-likelihood: -726488.535634 (converged)
#> iter: 3, log-likelihood: -726488.535634 (converged)
#> (2/2) Normalising data
HumanDLPFC = SpaNormSVG(HumanDLPFC)
#> (1/3) Retrieving SpaNorm model
#> (2/3) Fitting Null SpaNorm model
#> 201 cells/spots sampled to fit model
#> iter: 1, estimating gene-wise dispersion
#> iter: 1, log-likelihood: -1188651.839051
#> iter: 1, fitting NB model
#> iter: 1, iter: 1, log-likelihood: -1188651.839051
#> iter: 1, iter: 2, log-likelihood: -841193.194416
#> iter: 1, iter: 3, log-likelihood: -753597.137719
#> iter: 1, iter: 4, log-likelihood: -738967.675366
#> iter: 1, iter: 5, log-likelihood: -737103.741528
#> iter: 1, iter: 6, log-likelihood: -736936.873876
#> iter: 1, iter: 7, log-likelihood: -736929.062955 (converged)
#> iter: 2, estimating gene-wise dispersion
#> iter: 2, log-likelihood: -736913.063820
#> iter: 2, fitting NB model
#> iter: 2, iter: 1, log-likelihood: -736913.063820
#> iter: 2, iter: 2, log-likelihood: -736907.713985
#> iter: 2, iter: 2, log-likelihood: -736907.713985
#> iter: 2, iter: 2, log-likelihood: -736907.713985
#> iter: 2, iter: 3, log-likelihood: -736907.713985 (converged)
#> iter: 3, log-likelihood: -736907.713985 (converged)
#> (3/3) Finding SVGs
#> 426 SVGs found (FDR < 0.05)
head(rowData(HumanDLPFC))
#> DataFrame with 6 rows and 5 columns
#> gene_name gene_biotype svg.F svg.p svg.fdr
#> <character> <character> <numeric> <numeric> <numeric>
#> ENSG00000188976 NOC2L protein_coding 0.00000 1.000000 1
#> ENSG00000188290 HES4 protein_coding 0.00000 1.000000 1
#> ENSG00000187608 ISG15 protein_coding 0.00000 1.000000 1
#> ENSG00000188157 AGRN protein_coding 1.55474 0.183608 1
#> ENSG00000078808 SDF4 protein_coding 0.00000 1.000000 1
#> ENSG00000176022 B3GALT6 protein_coding 0.00000 1.000000 1