harmony-batch-correction
Harmony batch correction for scRNA-seq and other omics. Removes batch effects from PCA embeddings while preserving biology. Run after PCA, before UMAP. Scales to millions of cells. Python (harmonypy, scanpy) and R (Seurat).
npx skills add BioTender-max/awesome-bio-agent-skills --skill harmony-batch-correction --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
What it does
Harmony batch correction takes a PCA embedding (cells × PCs) and returns a corrected embedding with batch effects regressed out via iterative soft-clustering and per-cluster linear regression. The corrected embedding is then used to compute neighbors, UMAP, and downstream clustering, without modifying the raw counts. It is applicable to scRNA-seq, ATAC-seq, and other omics modalities that provide a PCA-like embedding. The skill covers various integration scenarios and recommends alternative methods for probabilistic, graph-based, or Seurat-based workflows.
How it works
The skill describes running Harmony in three modes:
- Via Scanpy integration: sc.external.pp.harmony_integrate modifies adata.obsm["X_pca"] in place and stores corrected results in adata.obsm["X_pca_harmony"], followed by building a neighbor graph on the corrected embedding and computing UMAP and Leiden clustering.
- Via harmonypy directly: uses harmonypy.run_harmony on the PCA embedding with a metadata DataFrame for variables to correct (e.g., batch); stores corrected embedding in adata.obsm["X_pca_harmony"].
- R integration with Seurat: RunHarmony adds a corrected reduction ("harmony"), then FindNeighbors, FindClusters, and RunUMAP using that reduction. Key steps include preparing an AnnData object with PCA already computed, selecting the columns for batch correction, and then downstream visualization and clustering on the corrected embedding.
When to use it
Use Harmony when integrating multiple scRNA-seq datasets across samples, donors, sequencing runs, or technical batches to remove batch variation while preserving biology. It is suitable for large datasets (millions of cells) and supports correcting for multiple confounding variables. The workflow favors using the corrected embedding for neighborhood graph construction and visualization rather than altering the gene expression matrix.
What it can touch
The tool interacts with:
- Python environment and packages: harmonypy, scanpy, anndata, pandas, matplotlib (explicit in prerequisites).
- Data structures: adata.obsm keys "X_pca" and "X_pca_harmony"; adata.obs with batch metadata; adata.layers["counts"] for raw counts storage.
- Optional R workflow: Seurat objects and RunHarmony via Seurat harmony integration.
Caveats
The skill notes that Harmony corrects the embedding, not the count matrix, and that differential expression should rely on raw or normalized counts. It also mentions that HVG selection and PCA should be batch-aware in Scanpy (batch_key usage). The text provides guidance on parameter options (theta, sigma, nclust, max_iter_harmony, tau, etc.) and warnings about potential over-correction in multi-variable scenarios. No licensing or usage restrictions beyond MIT in the provided material.
# Harmony Batch Correction ## Overview Harmony is a fast, scalable algorithm for batch integration in single-cell data. It takes a PCA embedding (cells × PCs) as input and returns a corrected embedding from which batch effects have been regressed out via iterative soft-clustering and per-cluster linear regression. The corrected embedding is then used to compute neighbors, UMAP, and downstream clustering — the raw count matrix is never modified. Harmony works for single-cell RNA-seq, ATAC-seq, and other omics modalities where a PCA-like embedding is available. ## When to Use - Integrating scRNA-seq datasets from different samples, donors, sequencing runs, or experimental batches that should contain the same cell types - Removing technical variation (library preparation protocol, 10x chemistry version, sequencing depth, sequencing platform) while preserving biological differences between cell types and conditions - Performing fast, scalable batch correction on datasets with millions of cells where deep generative model training would be prohibitively slow - Correcting for multiple confounding variables simultaneously (batch, donor, sequencing platform, tissue processing protocol) - P
- Overview
- When to Use
- Prerequisites
- Quick Start
- Workflow
- Step 1: Quality Control and Preprocessing
- Step 2: Run Harmony via Scanpy Integration
- Step 3: Run Harmony via harmonypy Directly
- Step 4: Compute Neighbors and UMAP on Harmony Embedding
- Step 5: Leiden Clustering on Harmony-Corrected Graph
- Step 6: Evaluate Batch Correction
- Step 7: R Integration with Seurat
- Key Parameters
- Key Concepts
pip install harmonypy "scanpy[leiden]" anndata pandas matplotlib
What does the harmony-batch-correction skill do?
Harmony batch correction for scRNA-seq and other omics. Removes batch effects from PCA embeddings while preserving biology. Run after PCA, before UMAP. Scales to millions of cells. Python (harmonypy, scanpy) and R (Seurat).
How do I install it?
Run `npx skills add BioTender-max/awesome-bio-agent-skills --skill harmony-batch-correction --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From BioTender-max/awesome-bio-agent-skills, a repository with 144 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
