scanpy.pp.regress_out#

scanpy.pp.regress_out(adata, covariates=None, *, use=None, out=False, n_jobs=None, copy=False, layer=None, keys=None)[source]#

Regress out (mostly) unwanted sources of variation.

Uses simple linear regression. This is inspired by Seurat’s regressOut function in R [Satija et al., 2015]. Note that this function tends to overcorrect in certain circumstances as described in #526.

Array type support#

Array type

supported

… experimentally in dask Array

numpy.ndarray

✅

❌

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

❌

❌

Parameters:
adata AnnData

The annotated data matrix.

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

Observation annotation(s) to regress on, e.g. A.obs['n_counts']. 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. If empty, all of .obs is used.

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

Which matrix to regress on. 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'.

layer str | None (default: None)

Deprecated since version 1.13.0: Use use/out instead.

A key of layers, i.e. layer='k' is use=A.layers['k'].

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.

n_jobs int | None (default: None)

Number of jobs for parallel computation. None means using scanpy.settings.n_jobs.

copy bool (default: False)

Deprecated since version 1.13.0: Copy adata before calling this function instead.

Whether to return a modified copy instead of modifying adata in place.

keys str | Sequence[str] | None (default: None)

Deprecated since version 1.13.0: Use covariates instead.

Names of .obs columns, i.e. keys=['k'] is covariates=[A.obs['k']].

Return type:

AnnData | ndarray | csr_array | csc_array | csr_matrix | csc_matrix | None

Returns:

Returns the corrected matrix if out=True, else None. By default overwrites the matrix use reads from (see out for others).