MyNixOS website logo
Description

Spatially Variable Genes Detection Methods for Spatial Transcriptomics.

A unified framework for detecting spatially variable genes (SVGs) in spatial transcriptomics data. This package integrates multiple state-of-the-art SVG detection methods including 'MERINGUE' (Moran's I based spatial autocorrelation), 'Giotto' binSpect (binary spatial enrichment test), 'SPARK-X' (non-parametric kernel-based test), and 'nnSVG' (nearest-neighbor Gaussian processes). Each method is implemented with optimized performance through vectorization, parallelization, and 'C++' acceleration where applicable. Methods are described in Miller et al. (2021) <doi:10.1101/gr.271288.120>, Dries et al. (2021) <doi:10.1186/s13059-021-02286-2>, Zhu et al. (2021) <doi:10.1186/s13059-021-02404-0>, and Weber et al. (2023) <doi:10.1038/s41467-023-39748-z>.

SVG: Spatially Variable Genes Detection Methods

R-CMD-check R-universe License: MIT Documentation

A unified R package for detecting spatially variable genes (SVGs) in spatial transcriptomics data, integrating multiple state-of-the-art methods with optimized performance.

📚 Documentation: https://zaoqu-liu.github.io/SVG/

Overview

SVG detection is a fundamental step in spatial transcriptomics analysis, identifying genes whose expression patterns exhibit significant spatial structure. This package provides:

  • Four SVG detection methods with a unified interface
  • Optimized implementations with C++ acceleration
  • Comprehensive documentation with scientific details
  • Flexible parameters for method customization

Installation

From R-Universe (Recommended)

# Install from R-Universe
install.packages("SVG", repos = "https://zaoqu-liu.r-universe.dev")

From GitHub

# Install from GitHub
devtools::install_github("Zaoqu-Liu/SVG")

# Or install with dependencies
devtools::install_github("Zaoqu-Liu/SVG", dependencies = TRUE)

From Bioconductor (Coming Soon)

# Install from Bioconductor (after acceptance)
BiocManager::install("SVG")

Dependencies

Core dependencies (automatically installed):

  • Matrix, Rcpp, RcppArmadillo

Optional dependencies for specific methods:

# For Delaunay triangulation
install.packages("geometry")

# For KNN network
install.packages("RANN")

# For nnSVG method (required)
install.packages("BRISC")

# For accurate p-values
install.packages("CompQuadForm")

Quick Start

library(SVG)

# Load your data
# expr_matrix: genes x spots (rows x columns)
# spatial_coords: spots x coordinates (x, y)

# Unified interface
results <- CalSVG(expr_matrix, spatial_coords, method = "meringue")

# Or use method-specific functions
results_meringue <- CalSVG_MERINGUE(expr_matrix, spatial_coords)
results_binspect <- CalSVG_binSpect(expr_matrix, spatial_coords)
results_sparkx <- CalSVG_SPARKX(expr_matrix, spatial_coords)
results_nnsvg <- CalSVG_nnSVG(expr_matrix, spatial_coords)

# Get significant SVGs
sig_genes <- results$gene[results$p.adj < 0.05]

Methods

1. MERINGUE (Moran's I with Network)

Spatial autocorrelation using Moran's I with binary adjacency network.

results <- CalSVG_MERINGUE(
    expr_matrix,
    spatial_coords,
    network_method = "delaunay",  # or "knn"
    k = 10,                       # neighbors for KNN
    alternative = "greater",      # test for clustering
    adjust_method = "BH"
)

Best for: General SVG detection with explicit spatial network

2. Seurat (Moran's I with Distance Weights)

Moran's I using inverse distance squared weights (Seurat default).

results <- CalSVG_Seurat(
    expr_matrix,
    spatial_coords,
    weight_scheme = "inverse_squared",  # 1/d^2 (default)
    adjust_method = "BH"
)

Best for: Compatible with Seurat workflow, continuous distance weighting

3. binSpect (Giotto)

Binary spatial enrichment test using Fisher's exact test.

results <- CalSVG_binSpect(
    expr_matrix,
    spatial_coords,
    bin_method = "kmeans",   # or "rank"
    rank_percent = 30,       # for rank method
    do_fisher_test = TRUE
)

Best for: Fast computation, robust to outliers

4. SPARK-X

Non-parametric kernel-based test using multiple spatial kernels.

results <- CalSVG_SPARKX(
    expr_matrix,
    spatial_coords,
    kernel_option = "mixture",  # or "single"
    n_threads = 4
)

Best for: Large datasets, diverse pattern types

5. nnSVG

Nearest-neighbor Gaussian processes for spatial modeling.

results <- CalSVG_nnSVG(
    expr_matrix,
    spatial_coords,
    n_neighbors = 10,
    cov_model = "exponential",
    n_threads = 4
)

Best for: Statistical rigor, effect size estimation

6. Mark Variogram

Spatial pattern detection using mark variogram from spatstat.

results <- CalSVG_MarkVario(
    expr_matrix,
    spatial_coords,
    r_metric = 5,       # distance to evaluate variogram
    normalize = TRUE
)

Best for: Different perspective on spatial patterns

Method Comparison

MethodPrincipleSpeedScalabilityEffect Size
MERINGUEMoran's I (network)FastMediumModerate
SeuratMoran's I (1/d²)FastMediumModerate
binSpectFisher testVery FastHighOdds ratio
SPARK-XKernel testFastVery HighNo
nnSVGGaussian processSlowMediumYes (prop_sv)
MarkVarioVariogramModerateMediumVariogram value

Output Columns

All methods return a data.frame with unified column names:

ColumnDescription
geneGene identifier
p.valueRaw p-value
p.adjAdjusted p-value (BH/FDR)

Method-specific columns:

MethodAdditional Columns
MERINGUEobserved, expected, sd, z_score
Seuratobserved, expected, sd, rank
binSpectestimate (odds ratio), score
SPARK-Xstat_*, pval_* (per kernel)
nnSVGsigma.sq, tau.sq, phi, prop_sv, LR_stat
MarkVarior.metric.value, rank (no p-values)

Tutorials

TutorialDescription
IntroductionComplete guide with all methods, benchmarks, and visualizations

Examples

Basic Workflow

library(SVG)

# Simulate data
set.seed(42)
n_spots <- 500
n_genes <- 100

# Expression matrix (genes x spots)
expr <- matrix(rpois(n_genes * n_spots, lambda = 10), 
               nrow = n_genes)
rownames(expr) <- paste0("gene_", 1:n_genes)
colnames(expr) <- paste0("spot_", 1:n_spots)

# Add spatial pattern to first 10 genes
coords <- cbind(x = runif(n_spots, 0, 100),
                y = runif(n_spots, 0, 100))
rownames(coords) <- colnames(expr)

# Create spatial gradient for first genes
for (i in 1:10) {
    expr[i, ] <- expr[i, ] + round(coords[, 1] / 10)
}

# Run SVG detection
results <- CalSVG(expr, coords, method = "meringue")

# Top SVGs
head(results)

# Significant genes
sig_genes <- results$gene[results$p.adj < 0.05]
print(sig_genes)

Integration with SpatialExperiment

library(SpatialExperiment)
library(SVG)

# From SpatialExperiment object
spe <- readRDS("your_spe.rds")

expr_matrix <- as.matrix(logcounts(spe))
spatial_coords <- spatialCoords(spe)

results <- CalSVG(expr_matrix, spatial_coords, method = "meringue")

Parallel Processing

# Use multiple cores for faster computation
results <- CalSVG(
    expr_matrix, spatial_coords,
    method = "sparkx",
    n_threads = parallel::detectCores() - 1
)

Citation

If you use this package, please cite:

Liu Z. (2024). SVG: Spatially Variable Genes Detection Methods. 
R package version 1.0.0. https://github.com/Zaoqu-Liu/SVG

And cite the original method papers:

  • MERINGUE: Miller et al. (2021) Genome Research
  • binSpect: Dries et al. (2021) Genome Biology
  • SPARK-X: Zhu et al. (2021) Genome Biology
  • nnSVG: Weber et al. (2023) Nature Communications

License

MIT License

Author

Zaoqu Liu
Chinese Academy of Medical Sciences and Peking Union Medical College
Email: [email protected]
ORCID: 0000-0002-0452-742X

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

See Also

  • Giotto - Spatial transcriptomics analysis suite
  • MERINGUE - Original MERINGUE package
  • SPARK - Original SPARK/SPARK-X package
  • nnSVG - Original nnSVG package.
Metadata

Version

1.0.0

License

Unknown

Platforms (78)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows