library(SpatialExperiment)
library(nnSVG)
# Filter low-expressed and mitochondrial genes
spe <- filter_genes(spe)
# Calculate logcounts using library size factors
spe <- computeLibraryFactors(spe)
spe <- logNormCounts(spe)
# Run nnSVG to identify spatially variable genes
spe <- nnSVG(spe)
Input: A SpatialExperiment object containing raw counts and spatial coordinates.
Output: A SpatialExperiment object with SVG ranking and statistics stored in rowData.
1---2name: nnsvg3description: nnSVG4---56# nnSVG78## Workflows910### Standard Workflow1112```r13library(SpatialExperiment)14library(nnSVG)1516# Filter low-expressed and mitochondrial genes17spe <- filter_genes(spe)1819# Calculate logcounts using library size factors20spe <- computeLibraryFactors(spe)21spe <- logNormCounts(spe)2223# Run nnSVG to identify spatially variable genes24spe <- nnSVG(spe)25```26Input: A `SpatialExperiment` object containing raw counts and spatial coordinates.27Output: A `SpatialExperiment` object with SVG ranking and statistics stored in `rowData`.2829## When to Use30- Identifying spatially variable genes (SVGs) in spatially-resolved transcriptomics datasets (e.g., Visium, Slide-seq).31- Identifying SVGs within spatial domains or cell types by incorporating covariates using the `X` parameter in `nnSVG`.32- Scaling SVG identification to large datasets with thousands of spatial locations.3334## When NOT to Use35- For non-spatial single-cell RNA-seq data, use standard highly variable gene (HVG) selection in `scran` or `Seurat`.36- For simple differential expression between pre-defined clusters without spatial modeling, use `findMarkers` from `scran`.3738## Data Requirements39- A `SpatialExperiment` object containing a `counts` assay and spatial coordinates (accessible via `spatialCoords`).40- Alternatively, a numeric matrix of log-transformed normalized counts and a matrix of spatial coordinates.4142## Key Parameters43- **X** (NULL): A model matrix of covariates (e.g., cell types or spatial domains) to include in the model.44- **filter_genes_ncounts** (3): Minimum number of counts for gene filtering in `filter_genes`.45- **filter_genes_pcspots** (0.5): Minimum percentage of spots with counts for gene filtering in `filter_genes`.46- **filter_mito** (TRUE): Whether to filter out mitochondrial genes in `filter_genes`.4748## Best Practices49- Filter out low-expressed genes using `filter_genes` before running `nnSVG` to avoid errors and reduce runtime.50- Re-calculate library size factors and log-normalized counts after filtering genes.51- For multi-sample datasets, run `nnSVG` individually per sample and combine results by averaging ranks.5253## Common Pitfalls54- Running `nnSVG` on rows (genes) or columns (spots) containing all zero counts; ensure proper filtering using `filter_genes` or manual subsetting.55- Empty levels in factor covariates when creating the design matrix; use `droplevels()` to remove them.5657## Alternatives58- `SpatialDE` for spatial variable gene identification.59- `Spark` / `SPARK-G` for statistical modeling of SVGs.60- `scran` for non-spatial highly variable gene selection.6162## Citations63- Weber and Hicks 2026 (or Weber et al., Nature Communications)64- Datta et al., 2016 (Nearest-neighbor Gaussian processes)65- Saha and Datta, 2018 (BRISC algorithm)6667## References68- Homepage: bioconductor.org/packages/nnSVG69- Vignette: https://bioconductor.org/packages/release/bioc/vignettes/nnSVG/inst/doc/nnSVG.html
Run npx skillmds@latest add biomate-ai/nnsvg in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
nnSVG It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
biomate-ai (@biomate-ai) published this skill. Their other Agent Skills are listed on their SkillMD profile.