Analyzes spatial transcriptomics with squidpy on AnnData/SpatialData objects. Routes Visium spots to grid-based neighbors and deconvolution, Xenium/MERFISH to Delaunay neighbors. Runs neighborhood enrichment, co-occurrence, spatial autocorrelation (Moran's I), Ripley's statistics, and ligand-receptor analysis.
Squidpy is the scverse toolkit for spatially-resolved omics, built on AnnData and
SpatialData. It answers questions a non-spatial scRNA-seq pipeline cannot: which
cell types sit next to which (neighborhood enrichment), how cell-type pairs
co-occur across distance (co-occurrence), which genes vary across tissue space
(Moran's I / spatially variable genes), and what ligand-receptor signalling is
plausible (ligrec). This skill does the spatial analysis; it hands non-spatial
QC/clustering to alterlab-scanpy and spot deconvolution to alterlab-scvi-tools.
Use when the request involves:
spatial_autocorr) or Sepal.ligrec).calculate_niche_*: neighborhood
profile, UTAG, CellCharter, SpatialLeiden).coord_type for the platform.| Request | Route to |
|---|---|
| Non-spatial scRNA-seq QC, normalization, PCA/UMAP, Leiden clustering, marker genes | alterlab-scanpy |
| Spot deconvolution / mapping cell types to Visium spots (destVI, Tangram), probabilistic batch correction/integration | alterlab-scvi-tools (see its references/models-spatial.md) |
Building/slicing/concatenating .h5ad AnnData objects, layer & obsm wrangling (no spatial analysis) | alterlab-anndata |
| RNA-velocity / trajectory dynamics | alterlab-scvelo |
| Bulk RNA-seq differential expression from a count matrix | alterlab-pydeseq2 |
| Raw FASTQ → expression matrix (read alignment/quantification) | alterlab-rnaseq-quant |
| Diversity / ecology statistics on a feature table | alterlab-scikit-bio |
Hand-off rule. When the request matches a row above, open your answer by naming that skill by its exact id (for example alterlab-scanpy) and saying in one line why it fits better, then stop applying this skill's procedure. Name it even when you also need to ask for missing input. If only part of the request is out of scope, name the skill for that part and do only the in-scope part. A brief general pointer is fine; the named skill does the work.
If the user wants the whole pipeline ("cluster my Xenium data, then find which
cell types are neighbors"), run the scanpy clustering step under alterlab-scanpy
first, then return here for the spatial graph and enrichment.
Squidpy's spatial graph depends on the measurement geometry. Getting coord_type
wrong silently produces a meaningless graph. (All parameter behavior below is from
the squidpy 1.8 sq.gr.spatial_neighbors API.)
| Platform | Resolution | Builder | Pair with |
|---|---|---|---|
| Visium | spot (multi-cell, hex grid) | coord_type="grid", n_neighs=6, n_rings=1..2 | deconvolution → alterlab-scvi-tools |
| Visium HD | 2/8/16 µm bins (square grid) | coord_type="grid" (square lattice) | binning choice up front |
| Xenium / MERFISH / CosMx | single cell | coord_type="generic", delaunay=True (or n_neighs=k) | direct cell-type analysis |
coord_type=None auto-picks "grid" only when spatial is in adata.uns with
n_neighs=6 (the Visium signature); otherwise it falls back to "generic". Set
coord_type explicitly rather than relying on auto-detection.delaunay=True is only used when coord_type="generic"; it builds the graph from
a Delaunay triangulation instead of k-nearest spots. n_rings is only used for
coord_type="grid".sq.gr.spatial_neighbors_grid,
_knn, _radius, _delaunay — each with only the parameters that apply to it.
Prefer them when you know the geometry: sq.gr.spatial_neighbors(..., delaunay=True)
silently ignores n_neighs, which is a common source of "my k did nothing".import squidpy as sq
import scanpy as sc
# Visium (legacy spot data) — squidpy's own reader, returns AnnData
adata = sq.read.visium("path/to/visium_outs/")
# Vizgen MERSCOPE / Nanostring CosMx via squidpy readers
adata = sq.read.vizgen("path/to/merscope/", counts_file="cell_by_gene.csv",
meta_file="cell_metadata.csv")
adata = sq.read.nanostring("path/to/cosmx/", counts_file="exprMat_file.csv",
meta_file="metadata_file.csv", fov_file="fov_positions.csv")
For Xenium and Visium HD, use the spatialdata-io readers (squidpy has no
sq.read.xenium) and operate on a SpatialData object:
from spatialdata_io import xenium, visium_hd, merscope
sdata = xenium("path/to/xenium_outs/") # 10x Xenium
sdata = visium_hd("path/to/visium_hd_outs/") # 10x Visium HD
sdata = merscope("path/to/merscope/") # Vizgen MERSCOPE
spatialdata-io reader names are verified against the spatialdata-io stable API.
Squidpy 1.8 accepts SpatialData objects directly; see
references/spatialdata_io.md for the SpatialData ↔ AnnData (table) flow.
QC, normalization, HVGs, PCA, neighbors, Leiden, and sc.tl.umap are scanpy
steps — run them via alterlab-scanpy. Once you have clusters / cell-type labels,
do the spatial part here.
import squidpy as sq
# 1. Build the spatial neighbor graph (choose coord_type per the table above)
sq.gr.spatial_neighbors(adata, coord_type="generic", delaunay=True) # Xenium/MERFISH
# sq.gr.spatial_neighbors(adata, coord_type="grid", n_neighs=6) # Visium
# 2. Neighborhood enrichment: which cluster pairs are spatially adjacent?
sq.gr.nhood_enrichment(adata, cluster_key="leiden")
sq.pl.nhood_enrichment(adata, cluster_key="leiden")
# 3. Co-occurrence across distance
sq.gr.co_occurrence(adata, cluster_key="leiden")
sq.pl.co_occurrence(adata, cluster_key="leiden", clusters="0")
# 4. Spatially variable genes via Moran's I
sq.gr.spatial_autocorr(adata, mode="moran")
svgs = adata.uns["moranI"].head(20) # ranked by Moran's I
# 5. Ligand-receptor interaction (Omnipath-backed)
sq.gr.ligrec(adata, cluster_key="leiden")
# 6. Spatial niches / tissue domains — cluster cells by their neighborhood, not
# just their own expression. Requires a spatial graph (step 1) already built.
sq.gr.calculate_niche_neighborhood(adata, groups="leiden", resolutions=[0.5, 1.0])
# other flavors: calculate_niche_utag, calculate_niche_cellcharter,
# calculate_niche_spatialleiden
The generic sq.gr.calculate_niche(..., flavor=...) dispatcher still works but is
deprecated for removal in squidpy 1.9 — call the flavor-specific function, whose
signature only carries the parameters that flavor actually uses. Niches answer a
different question from nhood_enrichment: enrichment asks which labelled cell types
sit together on average, niches assign each cell to a recurring tissue
microenvironment.
Other graph statistics: sq.gr.interaction_matrix, sq.gr.centrality_scores,
sq.gr.ripley (clustering/dispersion vs. CSR), and sq.gr.sepal (an alternative
spatially-variable-gene test). Visualize tissue with sq.pl.spatial_scatter
(spot/point) or sq.pl.spatial_segment (segmented cells);
sq.pl.nhood_enrichment_dotplot and sq.pl.var_by_distance (expression as a function
of distance to an anchor) are the other two plots worth knowing. For image features on
H&E/IF, the sq.im module (process, segment, calculate_image_features)
operates on an ImageContainer.
Helper script — build the graph and run the core statistics in one call:
uv run python scripts/spatial_neighborhood.py \
clustered.h5ad --platform xenium --cluster-key leiden --out spatial_report.json
See scripts/spatial_neighborhood.py --help. It chooses coord_type from
--platform, runs spatial_neighbors, nhood_enrichment, co_occurrence, and
spatial_autocorr, and writes a JSON summary (top spatially variable genes + the
enrichment z-score matrix) plus the updated .h5ad.
references/platform_routing.md — full platform→coord_type decision table, the
n_neighs/n_rings/delaunay parameter semantics, and per-platform gotchas.references/analysis_recipes.md — copy-paste recipes for each sq.gr / sq.pl
function with the parameters that matter and how to read the outputs.references/spatialdata_io.md — reading Xenium / Visium HD / MERSCOPE into
SpatialData and getting the AnnData table squidpy operates on.coord_type to match the platform (grid for Visium, generic for
single-cell)? A wrong graph invalidates every downstream statistic.alterlab-scanpy (this skill assumes labels exist)?alterlab-scvi-tools)
is needed before cell-type-level claims — spots are multi-cell?nhood_enrichment z-scores reported with the permutation context, not as raw
counts?Part of the AlterLab Academic Skills suite.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
spatial-transcriptomics, squidpy, visium, xenium, merfish, anndata, spatialdata
Not loaded · from alterlab-writing-tools
Claude Code won't load this skill
It ships in alterlab-writing-tools at skills/, but Claude Code only loads skills/<name>/SKILL.md and folders listed under skills in plugin.json. Installing the plugin doesn't add it.
Generated from the plugin's indexed repository (alterlab-ieu/alterlab-academic-skills) — no native marketplace selected
npx claudepluginhub p/alterlab-ieu-alterlab-writing-tools241 skills in this plugin
/alterlab-abm-mesaBuilds agent-based models of social systems with Mesa 3 — the current AgentSet API (model.agents.shuffle_do('step'), auto-assigned unique_id, mandatory super().__init__(rng=...)), cell spaces (mesa.discrete_space OrthogonalMooreGrid / classic mesa.space grids), the DataCollector, batch_run parameter sweeps, and SolaraViz — for emergence, segregation, diffusion, opinion dynamics, and cooperation models. It uses the Mesa 3.x API (the old mesa.time schedulers like RandomActivation are removed) and treats the model as a generative theory to be validated, not just run. Use when the request mentions an agent-based model, Mesa, simulating interacting agents, or emergent macro behavior from micro rules. For discrete-event (queueing/process) simulation prefer alterlab-simpy; for reinforcement learning prefer alterlab-stable-baselines3. Part of the AlterLab Academic Skills suite./alterlab-academic-careerPrepares academic career documents and professional-development materials for faculty and researchers. Use when drafting academic CVs, research statements, teaching philosophies, diversity statements, faculty-position cover letters, tenure dossiers, promotion narratives, academic portfolios, or mentorship statements, and when planning conference-networking strategy, building academic web presence, setting up ORCID profiles, or understanding impact metrics. Part of the AlterLab Academic Skills suite./alterlab-accreditation-aolScaffolds program-level Assurance-of-Learning (AoL) documentation for AACSB (Standard 5 in the 2020 standards and the 2026 Global Standards) and ABET (Criterion 3 Student Outcomes, Criterion 4 Continuous Improvement) accreditation — program learning outcomes / competency goals, curriculum-to-outcome mapping matrices, direct- and indirect-assessment plans, rubric design, and closing-the-loop continuous-improvement narratives — and validates the structure of an outcome-mapping matrix with scripts/aol_matrix.py. Use when the user needs AACSB or ABET assurance-of-learning material, a program-learning-outcomes set, a curriculum/outcome map or coverage matrix, a direct/indirect assessment plan, a closing-the-loop report, or accreditation self-study text. For single-course design or course rubrics prefer alterlab-teaching-design; for post-award grant reports prefer alterlab-grant-reporting. Part of the AlterLab Academic Skills suite./alterlab-adaptyvPrepares and validates Adaptyv Bio Foundry protein-testing submissions with no account — optimizes and pre-screens sequences locally (NetSolP/SoluProt heuristics, SolubleMPNN, ESM), assembles the experiment payload, and validates it offline against the Foundry's own type/method/sequence rules so it is ready and correct before it costs anything. Submitting to the Foundry, browsing the target catalog, tracking status and retrieving results run through the Foundry API with the user's own ADAPTYV_API_KEY (experiments cost money and take weeks). Use when designing proteins for wet-lab validation (binding/affinity, expression, thermostability, fluorescence), preparing or validating a Foundry submission, pre-screening sequences, or tracking an Adaptyv experiment. Triggers on "Adaptyv", "Foundry API", "cloud lab", "biolayer interferometry / BLI", "wet-lab validation". Part of the AlterLab Academic Skills suite./alterlab-aeonRuns time series machine learning with the aeon library — classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search via scikit-learn compatible APIs. Use when working with temporal data, sequential patterns, or time-indexed observations (univariate or multivariate) that need specialized algorithms beyond standard ML approaches. Part of the AlterLab Academic Skills suite./alterlab-ai-use-disclosureHelps faculty and researchers disclose generative-AI use and comply with the rules for manuscripts, grant proposals, peer review, theses and figures. Walks a venue → policy → placement decision tree over policies verified on 2026-09-23 (ICMJE, Springer Nature/Nature, Elsevier, Wiley, Taylor & Francis, Sage, IEEE, PLOS, arXiv; NIH NOT-OD-25-132 and NOT-OD-23-149, NSF, UKRI, ERC, TÜBİTAK; YÖK's 2024 ethics guide; EU AI Act Article 50), drafts English and Turkish statements, and ships scripts/disclosure_builder.py to emit a statement plus warnings where a policy forbids the use. Use when the request mentions an AI or ChatGPT disclosure or declaration, whether and where AI use must be declared, AI in peer review or grant review, AI-generated figures, AI rules for a thesis, or 'yapay zekâ kullanım beyanı'. For course AI policies and APA/MLA citations of ChatGPT prefer alterlab-syllabus-ai-policy; for writing the paper itself prefer alterlab-scientific-writing. Part of the AlterLab Academic Skills suite.2 plugins in one repository ship this exact skill · first indexed Nov 9, 2026
Other plugins' skills for the same job