Runs harmony::RunHarmony() on a low-dimensional embedding, such as
principal components of shifted log expression, and returns its soft cluster
assignments and penalties for correct_feature_batch(). Needs the optional
harmony package.
Arguments
- embedding
Named numeric samples by dimensions matrix, such as PCs.
- metadata
Data frame with one row per sample, keyed by
id_col.- batch_col
Metadata column holding the batch; at least two levels.
- seed
Nonnegative integer. Required; Harmony's k-means start uses R's random numbers. The caller's random number state is restored afterwards.
- id_col
Metadata column holding sample IDs.
- ...
Further arguments to
harmony::RunHarmony(), such asnclust,thetaor.options.
Value
A list with $assignments (samples by clusters, rows summing to
one), $lambda (clusters by batch levels, the penalties Harmony used),
$embedding (Harmony's corrected embedding) and $analysis_metadata.
Details
Pass $assignments and $lambda to correct_feature_batch() to
apply Harmony's correction to the full feature matrix. Applied to
embedding itself, that reproduces $embedding to Harmony's
single-precision arithmetic. Only one batch variable is supported.
References
Korsunsky I, Millard N, Fan J, et al. (2019). Fast, sensitive and accurate integration of single-cell data with Harmony. Nature Methods 16, 1289-1296. doi:10.1038/s41592-019-0619-0
Author
Mikhael Manurung (adapter). harmony: Ilya Korsunsky, Nikolaos Patikas, Soumya Raychaudhuri and contributors listed in its DESCRIPTION.
Examples
set.seed(1)
batch <- rep(c("b1", "b2"), each = 50)
pcs <- matrix(rnorm(100 * 5), 100, 5) + outer(batch == "b2", rep(1, 5))
dimnames(pcs) <- list(paste0("s", 1:100), paste0("PC", 1:5))
metadata <- data.frame(sample = rownames(pcs), batch = batch)
h <- harmony_assignments(pcs, metadata, "batch", seed = 1, nclust = 3)
dim(h$assignments)
#> [1] 100 3