scanpy.pp.normalize_per_cell
- scanpy.pp.normalize_per_cell(data, counts_per_cell_after=None, counts_per_cell=None, key_n_counts='n_counts', copy=False, layers=(), use_rep=None, min_counts=1)
Normalize total counts per cell.
Warning
Deprecated since version 1.3.7: Use
normalize_total()instead. The new function is equivalent to the present function, except thatthe new function doesn’t filter cells based on
min_counts, usefilter_cells()if filtering is needed.some arguments were renamed
copyis replaced byinplace
Normalize each cell by total counts over all genes, so that every cell has the same total count after normalization.
Similar functions are used, for example, by Seurat [Satija15], Cell Ranger [Zheng17] or SPRING [Weinreb17].
- Parameters
- data :
AnnData|ndarray|spmatrixUnion[AnnData,ndarray,spmatrix] The (annotated) data matrix of shape
n_obs×n_vars. Rows correspond to cells and columns to genes.- counts_per_cell_after :
float|NoneOptional[float] (default:None) If
None, after normalization, each cell has a total count equal to the median of the counts_per_cell before normalization.- counts_per_cell :
ndarray|NoneOptional[ndarray] (default:None) Precomputed counts per cell.
- key_n_counts :
strstr(default:'n_counts') Name of the field in
adata.obswhere the total counts per cell are stored.- copy :
boolbool(default:False) If an
AnnDatais passed, determines whether a copy is returned.- min_counts :
intint(default:1) Cells with counts less than
min_countsare filtered out during normalization.
- data :
- Return type
- Returns
Returns or updates
adatawith normalized version of the originaladata.X, depending oncopy.
Examples
>>> import scanpy as sc >>> adata = AnnData(np.array([[1, 0], [3, 0], [5, 6]])) >>> print(adata.X.sum(axis=1)) [ 1. 3. 11.] >>> sc.pp.normalize_per_cell(adata) >>> print(adata.obs) >>> print(adata.X.sum(axis=1)) n_counts 0 1.0 1 3.0 2 11.0 [ 3. 3. 3.] >>> sc.pp.normalize_per_cell( >>> adata, counts_per_cell_after=1, >>> key_n_counts='n_counts2', >>> ) >>> print(adata.obs) >>> print(adata.X.sum(axis=1)) n_counts n_counts2 0 1.0 3.0 1 3.0 3.0 2 11.0 3.0 [ 1. 1. 1.]