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
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 [Satija15], Cell Ranger [Zheng17] or SPRING [Weinreb17].
- Parameters
- data :
AnnData
|ndarray
|spmatrix
Union
[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
Optional
[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
|None
Optional
[ndarray
] (default:None
) Precomputed counts per cell.
- key_n_counts :
str
str
(default:'n_counts'
) Name of the field in
adata.obs
where the total counts per cell are stored.- copy :
bool
bool
(default:False
) If an
AnnData
is passed, determines whether a copy is returned.- min_counts :
int
int
(default:1
) Cells with counts less than
min_counts
are filtered out during normalization.
- data :
- Return type
- Returns
Returns or updates
adata
with 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.]