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)[source]#
Normalize total counts per cell.
Deprecated: The function normalize_per_cell is deprecated and will be removed in the future: Use :func:`~scanpy.pp.normalize_total` instead. The new function is equivalent to the present function, except that * the new function doesn’t filter cells based on `min_counts`, use :func:`~scanpy.pp.filter_cells` if filtering is needed. * some arguments were renamed * `copy` is replaced by `inplace`
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 [Satija et al., 2015], Cell Ranger [Zheng et al., 2017] or SPRING [Weinreb et al., 2017].
- Parameters:
- data
AnnData|ndarray|csr_array|csc_array|csr_matrix|csc_matrix The (annotated) data matrix of shape
n_obs×n_vars. Rows correspond to cells and columns to genes.- counts_per_cell_after
float|None(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|None(default:None) Precomputed counts per cell.
- key_n_counts
str(default:'n_counts') Name of the field in
adata.obswhere the total counts per cell are stored.- copy
bool(default:False) If an
AnnDatais passed, determines whether a copy is returned.- min_counts
int(default:1) Cells with counts less than
min_countsare filtered out during normalization.
- data
- Return type:
AnnData|ndarray|csr_array|csc_array|csr_matrix|csc_matrix|None- Returns:
Returns
Noneifcopy=False, else returns an updatedAnnDataobject. Sets the following fields:adata.Xnumpy.ndarray|scipy.sparse.csr_matrix(dtypefloat)Normalized count data matrix.
Examples
>>> import scanpy as sc >>> adata = AnnData(np.array([[1, 0], [3, 0], [5, 6]], dtype=np.float32)) >>> print(adata.X.sum(axis=1)) [ 1. 3. 11.] >>> sc.pp.normalize_per_cell(adata) FutureWarning: The function normalize_per_cell is deprecated ... >>> print(adata.obs) n_counts 0 1.0 1 3.0 2 11.0 >>> print(adata.X.sum(axis=1)) [3. 3. 3.] >>> sc.pp.normalize_per_cell( ... adata, ... counts_per_cell_after=1, ... key_n_counts="n_counts2", ... ) FutureWarning: The function normalize_per_cell is deprecated ... >>> print(adata.obs) n_counts n_counts2 0 1.0 3.0 1 3.0 3.0 2 11.0 3.0 >>> print(adata.X.sum(axis=1)) [1. 1. 1.]