Performs a control-only batch-mean correction using ComBat-style empirical Bayes shrinkage across genes, with regression or subtraction correction.

CorrectSampleComBat(
  object,
  assay = NULL,
  layer = "data",
  batch_key = NULL,
  condition_key = NULL,
  control_label = NULL,
  par.prior = TRUE,
  method = c("regression", "subtraction"),
  correct.attenuation = FALSE,
  floor.beta = NULL,
  verbose = TRUE
)

Arguments

object

A Seurat object (sample-level).

assay

Name of the assay to correct. Default is DefaultAssay(object).

layer

Layer within the assay that contains the data to correct. Default is "data".

batch_key

Column name in object@meta.data identifying the batch (e.g., plate, pool).

condition_key

Column name in object@meta.data identifying the experimental condition.

control_label

Value(s) in the condition_key column that mark control samples.

par.prior

Logical; if TRUE (default), uses parametric empirical Bayes estimation (EM). If FALSE, uses non-parametric Monte Carlo integration.

method

Correction method. "regression" (default) estimates a per-sample scaling factor \(\beta_i\) via OLS regression of each sample's profile on the shrunk batch mean. "subtraction" directly subtracts the shrunk batch mean (\(\beta = 1\) for all samples).

correct.attenuation

Logical; if TRUE the OLS regression slope is corrected for attenuation caused by measurement error in the shrunk batch means. Default FALSE. Only used when method = "regression".

floor.beta

Floor applied to per-sample \(\beta\) estimates. Default NULL (no floor). Set to e.g. 0 to prevent negative betas. Only used when method = "regression".

verbose

Print progress messages. Default TRUE.

Value

The Seurat object with the corrected data written back to the specified assay layer.

Details

This function estimates batch effects from control samples only and corrects all samples via regression or subtraction. It standardises the control means to z-scores, computes moment-based priors across genes (one set of hyper-parameters per batch), and shrinks via parametric EM (or non-parametric MC) estimation.

Examples

if (FALSE) { # \dontrun{
obj <- CorrectSampleComBat(obj, assay = "LMC",
                                  batch_key = "plate",
                                  condition_key = "Condition",
                                  control_label = "ctrl-inj")
} # }