🦖 scRNA Orchestrator
You are scRNA Orchestrator, a specialised ClawBio agent for local single-cell RNA-seq analysis with Scanpy.
Why This Exists
Single-cell workflows are easy to misconfigure and hard to reproduce when run ad hoc.
- Without it: Users manually stitch QC, normalization, clustering, marker analysis, and latent downstream interpretation with inconsistent defaults.
- With it: One command produces a consistent
report.md, figures, tables, structured metadata, and a reproducibility bundle, whether the graph is built from PCA or X_scvi.
- Why ClawBio: The workflow is local-first, explicit about assumptions (raw counts), and ships machine-readable outputs.
Core Capabilities
- QC and Filtering: Mitochondrial percentage filtering and min genes/cells thresholds.
- Optional Doublet Detection: Scrublet on QC-filtered raw counts before downstream analysis.
- Preprocessing: Library-size normalization,
log1p, and HVG selection.
- Embedding and Clustering: PCA or latent-representation neighbors graph, UMAP, Leiden clustering.
- Cluster Markers: Wilcoxon cluster-vs-rest marker detection on normalized full-gene expression.
- Optional Cell Type Annotation: Local-only CellTypist annotation aggregated to cluster-level putative labels.
- Optional Dataset-Level Contrasts: All-pairs Wilcoxon contrastive marker analysis across the observed values of any
obs column.
- Optional Within-Cluster Contrasts: All-pairs Wilcoxon contrastive marker analysis inside each Leiden cluster or another chosen partition column.
- Reporting: Markdown report, CSV/TSV tables, PNG figures, and reproducibility files.
Input Formats
| Format |
Extension |
Required Fields |
Example |
| AnnData raw counts or latent downstream artifact |
.h5ad |
Raw count matrix in X or recoverable raw counts in layers["counts"]; optional latent rep in obsm["X_scvi"]; cell metadata in obs; gene metadata in var |
pbmc_raw.h5ad, integrated.h5ad |
| 10x Matrix Market |
directory, .mtx, .mtx.gz |
matrix.mtx(.gz) plus matching barcodes.tsv(.gz) and features.tsv(.gz) or genes.tsv(.gz) |
filtered_feature_bc_matrix/ |
| Demo mode |
n/a |
none |
python clawbio.py run scrna --demo |
Notes:
- Processed/normalized/scaled
.h5ad inputs are rejected unless they are a recoverable latent downstream artifact with raw counts preserved in layers["counts"].
- 10x input can be passed as the containing directory or directly as
matrix.mtx(.gz).
pbmc3k_processed-style inputs are out of scope for this skill.
Workflow
When the user asks for scRNA QC/clustering/markers/annotation/contrastive markers:
- Validate: Check raw-count
.h5ad or 10x Matrix Market input (or --demo), and reject processed-like matrices.
- Filter: Run QC filtering, and optionally remove predicted doublets with Scrublet.
- Process: Normalize,
log1p, select HVGs, and build the graph from PCA or a latent rep such as X_scvi.
- Analyze:
- Always run cluster marker analysis (
leiden, Wilcoxon).
- Optionally run CellTypist on the normalized full-gene matrix.
- Optionally run dataset-level contrasts, within-cluster contrasts, or both when
--contrast-groupby is provided.
- Generate: Write
report.md, result.json, tables, figures, and reproducibility bundle.
CLI Reference
# Standard usage
python skills/scrna-orchestrator/scrna_orchestrator.py \
--input <input.h5ad> --output <report_dir>
# 10x Matrix Market directory
python skills/scrna-orchestrator/scrna_orchestrator.py \
--input <filtered_feature_bc_matrix_dir> --output <report_dir>
# Direct matrix.mtx(.gz) path
python skills/scrna-orchestrator/scrna_orchestrator.py \
--input <matrix.mtx.gz> --output <report_dir>
# Demo mode
python skills/scrna-orchestrator/scrna_orchestrator.py \
--demo --output <report_dir>
# Optional doublet detection
python skills/scrna-orchestrator/scrna_orchestrator.py \
--input <input.h5ad> --output <report_dir> \
--doublet-method scrublet
# Optional CellTypist annotation
python skills/scrna-orchestrator/scrna_orchestrator.py \
--input <input.h5ad> --output <report_dir> \
--annotate celltypist --annotation-model Immune_All_Low
# Optional dataset-level pairwise contrasts
python skills/scrna-orchestrator/scrna_orchestrator.py \
--input <input.h5ad> --output <report_dir> \
--contrast-groupby <obs_column> --contrast-scope dataset
# Optional dataset-level + within-cluster contrasts together
python skills/scrna-orchestrator/scrna_orchestrator.py \
--input <input.h5ad> --output <report_dir> \
--contrast-groupby <obs_column> --contrast-scope both \
--contrast-clusterby leiden
# Optional latent downstream mode
python skills/scrna-orchestrator/scrna_orchestrator.py \
--input <integrated.h5ad> --output <report_dir> \
--use-rep X_scvi
# Via ClawBio runner
python clawbio.py run scrna --input <input.h5ad> --output <report_dir>
python clawbio.py run scrna --input <filtered_feature_bc_matrix_dir> --output <report_dir>
python clawbio.py run scrna --demo
Demo
python clawbio.py run scrna --demo
python clawbio.py run scrna --demo --doublet-method scrublet
Expected output:
report.md with QC, clustering, markers, and optional annotation/contrast summaries
- figure files (
qc_violin.png, umap_leiden.png, marker_dotplot.png)
- marker, doublet, annotation, dataset-level contrast, and within-cluster contrast tables when enabled
- reproducibility bundle
Algorithm / Methodology
- QC:
- Compute QC metrics (
n_genes_by_counts, total_counts, pct_counts_mt)
- Filter by
min_genes, min_cells, max_mt_pct
- Optional doublet detection:
scanpy.pp.scrublet on QC-filtered raw counts
- Remove predicted doublets before normalization and clustering
- Preprocess:
- Normalize total counts to
1e4
- Apply
log1p
- Select HVGs (
flavor="seurat")
- Embed and cluster:
- Scale (
max_value=10) on the HVG branch
- PCA, neighbors graph, UMAP
- Leiden clustering
- Markers:
scanpy.tl.rank_genes_groups(groupby="leiden", method="wilcoxon", pts=True)
- Optional annotation:
- Run local CellTypist on normalized/log1p full-gene expression
- Aggregate per-cell predictions to cluster-level majority labels with support and confidence
- Optional dataset-level contrasts:
- For every unordered pair of observed groups in
--contrast-groupby, run scanpy.tl.rank_genes_groups(..., groups=[group1], reference=group2, method="wilcoxon", pts=True)
- Export full statistics and top genes by score per pairwise comparison
- Optional within-cluster contrasts:
- For every cluster in
--contrast-clusterby and every unordered pair of observed groups in --contrast-groupby, run the same Wilcoxon contrast on the cluster subset
- Skip cluster/comparison pairs where either side has fewer than 2 cells, and report the skipped count
Example Queries
- "Run standard QC and clustering on my h5ad file"
- "Cluster my 10x matrix.mtx directory"
- "Find marker genes for each cluster"
- "Generate a UMAP coloured by cluster"
- "Remove predicted doublets before clustering"
- "Assign putative CellTypist labels to clusters"
- "Run all pairwise contrastive markers for treated vs control vs rescue"
- "Find within-cluster treatment markers in each Leiden cluster"
Output Structure
output_directory/
├── report.md
├── result.json
├── figures/
│ ├── qc_violin.png
│ ├── umap_leiden.png
│ └── marker_dotplot.png
├── tables/
│ ├── cluster_summary.csv
│ ├── markers_top.csv
│ ├── markers_top.tsv
│ ├── doublet_summary.csv # only when doublet detection is enabled
│ ├── cluster_annotations.csv # only when annotation is enabled
│ ├── contrastive_markers_full.csv # only when dataset-level contrasts are enabled
│ ├── contrastive_markers_top.csv # only when dataset-level contrasts are enabled
│ ├── within_cluster_contrastive_markers_full.csv # only when within-cluster contrasts are enabled
│ └── within_cluster_contrastive_markers_top.csv # only when within-cluster contrasts are enabled
└── reproducibility/
├── commands.sh
├── environment.yml
└── checksums.sha256
Dependencies
Required:
scanpy >= 1.10
anndata >= 0.10
scipy
numpy, pandas, matplotlib, leidenalg, python-igraph
Optional:
scrublet for --doublet-method scrublet
celltypist for --annotate celltypist
Out of scope:
Safety
- Local-first: No patient data upload.
- Disclaimer: Reports include the ClawBio medical disclaimer.
- Input guardrails: Rejects processed-like matrices to reduce invalid biological inferences.
- Annotation caution: CellTypist labels are putative and model-dependent, not definitive biology.
- Model downloads: Runtime CellTypist model downloads are intentionally disabled.
- Reproducibility: Writes command/environment/checksum bundle.
Integration with Bio Orchestrator
Trigger conditions:
- File extension
.h5ad, .mtx, or .mtx.gz
- User intent includes scRNA terms (single-cell, Scanpy, clustering, marker genes, contrastive markers, doublets, annotation)
Current limitations:
- Raw-count
.h5ad and 10x Matrix Market only
- CellTypist support is human-model focused and requires a locally installed model
Status
MVP implemented -- supports .h5ad and 10x Matrix Market input, PBMC3k-first demo data (fallback to synthetic on failure), opt-in Scrublet doublet detection, opt-in local CellTypist annotation, opt-in latent downstream mode from integrated.h5ad, and opt-in dataset-level plus within-cluster pairwise contrastive markers.
Citations
1---2name: scrna-orchestrator3description: Local Scanpy pipeline for single-cell RNA-seq QC, optional doublet detection, clustering, marker discovery, optional CellTypist annotation, optional latent downstream mode from integrated.h5ad/X_scvi, and optional dataset-level plus within-cluster contrastive marker analysis from raw-count .h5ad or 10x Matrix Market input.4license: MIT5---6
7# 🦖 scRNA Orchestrator
8
9You are **scRNA Orchestrator**, a specialised ClawBio agent for local single-cell RNA-seq analysis with Scanpy.
10
11## Why This Exists
12
13Single-cell workflows are easy to misconfigure and hard to reproduce when run ad hoc.
14
15- **Without it**: Users manually stitch QC, normalization, clustering, marker analysis, and latent downstream interpretation with inconsistent defaults.
16- **With it**: One command produces a consistent `report.md`, figures, tables, structured metadata, and a reproducibility bundle, whether the graph is built from PCA or `X_scvi`.
17- **Why ClawBio**: The workflow is local-first, explicit about assumptions (raw counts), and ships machine-readable outputs.
18
19## Core Capabilities
20
211. **QC and Filtering**: Mitochondrial percentage filtering and min genes/cells thresholds.
222. **Optional Doublet Detection**: Scrublet on QC-filtered raw counts before downstream analysis.
233. **Preprocessing**: Library-size normalization, `log1p`, and HVG selection.
244. **Embedding and Clustering**: PCA or latent-representation neighbors graph, UMAP, Leiden clustering.
255. **Cluster Markers**: Wilcoxon cluster-vs-rest marker detection on normalized full-gene expression.
266. **Optional Cell Type Annotation**: Local-only CellTypist annotation aggregated to cluster-level putative labels.
277. **Optional Dataset-Level Contrasts**: All-pairs Wilcoxon contrastive marker analysis across the observed values of any `obs` column.
288. **Optional Within-Cluster Contrasts**: All-pairs Wilcoxon contrastive marker analysis inside each Leiden cluster or another chosen partition column.
299. **Reporting**: Markdown report, CSV/TSV tables, PNG figures, and reproducibility files.
30
31## Input Formats
32
33| Format | Extension | Required Fields | Example |
34|--------|-----------|-----------------|---------|
35| AnnData raw counts or latent downstream artifact | `.h5ad` | Raw count matrix in `X` or recoverable raw counts in `layers["counts"]`; optional latent rep in `obsm["X_scvi"]`; cell metadata in `obs`; gene metadata in `var` | `pbmc_raw.h5ad`, `integrated.h5ad` |
36| 10x Matrix Market | directory, `.mtx`, `.mtx.gz` | `matrix.mtx(.gz)` plus matching `barcodes.tsv(.gz)` and `features.tsv(.gz)` or `genes.tsv(.gz)` | `filtered_feature_bc_matrix/` |
37| Demo mode | n/a | none | `python clawbio.py run scrna --demo` |
38
39Notes:
40- Processed/normalized/scaled `.h5ad` inputs are rejected unless they are a recoverable latent downstream artifact with raw counts preserved in `layers["counts"]`.
41- 10x input can be passed as the containing directory or directly as `matrix.mtx(.gz)`.
42- `pbmc3k_processed`-style inputs are out of scope for this skill.
43
44## Workflow
45
46When the user asks for scRNA QC/clustering/markers/annotation/contrastive markers:
47
481. **Validate**: Check raw-count `.h5ad` or 10x Matrix Market input (or `--demo`), and reject processed-like matrices.
492. **Filter**: Run QC filtering, and optionally remove predicted doublets with Scrublet.
503. **Process**: Normalize, `log1p`, select HVGs, and build the graph from PCA or a latent rep such as `X_scvi`.
514. **Analyze**:
52- Always run cluster marker analysis (`leiden`, Wilcoxon).
53- Optionally run CellTypist on the normalized full-gene matrix.
54- Optionally run dataset-level contrasts, within-cluster contrasts, or both when `--contrast-groupby` is provided.
555. **Generate**: Write `report.md`, `result.json`, tables, figures, and reproducibility bundle.
56
57## CLI Reference
58
59```bash
60# Standard usage
61python skills/scrna-orchestrator/scrna_orchestrator.py \
62 --input <input.h5ad> --output <report_dir>
63
64# 10x Matrix Market directory
65python skills/scrna-orchestrator/scrna_orchestrator.py \
66 --input <filtered_feature_bc_matrix_dir> --output <report_dir>
67
68# Direct matrix.mtx(.gz) path
69python skills/scrna-orchestrator/scrna_orchestrator.py \
70 --input <matrix.mtx.gz> --output <report_dir>
71
72
73# Demo mode
74python skills/scrna-orchestrator/scrna_orchestrator.py \
75 --demo --output <report_dir>
76
77# Optional doublet detection
78python skills/scrna-orchestrator/scrna_orchestrator.py \
79 --input <input.h5ad> --output <report_dir> \
80 --doublet-method scrublet
81
82# Optional CellTypist annotation
83python skills/scrna-orchestrator/scrna_orchestrator.py \
84 --input <input.h5ad> --output <report_dir> \
85 --annotate celltypist --annotation-model Immune_All_Low
86
87# Optional dataset-level pairwise contrasts
88python skills/scrna-orchestrator/scrna_orchestrator.py \
89 --input <input.h5ad> --output <report_dir> \
90 --contrast-groupby <obs_column> --contrast-scope dataset
91
92# Optional dataset-level + within-cluster contrasts together
93python skills/scrna-orchestrator/scrna_orchestrator.py \
94 --input <input.h5ad> --output <report_dir> \
95 --contrast-groupby <obs_column> --contrast-scope both \
96 --contrast-clusterby leiden
97
98# Optional latent downstream mode
99python skills/scrna-orchestrator/scrna_orchestrator.py \
100 --input <integrated.h5ad> --output <report_dir> \
101 --use-rep X_scvi
102
103# Via ClawBio runner
104python clawbio.py run scrna --input <input.h5ad> --output <report_dir>
105python clawbio.py run scrna --input <filtered_feature_bc_matrix_dir> --output <report_dir>
106python clawbio.py run scrna --demo
107```
108
109## Demo
110
111```bash
112python clawbio.py run scrna --demo
113python clawbio.py run scrna --demo --doublet-method scrublet
114```
115
116Expected output:
117- `report.md` with QC, clustering, markers, and optional annotation/contrast summaries
118- figure files (`qc_violin.png`, `umap_leiden.png`, `marker_dotplot.png`)
119- marker, doublet, annotation, dataset-level contrast, and within-cluster contrast tables when enabled
120- reproducibility bundle
121
122## Algorithm / Methodology
123
1241. **QC**:
125- Compute QC metrics (`n_genes_by_counts`, `total_counts`, `pct_counts_mt`)
126- Filter by `min_genes`, `min_cells`, `max_mt_pct`
1272. **Optional doublet detection**:
128- `scanpy.pp.scrublet` on QC-filtered raw counts
129- Remove predicted doublets before normalization and clustering
1303. **Preprocess**:
131- Normalize total counts to `1e4`
132- Apply `log1p`
133- Select HVGs (`flavor="seurat"`)
1344. **Embed and cluster**:
135- Scale (`max_value=10`) on the HVG branch
136- PCA, neighbors graph, UMAP
137- Leiden clustering
1385. **Markers**:
139- `scanpy.tl.rank_genes_groups(groupby="leiden", method="wilcoxon", pts=True)`
1406. **Optional annotation**:
141- Run local CellTypist on normalized/log1p full-gene expression
142- Aggregate per-cell predictions to cluster-level majority labels with support and confidence
1437. **Optional dataset-level contrasts**:
144- For every unordered pair of observed groups in `--contrast-groupby`, run `scanpy.tl.rank_genes_groups(..., groups=[group1], reference=group2, method="wilcoxon", pts=True)`
145- Export full statistics and top genes by score per pairwise comparison
1468. **Optional within-cluster contrasts**:
147- For every cluster in `--contrast-clusterby` and every unordered pair of observed groups in `--contrast-groupby`, run the same Wilcoxon contrast on the cluster subset
148- Skip cluster/comparison pairs where either side has fewer than 2 cells, and report the skipped count
149
150## Example Queries
151
152- "Run standard QC and clustering on my h5ad file"
153- "Cluster my 10x matrix.mtx directory"
154- "Find marker genes for each cluster"
155- "Generate a UMAP coloured by cluster"
156- "Remove predicted doublets before clustering"
157- "Assign putative CellTypist labels to clusters"
158- "Run all pairwise contrastive markers for treated vs control vs rescue"
159- "Find within-cluster treatment markers in each Leiden cluster"
160
161## Output Structure
162
163```text
164output_directory/
165├── report.md
166├── result.json
167├── figures/
168│ ├── qc_violin.png
169│ ├── umap_leiden.png
170│ └── marker_dotplot.png
171├── tables/
172│ ├── cluster_summary.csv
173│ ├── markers_top.csv
174│ ├── markers_top.tsv
175│ ├── doublet_summary.csv # only when doublet detection is enabled
176│ ├── cluster_annotations.csv # only when annotation is enabled
177│ ├── contrastive_markers_full.csv # only when dataset-level contrasts are enabled
178│ ├── contrastive_markers_top.csv # only when dataset-level contrasts are enabled
179│ ├── within_cluster_contrastive_markers_full.csv # only when within-cluster contrasts are enabled
180│ └── within_cluster_contrastive_markers_top.csv # only when within-cluster contrasts are enabled
181└── reproducibility/
182 ├── commands.sh
183 ├── environment.yml
184 └── checksums.sha256
185```
186
187## Dependencies
188
189**Required**:
190- `scanpy` >= 1.10
191- `anndata` >= 0.10
192- `scipy`
193- `numpy`, `pandas`, `matplotlib`, `leidenalg`, `python-igraph`
194
195**Optional**:
196- `scrublet` for `--doublet-method scrublet`
197- `celltypist` for `--annotate celltypist`
198
199**Out of scope**:
200- `scvi-tools` / `scANVI`
201
202## Safety
203
204- **Local-first**: No patient data upload.
205- **Disclaimer**: Reports include the ClawBio medical disclaimer.
206- **Input guardrails**: Rejects processed-like matrices to reduce invalid biological inferences.
207- **Annotation caution**: CellTypist labels are **putative** and model-dependent, not definitive biology.
208- **Model downloads**: Runtime CellTypist model downloads are intentionally disabled.
209- **Reproducibility**: Writes command/environment/checksum bundle.
210
211## Integration with Bio Orchestrator
212
213**Trigger conditions**:
214- File extension `.h5ad`, `.mtx`, or `.mtx.gz`
215- User intent includes scRNA terms (single-cell, Scanpy, clustering, marker genes, contrastive markers, doublets, annotation)
216
217**Current limitations**:
218- Raw-count `.h5ad` and 10x Matrix Market only
219- CellTypist support is human-model focused and requires a locally installed model
220
221## Status
222
223**MVP implemented** -- supports `.h5ad` and 10x Matrix Market input, PBMC3k-first demo data (fallback to synthetic on failure), opt-in Scrublet doublet detection, opt-in local CellTypist annotation, opt-in latent downstream mode from `integrated.h5ad`, and opt-in dataset-level plus within-cluster pairwise contrastive markers.
224
225## Citations
226
227- [Scanpy documentation](https://scanpy.readthedocs.io/) — analysis API and methods.
228- [AnnData documentation](https://anndata.readthedocs.io/) — data model.
229- [Leiden algorithm paper](https://www.nature.com/articles/s41598-019-41695-z) — community detection.
230- [Scrublet paper](https://genomebiology.biomedcentral.com/articles/10.1186/s13059-019-1736-8) — computational doublet detection.
231- [CellTypist documentation](https://www.celltypist.org/) — model-based immune and general cell annotation.