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/annotate.py
View on GitHub#!/usr/bin/env python3
"""
Annotate clusters with cell-type labels from a mapping file.
Maps a cluster column (e.g. leiden) to cell-type names using a JSON or CSV
mapping, writes the labels into a new obs column, and saves a UMAP and dotplot.
The mapping file is one of:
* JSON : {"0": "CD4 T cells", "1": "B cells", ...}
* CSV : two columns ``cluster,cell_type``
Optionally provide a marker-gene JSON to draw a reference dotplot that helps
decide the mapping:
{"T cells": ["CD3D","CD3E"], "B cells": ["MS4A1","CD79A"]}
Examples:
python annotate.py clustered.h5ad -o annotated.h5ad --mapping celltypes.json
python annotate.py clustered.h5ad -o annotated.h5ad --mapping map.csv --cluster-key leiden
python annotate.py clustered.h5ad --markers markers.json --cluster-key leiden # dotplot only
"""
import argparse
import json
import os
from _common import add_io_args, configure_scanpy, die, info, load_anndata, save_anndata
def load_mapping(path):
if path.lower().endswith(".json"):
with open(path) as fh:
return {str(k): v for k, v in json.load(fh).items()}
import pandas as pd
df = pd.read_csv(path, dtype=str, keep_default_na=False)
if df.shape[1] < 2:
die("CSV mapping needs at least two columns: cluster,cell_type")
if df.iloc[:, 0].duplicated().any():
die("CSV mapping contains duplicate cluster labels")
return {str(k): v for k, v in zip(df.iloc[:, 0], df.iloc[:, 1])}
def main():
p = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
add_io_args(p, default_output="annotated.h5ad")
p.add_argument("--cluster-key", default="leiden", help="obs column with clusters (default leiden)")
p.add_argument("--mapping", default=None, help="JSON or CSV cluster->cell_type mapping")
p.add_argument("--label-key", default="cell_type", help="New obs column name (default cell_type)")
p.add_argument("--markers", default=None,
help="JSON of {cell_type: [genes]} to draw a reference dotplot")
p.add_argument("--no-plots", action="store_true", help="Skip plots")
args = p.parse_args()
sc = configure_scanpy(figdir=args.figdir)
adata = load_anndata(args.input)
if args.cluster_key not in adata.obs.columns:
die(f"cluster key '{args.cluster_key}' not in obs: {list(adata.obs.columns)}")
if args.markers:
with open(args.markers) as fh:
marker_dict = json.load(fh)
present = {ct: [g for g in genes if g in (adata.raw.var_names if adata.raw is not None else adata.var_names)]
for ct, genes in marker_dict.items()}
present = {ct: g for ct, g in present.items() if g}
if present and not args.no_plots:
sc.pl.dotplot(adata, present, groupby=args.cluster_key,
use_raw=adata.raw is not None, show=False, save="_marker_reference.png")
info("Wrote marker reference dotplot")
if args.mapping:
mapping = load_mapping(args.mapping)
adata.obs[args.label_key] = (
adata.obs[args.cluster_key].astype(str).map(mapping).fillna("Unknown").astype("category")
)
info(f"Annotated '{args.label_key}': "
+ ", ".join(f"{k}={v}" for k, v in adata.obs[args.label_key].value_counts().items()))
if not args.no_plots:
sc.pl.umap(adata, color=args.label_key, legend_loc="on data",
show=False, save="_celltypes.png")
save_anndata(adata, args.output)
elif not args.markers:
die("provide --mapping (to annotate) and/or --markers (for a reference dotplot)")
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 |