scrna-seq-pipeline
Skill76 starsChanged 5 months agoMIT-0View on GitHub
Scanpy-based single-cell RNA-seq analysis pipeline covering loading (10X, h5ad), QC, normalization, HVG selection, PCA/UMAP, Leiden clustering, differential expression, and batch correction (Harmony, scVI). Use when the user mentions single-cell, scRNA-seq, Scanpy, AnnData, UMAP, clustering, 10X, h5ad, leiden, highly variable genes, Harmony, scVI, cluster cells, find marker genes, filter low-quality cells, gene expression matrix, doublet removal, normalize counts, dimensionality reduction, cell clustering, QC single-cell, filtered_feature_bc_matrix, cellranger output, 10X h5, scrublet, cell ranger, count matrix, find cell types, batch effect, integration, neighborhood graph, or differential expression genes.
- Installs packages
1 other project uses a version of this.
Adopted by
Most recently taken up by
- zh123012/claude-skillstheir own version, first seen Jul 29, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- zh123012/claude-skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository42 other files it gives its agents.
- aws-genai-ml-architectSkill
- bioinformatics-on-healthomicsSkill
- biomarker-discoverySkill
- cdisc-complianceSkill
- cell-type-annotationSkill
- cheminformaticsSkill
- claims-analyticsSkill
- claims-billing-rulesSkill
- clinical-data-standardsSkill
- coordination-of-benefitsSkill
- dicom-processingSkill
- digital-pathologySkill
- drug-repurposingSkill
- edc-data-validationSkill
- ehr-data-parsingSkill
- genomic-variant-interpretationSkill
- hedis-measure-specificationSkill
- imaging-study-designSkill
- medical-device-software-complianceSkill
- ml-researcherSkill
- molecular-dockingSkill
- multi-omics-integrationSkill
- multi-omics-pipelineSkill
- ngs-quality-controlSkill
- pa-clinical-policySkill
- pa-decision-automationSkill
- pharmacoepidemiologySkill
- protein-structure-analysisSkill
- provider-denial-workupSkill
- quality-measuresSkill
- quantitative-proteomicsSkill
- radiology-preprocessingSkill
- risk-adjustmentSkill
- risk-adjustment-strategySkill
- risk-stratification-indicesSkill
- rna-seq-analysisSkill
- roda-open-dataSkill
- rwd-cohort-analysisSkill
- structure-based-drug-designSkill
- trajectory-analysisSkill
- translational-researchSkill
- variant-callingSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 2 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 28
Run the pipeline end-to-end:
- Distinctive: line 107
Keep code comments minimal and functional (what, not why-it-exists)
- Very specific: line 115
HVG flavor matters: Use flavor="seurat" on log-normalized data (default).
- Very specific: line 169
Right: Always set .raw on the log-normalized full matrix before adata = adata[:, adata.var.highly_variable].copy()
- Very specific: line 177
Right: Call adata.var_names_make_unique() immediately after loading
- Very specific: line 185
Right: Use MT- for human genes and mt- for mouse genes
- Very specific: line 189
Right: Always use .copy() after filtering: adata = adata[mask, :].copy()
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
scRNA-seq Pipeline (Scanpy)
Overview
This skill produces a reproducible scRNA-seq analysis in Python using Scanpy and AnnData. It covers the standard workflow: load counts → QC filter → normalize/log → HVG → scale/PCA → neighbors/UMAP → Leiden → differential expression, plus batch correction with Harmony or scVI. Default parameters follow the Scanpy PBMC3k tutorial conventions and are safe starting points for most 10X Genomics datasets.
Output is a single .h5ad file with all intermediate embeddings, cluster labels, and DE results stored on the AnnData object.
Usage
Install dependencies:
pip install "scanpy>=1.10" anndata leidenalg python-igraph harmonypy scvi-toolsRun the pipeline end-to-end:
import scanpy as sc
import scanpy.external as sce
sc.settings.verbosity = 2
sc.settings.set_figure_params(dpi=100, facecolor="white")
# 1. Load
adata = sc.read_10x_h5("filtered_feature_bc_matrix.h5")
# Alternatives:
# adata = sc.read_10x_mtx("filtered_feature_bc_matrix/", var_names="gene_symbols", cache=True)
# adata = sc.read_h5ad("input.h5ad")
adata.var_names_make_unique()
# 2. QC
adata.var["mt"] = adata.var_names.str.startswith("MT-")
sc.pp.calculate_qc_metrics(adata, qc_vars=["mt"], percent_top=None, log1p=False, inplace=True)
sc.pp.filter_cells(adata, min_genes=200)
sc.pp.filter_genes(adata, min_cells=3)
adata = adata[adata.obs.n_genes_by_counts < 5000, :]
adata = adata[adata.obs.pct_counts_mt < 20, :].copy()
# 3. Normalize + HVG
sc.pp.normalize_total(adata, target_sum=1e4)
sc.pp.log1p(adata)
adata.raw = adata # freeze log-normalized full gene set BEFORE HVG subset
sc.pp.highly_variable_genes(adata, n_top_genes=2000, flavor="seurat")
adata = adata[:, adata.var.highly_variable].copy()
# 4. Scale + PCA + neighbors + UMAP + Leiden
sc.pp.scale(adata, max_value=10)
sc.tl.pca(adata, n_comps=50, svd_solver="arpack")
sc.pp.neighbors(adata, n_neighbors=15, n_pcs=30)
sc.tl.umap(adata)
sc.tl.leiden(adata, resolution=0.5)
# 5. Differential expression per cluster
sc.tl.rank_genes_groups(adata, groupby="leiden", method="wilcoxon")
# 6. Save
adata.write("result.h5ad", compression="gzip")Batch correction — Harmony
# Assumes adata.obs["batch"] exists and PCA is already computed.
sce.pp.harmony_integrate(adata, key="batch") # writes adata.obsm["X_pca_harmony"]
sc.pp.neighbors(adata, n_neighbors=15, n_pcs=30, use_rep="X_pca_harmony")
sc.tl.umap(adata)
sc.tl.leiden(adata, resolution=0.5)Batch correction — scVI
scVI requires raw counts. Run it before normalization, or keep a raw-count layer.
import scvi
# adata_raw holds unnormalized integer counts; adata.obs["batch"] is the batch key.
scvi.model.SCVI.setup_anndata(adata_raw, batch_key="batch")
model = scvi.model.SCVI(adata_raw, n_latent=30)
model.train(max_epochs=400, early_stopping=True)
adata.obsm["X_scVI"] = model.get_latent_representation()
sc.pp.neighbors(adata, n_neighbors=15, use_rep="X_scVI")
sc.tl.umap(adata)
sc.tl.leiden(adata, resolution=0.5)Response Format
- Lead with the command or code the user needs — explain after
- Structure as: confirm inputs → working code → key parameters explained → gotchas
- One complete working example per task; do not show every alternative
- Keep code comments minimal and functional (what, not why-it-exists)
- Target: 50-100 lines of code with brief surrounding explanation
Core Concepts
- AnnData layout.
adata.Xis the current expression matrix (cells × genes).adata.obsholds per-cell metadata (QC metrics, cluster labels, batch).adata.varholds per-gene metadata (HVG flags,mt). Embeddings live inadata.obsm(X_pca,X_umap,X_scVI). Neighbor graph and DE results live inadata.uns. .rawsnapshot.adata.raw = adatastores the full log-normalized matrix before HVG subsetting. Downstream plotting functions (sc.pl.umap(..., color="GENE"),sc.pl.rank_genes_groups) read from.rawso you can visualize any gene even after restrictingadatato HVGs.- QC thresholds are dataset-dependent.
n_genes ∈ [200, 5000]andpct_mt < 20are reasonable defaults for human 10X PBMC-like data. Inspect distributions (sc.pl.violin) before committing. UseMT-for human andmt-for mouse. - HVG flavor matters. Use
flavor="seurat"on log-normalized data (default). Useflavor="seurat_v3"on raw counts — it expects integer counts and will error or mislead on log data. - Neighbors parameters.
n_neighborscontrols local/global structure (10–50; larger = smoother UMAP).n_pcsshould capture the elbow insc.pl.pca_variance_ratio(typically 20–50). Leidenresolutioncontrols cluster granularity (0.2–1.5; higher = more clusters). - Batch correction choice. Harmony is fast, operates on PCA, and works well for mild-to-moderate batch effects. scVI is a deep generative model, needs raw counts and GPU for speed, and handles stronger technical variation and multi-modal designs.
Quick Reference
Loading
| Input | Call |
| 10X HDF5 | sc.read_10x_h5("filtered_feature_bc_matrix.h5") |
| 10X MTX dir | sc.read_10x_mtx("path/", var_names="gene_symbols", cache=True) |
| Existing AnnData | sc.read_h5ad("input.h5ad") |
| Always after load | adata.var_names_make_unique() |
Key parameter ranges
| Parameter | Default | Typical range | Notes |
filter_cells(min_genes=) | 200 | 100–500 | Drop empty/low-quality droplets |
filter_genes(min_cells=) | 3 | 3–10 | Drop rarely-expressed genes |
n_genes_by_counts < | 5000 | 2500–8000 | Upper bound flags doublets |
pct_counts_mt < | 20 | 5–25 | Human tissue dependent |
normalize_total(target_sum=) | 1e4 | 1e4 | CP10k; standard |
n_top_genes (HVG) | 2000 | 1000–5000 | More HVGs → more signal + noise |
scale(max_value=) | 10 | 10 | Clip extreme z-scores |
pca(n_comps=) | 50 | 30–100 | Pick elbow for downstream n_pcs |
neighbors(n_neighbors=) | 15 | 10–50 | Larger → smoother manifold |
neighbors(n_pcs=) | 30 | 20–50 | ≤ n_comps |
leiden(resolution=) | 0.5 | 0.2–1.5 | Higher → more clusters |
DE & inspection
sc.tl.rank_genes_groups(adata, groupby="leiden", method="wilcoxon")
sc.pl.rank_genes_groups(adata, n_genes=25, sharey=False)
# Top-N markers per cluster as a DataFrame
import pandas as pd
result = adata.uns["rank_genes_groups"]
groups = result["names"].dtype.names
markers = pd.DataFrame({g: result["names"][g][:20] for g in groups})Saving / loading
adata.write("result.h5ad", compression="gzip")
adata = sc.read_h5ad("result.h5ad")Common Mistakes
- Wrong: Subsetting to HVGs before saving
adata.raw = adataRight: Always set.rawon the log-normalized full matrix beforeadata = adata[:, adata.var.highly_variable].copy()Why: Without.raw, you lose the ability to plot or score non-HVG genes in downstream analysis - Wrong: Using
flavor="seurat_v3"on log-normalized data Right: Match HVG flavor to data state:seurat_v3requires raw integer counts;seurat(default) requires log-normalized data Why: Wrong flavor produces nonsense HVG rankings or errors, corrupting all downstream steps - Wrong: Skipping
adata.var_names_make_unique()after loading 10X data Right: Calladata.var_names_make_unique()immediately after loading Why: Duplicated gene symbols cause silent misbehavior in indexing, HVG selection, and DE analysis - Wrong: Running scVI on normalized/log-transformed data
Right: Feed scVI the raw-count AnnData and set
batch_keyviasetup_anndataWhy: scVI models counts directly; normalized input violates its distributional assumptions and produces incorrect latent spaces - Wrong: Using
MT-prefix for mouse mitochondrial genes (ormt-for human) Right: UseMT-for human genes andmt-for mouse genes Why: Wrong prefix makespct_counts_mtalways zero, rendering the QC filter a no-op - Wrong: Boolean-slicing AnnData without calling
.copy()Right: Always use.copy()after filtering:adata = adata[mask, :].copy()Why: Without.copy(), the result is a view; subsequent in-place operations will warn or fail
References
- Scanpy: Wolf et al. Genome Biol 2018, https://doi.org/10.1186/s13059-017-1382-0
- Scanpy tutorials: https://scanpy.readthedocs.io/en/stable/tutorials.html
- scVI: Gayoso et al. Nat Biotechnol 2022, https://doi.org/10.1038/s41587-021-01206-w
- Harmony: Korsunsky et al. Nat Methods 2019, https://doi.org/10.1038/s41592-019-0619-0
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

