rapids_singlecell.pp.dsb#

rapids_singlecell.pp.dsb(adata, adata_empty=None, *, isotype_controls=None, use_isotype_controls=True, denoise_counts=True, pseudocount=None, scale_factor='standardize', fast_km=False, quantile_clip=None, use=None, out=False, dtype=<class 'numpy.float32'>, rng=None, layer=None, key_added=None, copy=False)[source]#

Normalize and denoise protein (ADT) counts with dsb [MuleMT22].

With empty droplets (adata_empty) this mirrors dsb::DSBNormalizeProtein:

  1. Ambient correction: log(counts + pseudocount) of every protein is standardized with the mean and standard deviation of that protein in the empty droplets (or only centered, scale_factor='mean_subtract').

  2. Technical denoising (denoise_counts): the first-component mean of a two-component Gaussian mixture fit to each cell’s values is its background level. With the isotype controls it defines a technical component (first principal component of the standardized isotype values and background means), which is regressed out of every protein.

Without adata_empty this mirrors dsb::ModelNegativeADTnorm: step 1 subtracts, per protein, the first-component mean of a mixture fit across cells.

Parameters:
adata AnnData

Cells-by-proteins raw ADT counts of cell-containing droplets.

adata_empty AnnData | None (default: None)

Raw ADT counts of empty droplets with the same proteins (may be backed). If None, the background is estimated from the cells.

isotype_controls str | Iterable[str] | None (default: None)

Name(s) of isotype control proteins in adata.var_names for step 2.

use_isotype_controls bool (default: True)

Use isotype_controls in step 2, as recommended by dsb. If False, only the per-cell background mean is regressed out (as in limma >= 3.66).

denoise_counts bool (default: True)

Run step 2.

pseudocount float | None (default: None)

Added before log transformation. Defaults to 10 with adata_empty and 1 without, as in dsb.

scale_factor Literal['standardize', 'mean_subtract'] (default: 'standardize')

Step 1 with empty droplets: 'standardize' or 'mean_subtract'.

fast_km bool (default: False)

Use the lower center of the optimal two-cluster k-means split as per-cell background.

quantile_clip tuple[float, float] | None (default: None)

Clip every protein to these lower and upper quantiles (type 7) of its normalized values; dsb’s quantile.clipping uses (0.001, 0.9995).

use LayerAcc | str | None (default: None)

Which matrix of adata and adata_empty holds the counts, e.g. A.X or A.layers['counts']. Strings are resolved by anndata.acc.AdAcc.resolve(), e.g. 'layers.counts'.

out LayerAcc | str | bool (default: False)

Where to write the normalized values, e.g. A.layers['dsb'] (or 'layers.dsb'). If True, they are returned instead, and the statistics below aren’t written. If False, they are written to the place use reads from.

dtype DTypeLike (default: <class 'numpy.float32'>)

Floating point type of the computations and the output (unlike scanpy.pp.dsb, where it only sets the output). float64 reproduces R. float32 is faster and stays within ~1e-5 of float64; mixture fits whose decisions fall within float32 noise are refit in float64.

Where R would fail on a model fit, rsc warns and continues: a cell whose mixture fit is singular in both models gets the lower k-means center as background, and EM stops after 100,000 iterations.

rng int | integer | Sequence[int] | SeedSequence | Generator | BitGenerator | None (default: None)

Random number generator for the mixture fits of vectors longer than 2000 values, which start from a random subset.

Return type:

AnnData | ndarray | ndarray | None

Returns:

The normalized values if out=True, else None. Otherwise sets the following.

.X, the place use reads from, or out

dsb normalized values (dense, dtype, on the device of the input).

.var['dsb_ambient_mean']

Per-protein background mean of log(counts + pseudocount) (0 for proteins whose fit failed).

.var['dsb_ambient_sd']

Empty droplet standard deviation (only with adata_empty).

.obs['dsb_cell_background_mean']

Per-cell background mean of step 2 (only with denoise_counts).

.obs['dsb_technical_component']

Covariate regressed out in step 2 (only with denoise_counts).