K-Dense-AI/scientific-agent-skills / skills/scanpy
scanpy
VerifiedPerforms 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.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 19.8 KB |
| assets/analysis_template.py | script | 10.0 KB |
| assets/celltype_mapping.json | config | 184 B |
| assets/gene_signatures.json | config | 355 B |
| assets/pipeline_config.json | config | 380 B |
| references/analysis_workflow.md | markdown | 7.6 KB |
| references/api_reference.md | markdown | 9.1 KB |
| references/plotting_guide.md | markdown | 10.5 KB |
| references/r_interop.md | markdown | 11.8 KB |
| references/standard_workflow.md | markdown | 7.0 KB |
| references/upstream-review.md | markdown | 8.3 KB |
| scripts/_common.py | script | 10.0 KB |
| scripts/annotate.py | script | 3.7 KB |
| scripts/batch_correct.py | script | 3.1 KB |
| scripts/cluster.py | script | 2.5 KB |
| scripts/convert.py | script | 1.5 KB |
| scripts/find_markers.py | script | 4.3 KB |
| scripts/inspect_data.py | script | 3.1 KB |
| scripts/plot.py | script | 3.6 KB |
| scripts/preprocess.py | script | 3.5 KB |
| scripts/pseudobulk.py | script | 4.6 KB |
| scripts/qc_analysis.pyexecutable | script | 5.1 KB |
| scripts/reduce_dimensions.py | script | 2.8 KB |
| scripts/run_pipeline.py | script | 9.4 KB |
| scripts/score_genes.py | script | 3.9 KB |
| scripts/subset.py | script | 2.6 KB |
scripts/preprocess.py
View on GitHub#!/usr/bin/env python3
"""
Normalize, log-transform, select highly variable genes, and optionally scale.
Takes QC-filtered raw counts and produces a normalized, log1p-transformed
object ready for dimensionality reduction. A copy of the raw counts is kept in
``adata.layers['counts']`` and the normalized log values in ``adata.raw`` so
downstream marker/expression plots can use ``use_raw=True``.
Examples:
python preprocess.py filtered.h5ad -o normalized.h5ad
python preprocess.py filtered.h5ad -o normalized.h5ad --n-top-genes 3000 --scale
python preprocess.py filtered.h5ad -o normalized.h5ad --flavor seurat_v3 --batch-key sample
python preprocess.py filtered.h5ad -o normalized.h5ad --regress-out total_counts pct_counts_mt
"""
import argparse
from _common import add_io_args, configure_scanpy, info, load_anndata, save_anndata, prepare_counts, normalize_hvg
def main():
p = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
add_io_args(p, default_output="normalized.h5ad")
p.add_argument("--counts-layer", default=None, help="Explicit raw-count layer instead of X")
p.add_argument("--target-sum", type=float, default=1e4,
help="Counts per cell after normalization (default 1e4)")
p.add_argument("--n-top-genes", type=int, default=2000,
help="Number of highly variable genes (default 2000)")
p.add_argument("--flavor", default="seurat",
choices=["seurat", "cell_ranger", "seurat_v3", "seurat_v3_paper"],
help="HVG flavor. seurat_v3 expects raw counts (default seurat)")
p.add_argument("--batch-key", default=None,
help="obs column for batch-aware HVG selection")
p.add_argument("--subset-hvg", action="store_true",
help="Subset the matrix to HVGs (smaller, but drops other genes from X)")
p.add_argument("--regress-out", nargs="+", default=None,
help="obs columns to regress out (e.g. total_counts pct_counts_mt)")
p.add_argument("--scale", action="store_true",
help="Scale to unit variance and zero mean (max_value=10)")
p.add_argument("--no-plots", action="store_true", help="Skip HVG plot")
args = p.parse_args()
sc = configure_scanpy(figdir=args.figdir)
adata = load_anndata(args.input)
info(f"Loaded {adata.n_obs} cells x {adata.n_vars} genes")
prepare_counts(adata, args.counts_layer)
normalize_hvg(sc, adata, target_sum=args.target_sum, n_top_genes=args.n_top_genes,
flavor=args.flavor, batch_key=args.batch_key)
n_hvg = int(adata.var["highly_variable"].sum())
info(f"Selected {n_hvg} highly variable genes")
# Stash the full normalized log matrix so plots can use_raw=True.
# normalize_hvg saved an independent full log-normalized snapshot.
if not args.no_plots:
sc.pl.highly_variable_genes(adata, show=False, save="_hvg.png")
if args.subset_hvg:
info("HVG subsetting also subsets counts; retain the full-gene input for pseudobulk")
adata = adata[:, adata.var["highly_variable"]].copy()
info(f"Subset to {adata.n_vars} HVGs")
if args.regress_out:
info(f"Regressing out: {', '.join(args.regress_out)}")
sc.pp.regress_out(adata, args.regress_out)
if args.scale:
info("Scaling (max_value=10)")
sc.pp.scale(adata, max_value=10)
save_anndata(adata, args.output)
if __name__ == "__main__":
main()
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |