scanpy.pp.normalize_shifted_clr#

scanpy.pp.normalize_shifted_clr(adata, *, alpha=None, use=None, out=False)[source]#

Normalize counts with the shifted centered log-ratio (PFlog) transform.

If alpha is not provided, it is estimated from the input matrix. PFlog is then computed as

T(x)i=log⁡(1+4αxi)−1D∑j=1Dlog⁡(1+4αxj),

which is equivalent to centering log⁡(xi+1/(4α)) because the constant log⁡(4α) cancels during CLR centering.

Array type support#

Array type

supported

… experimentally in dask Array

numpy.ndarray

✅

✅

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

✅

✅

Note

CLR centering generally maps zeros to non-zero values, so the resulting matrix is dense even when the input is sparse.

Parameters:
adata AnnData

The annotated data matrix of shape n_obs × n_vars. Rows correspond to cells and columns to genes.

alpha float | None (default: None)

Negative-binomial overdispersion of the dataset (var = μ + α·μ²). If None, it is estimated from the input matrix. A positive numeric value uses that value directly. PFlog applies log1p(4 * alpha * x) before CLR centering.

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

Which matrix to normalize. 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.

Return type:

ndarray | Array | None

Returns:

The normalized matrix if out=True, else None.

Example

>>> import numpy as np
>>> from anndata import AnnData
>>> import scanpy as sc
>>> adata = AnnData(np.array([[1, 2, 30], [4, 50, 6]], dtype="float32"))
>>> sc.pp.normalize_shifted_clr(adata, alpha=0.5)
>>> np.allclose(adata.X.sum(axis=1), 0, atol=1e-5)
True