SKILL.md--- name: scanpy description: Performs Scanpy single-cell RNA-seq QC, normalization, HVG selection, PCA/UMAP/t-SNE, clustering, exploratory marker ranking, pseudobulk preparation, visualization, and Seurat or SingleCellExperiment RDS conversion to h5ad. Applies to established exploratory scRNA-seq workflows with explicit count and expression provenance; complementary skills cover scvi-tools models and AnnData format details. license: BSD-3-Clause compatibility: Requires Python 3.12+ and Scanpy; tested with Python 3.13, Scanpy 1.12.4, and AnnData 0.13.4. Optional integrations need separate packages; R conversion needs R. Local analysis needs no credentials or network. metadata: version: "1.8" last-reviewed: "2026-10-01" upstream-version: "1.12.4" skill-author: K-Dense Inc. --- # Scanpy: Single-Cell Analysis ## Overview Scanpy is a scalable Python toolkit for analyzing single-cell RNA-seq data, built on AnnData. Apply this skill for complete single-cell workflows including quality control, normalization, dimensionality reduction, clustering, marker gene identification, visualization, and trajectory analysis. Targets **Scanpy 1.12.4** (released 2026-08-27), reviewed 2026-10-01. Native synthetic tests establish data/API contracts, not biological validity. ## Installation Requires Python **3.12+** (scanpy 1.12 dropped Python ≤3.11) and anndata **≥0.10**. ```bash uv pip install "scanpy[leiden]" ``` The `[leiden]` extra installs `igraph` and `leidenalg`; the scripts explicitly select `flavor="igraph"`. For reproducible environments, pin a version: `uv pip install "scanpy[leiden]==1.12.4"`. For large or out-of-core datasets, many functions support [Dask](https://docs.dask.org/) arrays (experimental): ```bash uv pip install "scanpy[leiden]" dask ``` See the [Using dask with Scanpy](https://scanpy.scverse.org/en/stable/tutorials/experimental/dask.html) tutorial. For GPU-accelerated scanpy-like operations, use [rapids-singlecell](https://rapids-singlecell.readthedocs.io/) as a separate package. If the input is an R-native single-cell object (`.rds`, `.RData`, Seurat, or SingleCellExperiment), first convert it to `.h5ad` with R tooling, then load it with Scanpy. Read `references/r_interop.md` for agent-run installation and conversion instructions across macOS, Linux, and Windows. For AnnData structure and I/O details, use the **anndata** skill. For probabilistic models and batch correction, use **scvi-tools**. ## Representation and inference contracts - Input to QC/preprocessing must be identified raw counts. The scripts reject negative, fractional, nonfinite or zero-total cells. Use `--counts-layer counts` when X is already normalized; never infer provenance from integer-looking values alone. - `layers["counts"]` remains unnormalized; `.raw` is an independent full-gene log-normalized snapshot. Gene subsetting also subsets every layer, but does not subset `.ra