Inferensys

Glossary

Harmony

An iterative algorithm that integrates single-cell RNA-seq data by soft-clustering cells and applying a mixture model-based correction to harmonize diverse datasets in a shared embedding.
ML engineer managing model training cluster on laptop, GPU utilization visible, technical deep learning setup.
SINGLE-CELL DATA INTEGRATION

What is Harmony?

Harmony is an iterative algorithm for integrating single-cell RNA-seq data that uses soft clustering and a mixture model-based correction to project diverse datasets into a shared, batch-corrected embedding.

Harmony is an algorithm that integrates single-cell RNA-seq data by iteratively soft-clustering cells and applying a mixture model-based correction to harmonize diverse datasets in a shared embedding. It operates on a low-dimensional principal component analysis (PCA) space, grouping cells into multi-dataset clusters and computing dataset-specific linear correction factors to align populations while preserving genuine biological variation.

Unlike methods requiring a reference dataset, Harmony performs unsupervised data integration by maximizing cluster diversity—penalizing clusters dominated by a single batch. This makes it robust for merging heterogeneous studies, technologies, and donors. The algorithm scales efficiently to millions of cells and is widely used for query-to-reference mapping and constructing large-scale single-cell atlases.

Algorithm Mechanics

Key Features of Harmony

Harmony integrates single-cell RNA-seq data through an iterative process of soft clustering and mixture model-based correction, projecting diverse datasets into a shared, batch-corrected embedding without requiring predefined cell-type labels.

01

Soft Clustering with Fuzzy Assignment

Harmony uses soft k-means clustering to assign each cell to multiple clusters probabilistically rather than forcing hard boundaries. This fuzzy assignment captures transitional cell states and continuous differentiation trajectories more accurately than discrete clustering. Each cell receives a membership vector across k clusters, enabling nuanced correction that respects biological gradients.

02

Mixture Model-Based Batch Correction

The algorithm applies a linear mixture model to estimate and remove batch effects within each soft cluster independently. For each cluster, Harmony computes a dataset-specific correction factor that shifts cells toward a shared centroid. This local correction preserves biologically meaningful variation while eliminating technical noise introduced by different sequencing platforms, protocols, or laboratories.

03

Maximum Diversity Clustering

Harmony enforces a maximum diversity penalty during clustering to prevent any single batch from dominating a cluster. This constraint ensures that each cluster contains cells from multiple datasets, forcing the algorithm to find shared biological structures rather than isolating batch-specific artifacts. The penalty is controlled by a tunable theta parameter that balances integration strength against biological preservation.

04

Iterative Expectation-Maximization

The algorithm alternates between two steps until convergence:

  • E-step: Update soft cluster assignments based on current corrected embeddings
  • M-step: Re-estimate cluster centroids and batch correction parameters This expectation-maximization framework guarantees monotonic improvement of the objective function, typically converging within 5-10 iterations for most single-cell datasets.
05

Scalable to Million-Cell Datasets

Harmony achieves O(N) linear time complexity relative to cell count, making it suitable for atlas-scale integration. The algorithm processes 1 million cells in under 30 minutes on standard hardware by using efficient sparse matrix operations and avoiding pairwise distance calculations between all cells. This scalability has enabled integration of the Human Cell Atlas and other large-scale reference mapping projects.

< 30 min
Per Million Cells
O(N)
Time Complexity
06

Integration Without Reference Dataset

Unlike supervised methods such as label transfer or query-to-reference mapping, Harmony performs unsupervised integration without requiring a pre-annotated reference atlas. All datasets are treated symmetrically during correction, making it ideal for exploratory analyses where ground-truth cell types are unknown or when integrating novel populations not present in existing references.

HARMONY ALGORITHM DEEP DIVE

Frequently Asked Questions

Explore the mechanics, applications, and theoretical underpinnings of the Harmony algorithm for robust single-cell data integration.

Harmony is an iterative algorithm that integrates single-cell RNA-seq data by soft-clustering cells and applying a mixture model-based correction to harmonize diverse datasets in a shared embedding. It begins with a low-dimensional embedding, such as one generated by Principal Component Analysis (PCA). In each iteration, Harmony performs a fuzzy clustering of cells into potentially overlapping groups using a variant of the Expectation-Maximization (EM) algorithm. It then calculates a dataset-specific linear correction factor for each cluster. Crucially, it applies a soft-mixing penalty that encourages cells from different datasets to intermingle within each cluster, progressively removing technical batch effects while preserving genuine biological variation. The output is an adjusted embedding where cells group by cell type rather than by experimental origin.

METHOD COMPARISON

Harmony vs. Other Integration Methods

A feature-level comparison of Harmony with alternative single-cell data integration algorithms for batch correction and dataset harmonization.

FeatureHarmonySeurat CCAscVI

Core Algorithm

Iterative soft-clustering with mixture model correction

Canonical correlation analysis with mutual nearest neighbors

Variational autoencoder with latent variable modeling

Handles Multiple Batches Simultaneously

Preserves Rare Cell Populations

Requires GPU for Training

Scalability (Cells)

1 million

~100,000

1 million

Output Type

Corrected PCA embeddings

Aligned canonical components

Probabilistic latent space

Integration Runtime (100k cells)

< 5 min

10-30 min

30-60 min

Prasad Kumkar

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.