Harmony is an iterative clustering algorithm that projects cells from multiple batches into a shared embedding where it softly clusters cells by both cell type and dataset of origin to correct for batch effects in single-cell RNA sequencing data. Unlike methods that rely on identifying mutual nearest neighbors (MNN) or a single reference batch, Harmony uses a probabilistic clustering model that iteratively estimates a dataset-specific linear correction factor for each cell, pushing cells from different batches toward shared cluster centroids while preserving genuine biological variation.
Glossary
Harmony

What is Harmony?
Harmony is an iterative algorithm for integrating single-cell RNA sequencing datasets that projects cells into a shared, low-dimensional embedding while simultaneously clustering them by cell type and dataset of origin to correct for batch effects.
The algorithm begins with a low-dimensional embedding, typically from Principal Component Analysis (PCA) , and alternates between two steps: maximum-likelihood clustering of cells using a soft k-means framework and estimating a batch-specific linear correction for each cluster. This correction is applied to the cell embeddings, and the process repeats until convergence. Harmony's performance is often evaluated using the Local Inverse Simpson's Index (LISI) , which quantifies the effective number of datasets in a cell's local neighborhood, with a high integration LISI score indicating successful mixing of batches without overcorrection that would obscure true cell-type distinctions.
Key Features of Harmony
Harmony is an iterative algorithm that projects single-cell RNA-seq data into a shared, batch-corrected embedding. It uses a novel soft-clustering strategy that groups cells by both cell type and dataset of origin, then applies a dataset-specific linear correction to align populations.
Soft k-Means Clustering
Harmony uses a soft k-means clustering approach that assigns cells to multiple clusters probabilistically rather than making hard assignments. This allows cells to belong to a cell-type cluster and a dataset-specific cluster simultaneously.
- Penalizes clusters that are dominated by a single dataset
- Encourages mixing of cells from different batches within each cluster
- The soft assignment matrix is used to compute a maximum diversity clustering
Maximum Diversity Clustering
The algorithm applies a diversity penalty to the soft clustering objective. For each cluster, Harmony calculates the proportion of cells from each dataset and penalizes clusters where one dataset dominates.
- Uses an entropy-based regularization term
- The penalty strength is controlled by a parameter theta (θ)
- High theta forces aggressive mixing; low theta preserves biological structure
- This prevents the algorithm from simply grouping cells by batch
Linear Mixture Model Correction
Once cells are softly clustered, Harmony estimates a dataset-specific linear correction factor for each cluster. The correction is computed as the difference between the cluster centroid and the dataset-specific centroid within that cluster.
- Correction is a simple shift vector applied to each cell
- Preserves the relative distances between cells within a cluster
- Avoids the overcorrection problems of global alignment methods
- Correction is applied iteratively until convergence
Iterative Expectation-Maximization
Harmony operates in an expectation-maximization (EM) framework that alternates between two steps until convergence:
- E-step: Softly assign cells to clusters based on current corrected coordinates
- M-step: Re-estimate cluster centroids and dataset-specific correction factors
- Typically converges in 5-10 iterations
- The algorithm is deterministic given the same initialization
- Output is a batch-corrected embedding matrix suitable for downstream analysis
Integration Metrics
Harmony's performance is evaluated using quantitative metrics that assess both batch mixing and biological preservation:
- Local Inverse Simpson's Index (LISI): Measures the effective number of datasets in each cell's local neighborhood. A high integration LISI (iLISI) indicates good mixing
- Average Silhouette Width (ASW): Evaluates whether cells of the same type remain close together after correction
- kBET acceptance rate: Tests whether the local batch distribution matches the global distribution
- Harmony consistently achieves near-1.0 kBET acceptance rates on benchmark datasets
Scalability and Performance
Harmony is designed for large-scale single-cell datasets with hundreds of thousands to millions of cells. Its linear-time complexity makes it suitable for atlas-scale integration projects.
- Runtime scales linearly O(N) with the number of cells
- Processes 100,000 cells in under 2 minutes on standard hardware
- Implemented in both R (harmony package) and Python (harmonypy)
- Integrates seamlessly with Seurat, Scanpy, and SingleCellExperiment workflows
- Memory-efficient implementation uses sparse matrix operations
Harmony vs. Other Batch Correction Methods
A feature-level comparison of Harmony against widely used batch correction algorithms for single-cell RNA sequencing data integration.
| Feature | Harmony | Seurat Integration | MNN | Scanorama | BBKNN |
|---|---|---|---|---|---|
Core Algorithm | Iterative soft k-means clustering in PCA space | CCA-based anchor identification and integration | Mutual nearest neighbor detection and correction vector estimation | Panoramic stitching via pairwise MNN matching | Batch-balanced k-nearest neighbor graph construction |
Input Data | PCA embeddings | Normalized expression matrix | High-dimensional expression space | Normalized expression matrix | PCA or expression matrix |
Scalability | Linear in cell number; handles 10^6 cells | Moderate; anchor finding is computationally intensive | O(N^2) pairwise distance calculations | O(N^2) pairwise comparisons across all datasets | Efficient; approximate nearest neighbors via annoy |
Preserves Batch Structure | |||||
Output Type | Corrected PCA embeddings | Integrated expression matrix and corrected embeddings | Corrected expression matrix | Corrected expression matrix | Corrected kNN graph only |
Requires Cell Type Labels | |||||
Handles >2 Batches Natively | |||||
Runtime for 100k Cells | < 1 min | 5-15 min | 10-30 min | 30-60 min | < 1 min |
Sensitivity to Batch Order |
Frequently Asked Questions
Clarifying the mechanics, applications, and evaluation of the Harmony algorithm for robust single-cell data integration.
The Harmony algorithm is an iterative process that projects single-cell RNA sequencing data into a shared, batch-corrected embedding by softly clustering cells using both cell-type identity and dataset-of-origin labels. It begins with a low-dimensional representation, such as from Principal Component Analysis (PCA) , and iteratively refines it. In each iteration, Harmony performs a soft k-means clustering that groups cells by their transcriptional similarity while penalizing clusters that are dominated by a single batch. It then calculates a linear, dataset-specific correction factor for each cluster and moves each cell toward the cluster centroid by its batch-specific factor. This process repeats until convergence, effectively removing the technical variation introduced by different experimental batches while preserving the true biological heterogeneity between distinct cell types and states.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Core concepts, algorithms, and evaluation metrics that form the computational foundation for removing technical variation while preserving biological signals in single-cell data.
Batch Effect
A systematic non-biological source of variation introduced across different experimental batches—such as different processing dates, reagents, or technicians—that can confound downstream analysis. In single-cell RNA sequencing, batch effects manifest as global shifts in gene expression distributions that obscure true biological differences. If uncorrected, they can lead to spurious clustering where cells group by batch rather than by cell type, producing false discoveries in differential expression and trajectory analyses.
Mutual Nearest Neighbors (MNN)
A batch correction method that identifies pairs of cells from different batches that are mutual nearest neighbors in high-dimensional expression space. These MNN pairs are assumed to represent the same biological cell type and are used to estimate a correction vector that is then applied to all cells. The method is robust to differences in cell-type composition between batches and does not require a shared gene set, making it suitable for cross-platform integration scenarios.
Local Inverse Simpson's Index (LISI)
A diversity score computed for each cell's local neighborhood that quantifies the effective number of different batches (iLISI) or cell types (cLISI) present. An iLISI score approaching the total number of batches indicates perfect mixing, while a cLISI score of 1.0 indicates that a neighborhood contains only one cell type. Used together, these metrics provide a dual assessment of integration quality—confirming that batches are mixed while cell-type purity is preserved.
Overcorrection Assessment
The process of evaluating whether a batch correction method has removed true biological variation alongside technical noise. Overcorrection occurs when algorithms aggressively align cells from different batches, erasing meaningful biological distinctions such as rare cell populations or subtle activation states. Assessment typically involves measuring the preservation of known cell-type clusters, the variance explained by biological covariates, and the recovery of expected marker gene expression patterns post-correction.
Batch Confounding
A critical experimental design flaw where the batch variable is perfectly correlated with the biological condition of interest. For example, if all control samples are processed on Monday and all treatment samples on Tuesday, it becomes statistically impossible to separate technical artifacts from the true biological signal. No computational method can fully rescue a confounded design; the only solution is proper randomization of conditions across batches during experimental planning.
Residual Batch Effect
Systematic technical variation that remains in a dataset after an initial batch correction procedure has been applied. Residual effects often indicate incomplete modeling of the experimental design—such as unaccounted-for covariates like sample processing time or reagent lot numbers. Detection typically involves visualizing post-correction data with dimensionality reduction and applying quantitative metrics like kBET; significant residual effects may require a secondary, post-hoc correction step or revisiting the original model specification.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us