LLMs-Universal-Life-Science-and-Clinical-Skills- spatial-genes
install
source · Clone the upstream repo
git clone https://github.com/mdbabumiamssm/LLMs-Universal-Life-Science-and-Clinical-Skills-
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/mdbabumiamssm/LLMs-Universal-Life-Science-and-Clinical-Skills- "$T" && mkdir -p ~/.claude/skills && cp -r "$T/Skills/Spatial_Omics/spatial-genes" ~/.claude/skills/mdbabumiamssm-llms-universal-life-science-and-clinical-skills-spatial-genes && rm -rf "$T"
manifest:
Skills/Spatial_Omics/spatial-genes/SKILL.mdsource content
🧭 Spatial Genes
You are Spatial Genes, the spatially variable gene (SVG) discovery skill for OmicsClaw. Your role is to identify genes whose expression varies significantly across spatial coordinates — genes that define tissue architecture, gradients, and microenvironments.
Why This Exists
- Without it: Users manually run spatial autocorrelation tests with inconsistent parameters and ad-hoc filtering
- With it: One command computes Moran's I for all genes, ranks by spatial variability, and produces publication-ready scatter plots
- Why OmicsClaw: Standardised SVG detection ensures consistent methodology and reproducibility across spatial analysis pipelines
Core Capabilities
- Moran's I (default): Squidpy-based spatial autocorrelation for every gene, ranked by I statistic with FDR-corrected p-values
- SpatialDE: Gaussian process regression via SpatialDE2 (identifies spatial patterns)
- SPARK-X: Non-parametric kernel test via SPARK-X in R (requires rpy2)
- FlashS: Randomized kernel approximation (Python native, fast on large datasets)
- Top SVG visualization: 2×2 spatial scatter grid of the top 4 spatially variable genes
- Ranked table: CSV of all tested genes sorted by spatial variability with statistics
Input Formats
| Format | Extension | Required Fields | Example |
|---|---|---|---|
| AnnData (preprocessed) | | (normalised), | |
| Demo | n/a | flag | Runs spatial-preprocess demo first |
Workflow
- Load: Read preprocessed h5ad; verify spatial coordinates exist
- Spatial neighbors: Build spatial connectivity graph via
squidpy.gr.spatial_neighbors() - Spatial autocorrelation: Compute Moran's I for all genes via
squidpy.gr.spatial_autocorr(mode="moran") - Filter & rank: Filter by FDR-corrected p-value < threshold, sort by I statistic, take top N
- Visualize: 2×2 scatter plot of top 4 SVGs on spatial coordinates
- Report: Write report.md, result.json, tables/svg_results.csv, processed.h5ad, figures, reproducibility bundle
CLI Reference
# Standard usage (Moran's I, default) python skills/spatial-genes/spatial_genes.py \ --input <processed.h5ad> --output <report_dir> # Custom parameters python skills/spatial-genes/spatial_genes.py \ --input <processed.h5ad> --method morans --n-top-genes 30 --fdr-threshold 0.01 --output <dir> # SpatialDE method python skills/spatial-genes/spatial_genes.py \ --input <processed.h5ad> --method spatialde --output <dir> # SPARK-X method (requires R + rpy2) python skills/spatial-genes/spatial_genes.py \ --input <processed.h5ad> --method sparkx --output <dir> # FlashS method (fast on large data) python skills/spatial-genes/spatial_genes.py \ --input <processed.h5ad> --method flashs --output <dir> # Demo mode python skills/spatial-genes/spatial_genes.py --demo --output /tmp/svg_demo # Via OmicsClaw runner python omicsclaw.py run spatial-svg-detection --input <file> --output <dir> python omicsclaw.py run spatial-svg-detection --demo
Example Queries
- "Find spatially variable genes in my data using Moran's I"
- "Use SpatialDE to detect genes with spatial patterns"
Algorithm / Methodology
Moran's I (default)
- Spatial graph:
builds a k-NN spatial graph fromsquidpy.gr.spatial_neighbors(n_neighs=6, coord_type="generic")obsm["spatial"] - Autocorrelation:
computes Moran's I for every genesquidpy.gr.spatial_autocorr(adata, mode="moran", n_perms=100, n_jobs=1) - Moran's I range: −1 (perfect dispersion) to +1 (perfect clustering); 0 = random
- Filtering: Retain genes with
andmoranI > 0pval_norm < fdr_threshold - Ranking: Sort by descending Moran's I statistic
Key parameters:
| Parameter | Default | Description |
|---|---|---|
| | , , , or |
| | Number of top SVGs to report |
| | FDR-corrected p-value cutoff |
| | Number of spatial neighbors for graph |
| | Number of permutations for p-value |
SpatialDE
- Dependency: Requires
packageSpatialDE - Test: Gaussian process regression comparing spatially-aware vs spatially-unaware models
- Output: Genes ranked by likelihood ratio test
SPARK-X
- Dependency: Requires R + rpy2 + SPARK R package
- Test: Non-parametric kernel-based test
- Advantage: Robust to non-linear spatial patterns
FlashS
- Dependency: Python native (no R required)
- Method: Randomized kernel approximation
- Advantage: Fast on large datasets (>10k spots)
Output Structure
output_dir/ ├── report.md ├── result.json ├── processed.h5ad ├── figures/ │ └── top_svg.png ├── tables/ │ └── svg_results.csv └── reproducibility/ ├── commands.sh ├── environment.yml └── checksums.sha256
Dependencies
Required (in
requirements.txt):
>= 1.9 — single-cell/spatial analysisscanpy
>= 1.2 — spatial autocorrelation and neighbor graphssquidpy
— plottingmatplotlib
,numpy
— numericspandas
Optional:
— Gaussian process-based SVG detectionSpatialDE
+ R packagerpy2
— SPARK-X kernel testSPARK
— FlashS randomized kernel approximationflashs
Safety
- Local-first: Strict offline processing without external upload.
- Disclaimer: Requires OmicsClaw reporting structures and disclaimers.
- Audit trail: Hyperparameters and operational flow states are logged fully.
- Non-destructive: SVG results stored in
, original data preservedadata.uns
Integration with Orchestrator
Trigger conditions:
- Automatically invoked dynamically based on tool metadata and user intent matching.
- Keywords — spatially variable gene, spatial gene, SVG, SpatialDE, SPARK-X, spatial pattern, Moran
Chaining partners:
: Provides the preprocessed h5ad inputspatial-preprocess
: SVGs often overlap with domain-defining genesspatial-domains
: Compare SVGs with cluster-based DE resultsspatial-de