Conducts hypothesis testing to identify spatially variable genes (SVGs) using an adaptive multi-kernel approach, and provides Effective Spatial Variability (ESV) scores (ranging from 0 to 1), where higher values indicate greater spatial variability in gene expression.
Usage
spacelink(
normalized_counts,
spatial_coords,
covariates = NULL,
lite = FALSE,
grid_size = NULL,
kernel = "Exponential",
n_lengthscales = 5,
n_workers = 1
)Arguments
- normalized_counts
Normalized count matrix (genes x spots). Accepts a numeric matrix, data.frame, or sparse matrix (
sparseMatrix).- spatial_coords
Two-dimensional spatial coordinate matrix (spots x 2). Accepts a numeric matrix or data.frame.
- covariates
Optional covariate matrix (spots x covariates, without intercept). Accepts a numeric vector, matrix, or data.frame. Default is
NULL.- lite
Logical. If
TRUE, uses a grid-based approximation to speed up computation for large datasets. Default isFALSE.- grid_size
Grid cell size for lite mode. If
NULL, set automatically to 5 times the minimum nearest-neighbor distance. Default isNULL.- kernel
Spatial kernel type. One of
"Exponential"(default) or"Gaussian".- n_lengthscales
Number of length scales (kernels). Default is 5.
- n_workers
Number of workers for parallelization. Default is 1.
Value
A data frame (genes x results) containing:
- tau.sq
Nugget variance component
- sigma.sq1, sigma.sq2, ...
Spatial variance components for each kernel
- phi1, phi2, ...
Inverse length scales for each kernel
- ESV
Effective Spatial Variability score
- pval1, pval2, ...
Score test p-values for each kernel
- pval
Combined p-value (ACAT)
- padj
Benjamini-Hochberg adjusted p-value
- ESV_adj
ESV adjusted for non-SVGs (0 if padj > 0.05)
- time
Computation time per gene (seconds)
Examples
# \donttest{
library(spacelink)
set.seed(123)
n_spots <- 100
n_genes <- 10
coords <- expand.grid(
x = seq(0, 10, length.out = sqrt(n_spots)),
y = seq(0, 10, length.out = sqrt(n_spots))
)
expr_data <- matrix(nrow = n_genes, ncol = n_spots)
rownames(expr_data) <- paste0("Gene_", 1:n_genes)
D <- as.matrix(dist(coords))
K <- exp(-D / 2); chol_K <- chol(K)
for (i in 1:(n_genes / 2)) {
expr_data[i, ] <- rnorm(n_spots) + i * rnorm(n_spots) %*% chol_K
}
for (i in (n_genes / 2 + 1):n_genes) {
expr_data[i, ] <- rnorm(n_spots)
}
results <- spacelink(normalized_counts = expr_data, spatial_coords = coords)
print(results[, c("ESV", "pval", "padj")])
#> ESV pval padj
#> Gene_1 0.36240416 1.316941e-02 2.633882e-02
#> Gene_2 0.67450493 1.641875e-05 5.472917e-05
#> Gene_3 0.63469294 2.190094e-04 5.475235e-04
#> Gene_4 0.67450493 1.096747e-06 5.483735e-06
#> Gene_5 0.67450493 2.671183e-08 2.671183e-07
#> Gene_6 0.00000000 7.483181e-01 8.645015e-01
#> Gene_7 0.00000000 8.050144e-01 8.645015e-01
#> Gene_8 0.06886313 3.269677e-01 5.449462e-01
#> Gene_9 0.00000000 8.351624e-01 8.645015e-01
#> Gene_10 0.00000000 8.645015e-01 8.645015e-01
# }