runSVGsGpGp: runSVGsGpGp

Description Usage Arguments Details Value Examples

View source: R/runSVGsGpGp.R

Description

Run method to identify spatially variable genes (SVGs) using GpGp.

Usage

1
2
3
4
5
6
7
8
9
runSVGsGpGp(
  spe,
  x = NULL,
  fix_param_range = NULL,
  n_neighbors = 15,
  lr_test = TRUE,
  n_threads = 1,
  verbose = FALSE
)

Arguments

spe

SpatialExperiment Input object, assumed to be a SpatialExperiment containing an assay named logcounts and spatial coordinates accessible with spatialCoords().

x

numeric matrix Matrix of covariates, with number of rows (spots) matching the number of columns (spots) in spe. Default = NULL, which specifies an intercept-only model. See GpGp documentation for details.

fix_param_range

numeric Whether to use a fixed parameter value for 'range' covariance function parameter in 'exponential_isotropic' covariance function (corresponding to 'phi' in other parameterizations). For example, set to 0.5 to fix the parameter to this value. Default = NULL, which will estimate the parameter. See GpGp documentation for details.

n_neighbors

numeric Number of nearest neighbors. See GpGp documentation for details.

lr_test

logical Whether to return log likelihoods and calculate likelihood ratio tests compared to the null model without spatial terms. If TRUE, will calculate log likelihoods for the null models, calculate likelihood ratio tests using the asymptotic chi-squared distribution with 2 degrees of freedom, and calculate adjusted p-values using the Benjamini-Hochberg method. Default = TRUE.

n_threads

integer Number of threads for parallelization. Default = 1.

verbose

logical Whether to display verbose output from GpGp. Default = FALSE.

Details

Run method to identify spatially variable genes (SVGs) using GpGp (Guinness 2018).

This function runs GpGp separately for each gene, using parallelization for faster runtime using one core per GpGp run. The main outputs of interest are the covariance parameter estimates stored in 'covparms' in the GpGp output (for the 'exponential_isotropic' covariance function these are: variance, range, nugget). Optionally, the 'range' parameter (parameterized as 'phi' in other methods) can be fixed to a user-specified value, so that this parameter is the same for all genes. We also use the log-likelihood ('loglik' in GpGp output) to calculate likelihood ratio tests.

Note the parameterization used by GpGp: total variance = sigmasq + (tausq * sigmasq); i.e. the nugget is 'tausq * sigmasq', not 'tausq' itself as in many other methods.

Assumes the input object is a SpatialExperiment containing an assay named logcounts, which has been filtered to exclude very low-expressed genes, e.g. as prepared with preprocessSVGs.

Value

Returns output values stored as new columns in rowData in the spe SpatialExperiment object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
library(SpatialExperiment)
library(STexampleData)
library(spatzli)

spe <- Visium_humanDLPFC()

spe <- preprocessSVGs(spe)

# subset 1 gene
spe_1 <- spe[1, ]
system.time({
  spe_1 <- runSVGsGpGp(spe_1, verbose = TRUE)
})

# subset 100 genes and use parallelization
# spe_100 <- spe[1:100, ]
# spe_100 <- runSVGsGpGp(spe_100, n_threads = 4)

lmweber/spatzli documentation built on Feb. 2, 2022, 1:09 p.m.