cycombinepy.correct_data

cycombinepy.correct_data(adata, label_key='cycombine_som', markers=None, batch_key='batch', covar=None, anchor=None, parametric=True, ref_batch=None, layer=None, out_layer='cycombine_corrected', copy=False, return_report=False, uns_key='cycombinepy_correction', error_policy='raise', confound_policy='raise')[source]

Per-cluster ComBat batch correction.

Parameters:
  • adata (AnnData) – AnnData with a cluster label in adata.obs[label_key] and a batch in adata.obs[batch_key].

  • label_key (str) – Column in adata.obs with the SOM cluster id (from create_som()).

  • markers (Optional[Iterable[str]]) – Var names to correct. If None, uses cycombinepy.get_markers().

  • batch_key (str) – Column in adata.obs giving the batch assignment.

  • covar (str | None) – Optional adata.obs columns used as ComBat covariates. Skew- and confound-detection follow the R logic at lines 455-506.

  • anchor (str | None) – Optional adata.obs columns used as ComBat covariates. Skew- and confound-detection follow the R logic at lines 455-506.

  • parametric (bool) – Parametric vs. non-parametric ComBat prior.

  • ref_batch – Optional reference batch that is kept unchanged.

  • layer (str | None) – If given, read the uncorrected matrix from this layer rather than X.

  • out_layer (str) – Name of the layer to store the corrected matrix in.

  • copy (bool) – If True, return a corrected copy; otherwise mutate in place.

  • return_report (bool) – If True, return the correction report dict. With copy=True, returns (adata, report).

  • uns_key (str) – Key in adata.uns where the correction report is stored.

  • error_policy (Literal['raise', 'report', 'warn']) – How to handle ComBat exceptions: raise, record in the report, or warn and record in the report.

  • confound_policy (Literal['raise', 'skip', 'drop']) – How to handle requested covariates that are confounded or dropped by the effective design logic.

Return type:

AnnData | tuple[AnnData, dict] | dict | None