Scrna preprocessing clustering

From zongtingwei/Bioclaw_Skills_Hub · View interactive version

Scrna preprocessing clustering is an AI agent skill from the GitHub repository zongtingwei/Bioclaw_Skills_Hub. Standard scRNA-seq preprocessing and clustering with Scanpy. Use for QC, normalization, HVG selection, PCA, neighbor graph construction, UMAP, Leiden clustering, and export of an analysis-ready AnnData object.

How to use this skill

Skill file

scRNA Preprocessing And Clustering

Version Compatibility

Reference examples assume:

Before using code patterns, verify installed versions match the environment:

Overview

Use this skill to turn raw or minimally processed scRNA-seq data into an analysis-ready object with:

When To Use This Skill

Quick Route

Progressive Disclosure

Default Rules

Expected Inputs

Expected Outputs

Preferred Tools

Starter Pattern

import scanpy as sc

adata = sc.read_10x_mtx("counts/")
adata.var_names_make_unique()
adata.var["mt"] = adata.var_names.str.upper().str.startswith("MT-")
sc.pp.calculate_qc_metrics(adata, qc_vars=["mt"], inplace=True)

adata = adata[
    (adata.obs["n_genes_by_counts"] >= 200)
    & (adata.obs["n_genes_by_counts"] <= 6000)
    & (adata.obs["pct_counts_mt"] < 15),
    :
].copy()

sc.pp.filter_genes(adata, min_cells=3)
sc.pp.normalize_total(adata, target_sum=1e4)
sc.pp.log1p(adata)
adata.raw = adata.copy()

sc.pp.highly_variable_genes(adata, n_top_genes=3000, flavor="seurat_v3")
adata = adata[:, adata.var["highly_variable"]].copy()
sc.pp.scale(adata, max_value=10)
sc.tl.pca(adata, svd_solver="arpack")
sc.pp.neighbors(adata, n_neighbors=15, n_pcs=30)
sc.tl.umap(adata)
sc.tl.leiden(adata, resolution=0.5, key_added="leiden_r05")
adata.write("results/processed.h5ad")

Workflow

1. Load and validate the object

2. Compute QC metrics and inspect distributions

Plot distributions before filtering. Thresholds vary by chemistry, tissue, and nucleus versus whole-cell assay.

3. Filter cells and genes

Use dataset-aware thresholds. Good first-pass defaults:

4. Normalize, log-transform, and select HVGs

5. Reduce dimensions and cluster

6. Export analysis-ready artifacts

Always save:

Output Artifacts

Quality Review

Anti-Patterns

Related Skills

Optional Supplements

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.