| Title: | 'Rust' Native Kernels for 'Harmony' Single-Cell Integration |
|---|---|
| Description: | 'Rust' reimplementation of the 'Harmony' integration loop (soft k-means, diversity penalty, mixture-of-experts ridge) with the same RunHarmony() signature used by the immunogenomics 'Harmony' R package. Designed to sit next to 'seurust': 'Seurat'/'seurust' produce the PCA embedding, 'harmorust' corrects it. Installing from source builds the 'harmorust' CLI with Cargo and places it in the package 'bin' directory. |
| Authors: | Nebil Ibrahim [aut, cre] |
| Maintainer: | Nebil Ibrahim <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-10-31 07:16:54 UTC |
| Source: | https://github.com/NebilI/harmony-rs |
Rust reimplementation of the Harmony integration loop with the same
RunHarmony() signature used by the immunogenomics Harmony R package.
A source install compiles the harmorust CLI with Cargo and stores it
in the package ‘bin’ directory.
| Package: | harmorust |
| Version: | 0.1.0 |
| License: | MIT |
Typical workflow: Seurat or seurust produce a PCA embedding, then
RunHarmony corrects batch effects.
Nebil Ibrahim [email protected]
RunHarmony, harmony_options,
HarmonyConvergencePlot
Same names as harmony::harmony_options.
harmony_options( alpha = 0.2, tau = 0, block.size = 0.05, max.iter.cluster = 4, epsilon.cluster = 1e-3, epsilon.harmony = 1e-2, batch.prop.cutoff = 1e-5 )harmony_options( alpha = 0.2, tau = 0, block.size = 0.05, max.iter.cluster = 4, epsilon.cluster = 1e-3, epsilon.harmony = 1e-2, batch.prop.cutoff = 1e-5 )
alpha |
Harmony2 automatic-lambda scale. Default 0.2. |
tau |
Softens theta for small batches. Default 0. |
block.size |
Fraction of cells updated per clustering block.
|
max.iter.cluster |
Inner clustering iterations per Harmony round. |
epsilon.cluster |
Clustering convergence tolerance. |
epsilon.harmony |
Outer-loop convergence tolerance. |
batch.prop.cutoff |
Skip a batch in a cluster below this soft membership. |
An object of class harmony_options.
opts <- harmony_options(block.size = 0.1, max.iter.cluster = 5)opts <- harmony_options(block.size = 0.1, max.iter.cluster = 5)
Same role as the unexported HarmonyConvergencePlot helper in
immunogenomics/harmony: visualise objective_kmeans across outer
rounds.
HarmonyConvergencePlot( harmonyObj, round_start = 1, round_end = Inf, do_wrap = FALSE )HarmonyConvergencePlot( harmonyObj, round_start = 1, round_end = Inf, do_wrap = FALSE )
harmonyObj |
Object from |
round_start |
First outer Harmony round to include (1-based). |
round_end |
Last outer Harmony round to include. |
do_wrap |
Facet by outer round when |
A ggplot object.
## Not run: obj <- RunHarmony(pca_matrix, meta_data, vars_use = "donor", return_object = TRUE) HarmonyConvergencePlot(obj) ## End(Not run)## Not run: obj <- RunHarmony(pca_matrix, meta_data, vars_use = "donor", return_object = TRUE) HarmonyConvergencePlot(obj) ## End(Not run)
Drop-in companion to harmony::RunHarmony(). The default method
matches Harmony's matrix API (data_mat, meta_data,
vars_use). Seurat and SingleCellExperiment methods match the
original package so a seurust-preprocessed object can be integrated
without changing the rest of the workflow.
RunHarmony(...) ## Default S3 method: RunHarmony( data_mat, meta_data, vars_use, theta = NULL, sigma = 0.1, lambda = NULL, nclust = NULL, max_iter = 10, early_stop = TRUE, ncores = 1, plot_convergence = FALSE, return_object = FALSE, verbose = TRUE, .options = harmony_options(), ... ) ## S3 method for class 'Seurat' RunHarmony( object, group.by.vars, reduction.use = "pca", reduction = NULL, dims.use = NULL, reduction.save = "harmony", reduction.name = NULL, project.dim = TRUE, ... ) ## S3 method for class 'SingleCellExperiment' RunHarmony( object, group.by.vars, dims.use = NULL, verbose = TRUE, reduction.save = "HARMONY", ... )RunHarmony(...) ## Default S3 method: RunHarmony( data_mat, meta_data, vars_use, theta = NULL, sigma = 0.1, lambda = NULL, nclust = NULL, max_iter = 10, early_stop = TRUE, ncores = 1, plot_convergence = FALSE, return_object = FALSE, verbose = TRUE, .options = harmony_options(), ... ) ## S3 method for class 'Seurat' RunHarmony( object, group.by.vars, reduction.use = "pca", reduction = NULL, dims.use = NULL, reduction.save = "harmony", reduction.name = NULL, project.dim = TRUE, ... ) ## S3 method for class 'SingleCellExperiment' RunHarmony( object, group.by.vars, dims.use = NULL, verbose = TRUE, reduction.save = "HARMONY", ... )
object |
PCA matrix, Seurat object, or SingleCellExperiment. |
data_mat |
Cell embedding matrix (cells |
meta_data |
Data frame of covariates, or a batch vector. |
vars_use, group.by.vars
|
Covariate name(s) Harmony should remove. |
theta |
Diversity penalty. Default 2 per covariate. |
sigma |
Soft k-means width. Default 0.1. |
lambda |
Ridge penalty. |
nclust |
Number of soft clusters. Default
|
max_iter |
Outer Harmony rounds. Default 10. |
early_stop |
Stop when the objective stalls. Default |
ncores |
Rayon threads for the Rust kernel
( |
plot_convergence |
Draw |
return_object |
Return a Harmony-like object instead of the matrix. |
verbose |
Print progress messages. |
.options |
Advanced options from |
reduction.use, reduction
|
Name of the input reduction. Default
|
reduction.save, reduction.name
|
Name of the written reduction. |
dims.use |
Which PCs to correct. |
project.dim |
Project Harmony loadings (Seurat). Default |
... |
Must be empty (legacy Harmony args are rejected). |
For the default method, a numeric matrix of corrected embeddings, or a
Harmony-like object when return_object = TRUE. Seurat and
SingleCellExperiment methods return the input object with a Harmony
reduction added.
harmony_options, HarmonyConvergencePlot
set.seed(1) pca_matrix <- cbind(rnorm(20), rnorm(20)) batch <- rep(c("A", "B"), each = 10) ## Not run: corrected <- RunHarmony(pca_matrix, batch, nclust = 2, max_iter = 2, verbose = FALSE) ## End(Not run)set.seed(1) pca_matrix <- cbind(rnorm(20), rnorm(20)) batch <- rep(c("A", "B"), each = 10) ## Not run: corrected <- RunHarmony(pca_matrix, batch, nclust = 2, max_iter = 2, verbose = FALSE) ## End(Not run)