domains / science / single-cell-rna-seq-analysis / scanpy
The K-Dense-AI copy is the most rigorous and specific, containing critical 'Representation and inference contracts' (e.g., raw count provenance, HVG flavor differences, Harmony/BBKNN side effects) and specific version pinning (Python 3.12+, Scanpy 1.12.4) that the others lack. However, the other three copies (Vibe-Skills, aipoch, sickn33) provide a complete, step-by-step 'Standard Analysis Workflow' with Python code snippets for QC, normalization, clustering, and annotation that the K-Dense copy omits in favor of referencing bundled scripts. The aipoch copy also adds a 'When to Use' section that explicitly frames the skill as a packaged method for reproducible deliverables. Combining is necessary to capture both the rigorous data contracts of the K-Dense copy and the executable workflow steps of the others.
| Repository | Path |
|---|---|
| K-Dense-AI/scientific-agent-skills | skills/scanpy/SKILL.md |
| foryourhealth111-pixel/Vibe-Skills | bundled/skills/scanpy/SKILL.md |
| aipoch/medical-research-skills | scientific-skills/Data Analysis/scanpy/SKILL.md |
| sickn33/agentic-awesome-skills | plugins/agentic-awesome-skills-claude/skills/scanpy/SKILL.md |
| Role | Repository | Path |
|---|---|---|
| peer | K-Dense-AI/scientific-agent-skills | skills/scanpy/SKILL.md |
| peer | foryourhealth111-pixel/Vibe-Skills | bundled/skills/scanpy/SKILL.md |
| peer | aipoch/medical-research-skills | scientific-skills/Data Analysis/scanpy/SKILL.md |
| peer | sickn33/agentic-awesome-skills | plugins/agentic-awesome-skills-claude/skills/scanpy/SKILL.md |
| inferior | FreedomIntelligence/OpenClaw-Medical-Skills | skills/scanpy/SKILL.md |
| adapter | sickn33/agentic-awesome-skills | plugins/agentic-awesome-skills/skills/scanpy/SKILL.md |
| adapter | sickn33/agentic-awesome-skills | skills/scanpy/SKILL.md |
# Scanpy: Single-Cell Analysis
## Overview
Scanpy is a scalable Python toolkit for analyzing single-cell RNA-seq data, built on AnnData. This skill covers complete workflows including quality control, normalization, dimensionality reduction, clustering, marker gene identification, visualization, and trajectory analysis.
## Environment & Installation
- **Python**: 3.12+ (Scanpy 1.12+ requirement).
- **Packages**: `scanpy[leiden]` (installs `igraph` and `leidenalg`).
- **Version Pinning**: Pin to `scanpy==1.12.4` for reproducibility.
- **R Interop**: Convert `.rds`/Seurat objects to `.h5ad` using R tooling before loading in Scanpy.
## Data Contracts & Provenance
- **Input**: Must be identified raw counts. Reject negative, fractional, or non-finite values.
- **Layers**: `layers["counts"]` remains unnormalized. `.raw` is an independent log-normalized snapshot.
- **HVGs**: `seurat`/`cell_ranger` flavors use log-normalized values; `seurat_v3` uses counts.
- **Marker Ranking**: Defaults to `.raw` if present. Use `--no-use-raw` to select X.
- **Integration**: Harmony/BBKNN modify PCA/graphs. Keep original expression for DE analysis.
## Standard Analysis Workflow
### 1. Quality Control
```python
import scanpy as sc
adata.var['mt'] = adata.var_names.str.startswith('MT-')
sc.pp.calculate_qc_metrics(adata, qc_vars=['mt'], inplace=True)
sc.pp.filter_cells(adata, min_genes=200)
sc.pp.filter_genes(adata, min_cells=3)
adata = adata[adata.obs.pct_counts_mt < 5, :]
```
### 2. Normalization & Preprocessing
```python
sc.pp.normalize_total(adata, target_sum=1e4)
sc.pp.log1p(adata)
adata.raw = adata
sc.pp.highly_variable_genes(adata, n_top_genes=2000)
adata = adata[:, adata.var.highly_variable]
sc.pp.scale(adata, max_value=10)
```
### 3. Dimensionality Reduction
```python
sc.tl.pca(adata, svd_solver='arpack')
sc.pp.neighbors(adata, n_neighbors=10, n_pcs=40)
sc.tl.umap(adata)
```
### 4. Clustering
```python
sc.tl.leiden(adata, resolution=0.5)
```
### 5. Marker Genes & Annotation
```python
sc.tl.rank_genes_groups(adata, 'leiden', method='wilcoxon')
sc.pl.rank_genes_groups(adata, n_genes=25, sharey=False)
# Map clusters to cell types based on marker expression
```
### 6. Visualization & Export
```python
sc.settings.set_figure_params(dpi=300, frameon=False)
sc.pl.umap(adata, color='cell_type', palette='Set2')
adata.write('results/processed_data.h5ad')
```
## When to Use
- Analyzing `.h5ad`, 10X, or CSV single-cell data.
- Performing exploratory scRNA-seq analysis.
- Generating publication-quality plots.
- Converting R-native objects to h5ad for downstream Python analysis.