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 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
copy
is 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 [Satija et al., 2015], Cell Ranger [Zheng et al., 2017] or SPRING [Weinreb et al., 2017].
- Parameters:
- data
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
|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.obs
where the total counts per cell are stored.- copy
bool
(default:False
) If an
AnnData
is passed, determines whether a copy is returned.- min_counts
int
(default:1
) Cells with counts less than
min_counts
are filtered out during normalization.
- data
- Return type:
- Returns:
Returns
None
ifcopy=False
, else returns an updatedAnnData
object. Sets the following fields:adata.X
numpy.ndarray
|scipy.sparse._csr.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) >>> 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', ... ) >>> 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.]