scanpy.pp.combat#

scanpy.pp.combat(adata, batch=A.obs['batch'], *, covariates=None, use=None, out=False, inplace=True, key=None)[source]#

ComBat function for batch effect correction [Johnson et al., 2006, Leek et al., 2017, Pedersen, 2012].

Corrects for batch effects by fitting linear models, gains statistical power via an EB framework where information is borrowed across genes. This uses the implementation combat.py [Pedersen, 2012].

Array type support#

Array type

supported

… experimentally in dask Array

numpy.ndarray

✅

❌

scipy.sparse.{csr,csc}_{array,matrix}

❌

❌

Parameters:
adata AnnData

Annotated data matrix

batch AdRef | str | Default (default: A.obs['batch'])

A categorical annotation that will be used for batch effect removal, e.g. A.obs['batch']. If scanpy.settings.preset is ScanpyV2Preview, strs are anndata.acc.AdAcc.resolve()d to AdRefs (e.g. 'obs.is_control'), otherwise interpreted as column names.

covariates Collection[AdRef | str] | None (default: None)

Additional covariates besides the batch variable such as adjustment variables or biological condition (references or names like batch). This parameter refers to the design matrix X in Equation 2.1 in Johnson et al. [2006] and to the mod argument in the original combat function in the sva R package. Note that not including covariates may introduce bias or lead to the removal of biological signal in unbalanced designs.

use LayerAcc | MultiAcc | str | None (default: None)

Which matrix to correct. Given by an accessor, e.g. A.X, A.layers['counts'] or A.obsm['pca']. strs are anndata.acc.AdAcc.resolve()d, e.g. 'layers.counts'.

out LayerAcc | MultiAcc | str | bool (default: False)

Where to write the result, e.g. A.layers['scaled']. strs are anndata.acc.AdAcc.resolve()d, e.g. 'layers.scaled'. If True, the result is returned instead of written. If False, it is written to the place use reads from.

inplace bool (default: True)

Deprecated since version 1.13.0: Use out=True instead of inplace=False.

Whether to replace adata.X or to return the corrected data

key str | None (default: None)

Deprecated since version 1.13.0: Use batch instead.

The name of a .obs column, i.e. key='b' is batch=A.obs['b'].

Return type:

ndarray | None

Returns:

Returns the corrected matrix (a numpy.ndarray) if out=True, else None.