/datascales-skills:spatial-on-gpufrom datascales-skills
Analyzes spatial transcriptomics cell tables (10x Xenium, Atera, SpatialData) on GPU using rapids-singlecell. Handles spatial QC, neighbor graphs, tissue niches, neighborhood enrichment, co-occurrence, ligand-receptor analysis, and spatially variable genes.
Ships in datascales-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Spatial statistics run on the cell table: counts in X, cell centers in obsm["spatial"].
rapids-singlecell has GPU versions of the squidpy graph functions under rsc.gr. The calls
below are copied from the team's Atera breast cancer notebook (170,057 cells × 18,028 genes,
capsules/process/code/notebooks/ in the DataScales repository; rapids-singlecell 0.18.1,
squidpy 1.8.3, spatialdata 0.8.0). They were run as written on 2026-12-01 on one Xenium
sample (259,541 cells × 480 genes, 1× A100 80 GB, rapids-singlecell 0.18.1; about 55 s,
single run), with expression clusters in place of cell_type. rsc.gr.ligrec and
rsc.dcg.ulm were not run. Print
rsc.__version__ and check a failing call against the docs. One sample of this size fits on
a GPU without Dask. The institute's Xenium best-practices file
(standardized_notebooks/xenium/best-practices/readme.md) is the reference for choices.
| Object | Holds | Use it for |
|---|---|---|
SpatialData .zarr | Images, shapes, transcripts and tables per sample | Viewing, cropping, anything that needs images |
Per-sample table (<sample>_table) | That sample's cells, its gene panel, obsm["spatial"] in µm | Every spatial step |
Joint table (table, from the spatial_ingest capsule) | All samples' cells, union of genes, no coordinates | Clustering and labelling across samples |
read_elem(zarr.open_group(STORE, mode="r")["tables/table"]).spatialdata 0.8.0 reads and writes paths only. A table alone can be versioned.Cut-offs depend on the tissue and the panel. Plot where in the tissue each cut-off removes cells and confirm with the person before filtering.
| Check | Starting point |
|---|---|
| Low counts | Notebook: at least 10 transcripts. qc capsule default: 20 |
| Low genes | qc capsule default: at least 5 |
| Nuclei | At least 1 nucleus per cell; review cells with several |
| Negative probes | No more than 4 to 5 per cell; plot them to find poor regions |
| Mitochondrial % | Usually absent: most panels have no MT genes |
| Doublets | Scrublet is not designed for spatial data; top 1 to 2% at most, with caution |
import cupy as cp, numpy as np, anndata as ad, pandas as pd, rapids_singlecell as rsc, rmm
from rmm.allocators.cupy import rmm_cupy_allocator
rmm.reinitialize(managed_memory=True, pool_allocator=False) # spill to host RAM, not fail
cp.cuda.set_allocator(rmm_cupy_allocator)
adata.X = adata.X.astype(np.float32)
rsc.get.anndata_to_GPU(adata, convert_all=True)
rsc.pp.calculate_qc_metrics(adata, expr_type="counts", var_type="genes", log1p=True)
keep = adata.obs["total_counts"] >= 10 # confirm the cut-off
if "nucleus_count" in adata.obs:
keep &= adata.obs["nucleus_count"] >= 1
adata = adata[keep].copy()
rsc.pp.filter_genes(adata, min_cells=3)
adata.layers["counts"] = adata.X.copy()
rsc.pp.normalize_total(adata)
rsc.pp.log1p(adata)
adata.layers["lognorm"] = adata.X.copy()
rsc.pp.highly_variable_genes(adata, n_top_genes=2000, flavor="seurat_v3", layer="counts")
rsc.pp.pca(adata, n_comps=50, mask_var="highly_variable")
rsc.pp.neighbors(adata, n_neighbors=15, use_rep="X_pca")
rsc.tl.leiden(adata, resolution=1.0, key_added="leiden_expr")
rsc.tl.umap(adata)
rsc.gr.spatial_neighbors_delaunay(adata, percentile=99) # drops the longest 1% of edges
niche_ad = ad.AnnData(X=rsc.get.X_to_CPU(adata.obsm["X_pca"]), obs=pd.DataFrame(index=adata.obs_names))
niche_ad.obsp["spatial_connectivities"] = adata.obsp["spatial_connectivities"]
rsc.gr.calculate_niche_cellcharter(niche_ad, n_components=9) # niches on PCs, not all genes
adata.obs["cellcharter_niche"] = niche_ad.obs["cellcharter_niche"].astype("category").values
rsc.gr.co_occurrence(adata, cluster_key="cell_type", interval=np.linspace(0, 250, 26), multi_gpu=False)
rsc.gr.nhood_enrichment(adata, cluster_key="cell_type", n_perms=500)
moran = rsc.gr.spatial_autocorr(adata, mode="moran", layer="lognorm", copy=True)
| Point | Why |
|---|---|
| Niches on the 50 PCs | On all 18,028 genes the GPU ran out of resources |
| Number of niches (9 here) | A choice for this tissue. Ask the person; compare with zones they expect |
percentile=99 | Triangulation links cells across gaps in the tissue |
rsc.gr.ligrec | Needs the AnnData back on the CPU (rsc.get.anndata_to_CPU) and takes no seed; set cp.random.seed |
| squidpy plots | CPU only: move the AnnData back once, before plotting |
| Cell types | The notebook scores marker genes with rsc.dcg.ulm and labels each cluster by its best mean score. The marker list is for that tissue only |
library_key="<sample column>"
to rsc.gr.spatial_neighbors_delaunay (run on four Xenium samples, 2.3M cells: no edge
between samples). Cluster on the joint table and map labels back by cell_id.anndata_ingest capsule's default CellTypist models are PBMC
models. For tissue, use a reference for that tissue cut down to the panel's genes, or
marker scores per cluster, and expect manual review.rapids-out-of-core for the expression steps.spatial_leiden, X_umap_spatial) so they do not
replace results from an scRNA run on the same table.X, then save the analysed
table as an Icechunk repository (az.convert(adata, ...) in icechunk-analysis-history)
and add later results as commits. Use adata.write_zarr only if the person asks for plain Zarr. In the team's test both agents left 14 to 15 GB
of .h5ad with five or six copies of a 2.3M-cell matrix.uns or a small JSON file beside the outputs.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
npx claudepluginhub aifimmunology/datascales --plugin datascales-skills5 skills in this plugin
/datascales-workflowPlans an analysis of large single-cell or spatial data as one workflow, AnnData on Zarr, Icechunk history and rapids-singlecell on a GPU, as the DataScales team at the Allen Institute for Immunology runs it. Use when someone wants to analyse data that is too big for memory, keeps growing or is shared between people; asks whether a GPU is worth it; wants QC through clustering at scale; or asks which DataScales tools, capsules or benchmarks exist. Start here for a whole analysis; the topic skills cover single steps./icechunk-analysis-historyKeeps the history of an analysis inside an Icechunk repository holding an AnnData store, with commits and branches through annizarr. Use by default whenever a Zarr store is built or results are saved into one, and when someone wants to version or snapshot a single-cell store, keep raw counts safe while analysing, give each person or analysis a branch, save QC results or clusters as a commit with the settings that made them, read or compare an earlier state, undo a step, or avoid keeping a full copy of the data per analysis stage. Not for choosing the store layout, and not for versioning code./rapids-out-of-coreRuns rapids-singlecell on a GPU over a Zarr AnnData store that is larger than GPU or host memory, reading cells in Dask blocks. Use when someone wants to normalize, find variable genes, run PCA, neighbors, UMAP or Leiden on millions of cells on a GPU, set up a Dask-CUDA cluster, choose managed memory or a pool, size a GPU for a dataset, or when a GPU run is slow, runs out of memory, or does not speed up with more GPUs. Not for building the store or for spatial statistics./zarr-for-single-cellSets up and tunes one AnnData store on Zarr v3 for single-cell counts with annizarr. Use when someone wants to convert or combine h5ad or 10x files into a Zarr store, add samples later, choose between CSR, CSC and dense, sort cells, pick chunks, shards or compression, or when reading one gene or one cell type from a store is slow, a store has too many small files, or a conversion runs out of memory. Not for commits and branches, and not for the GPU analysis itself.