episcanpy.pp.normalize_per_cell

episcanpy.pp.normalize_per_cell(adata, counts_per_cell_after=None, counts_per_cell=None, key_n_counts=None, 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 that

  • the new function doesn’t filter cells based on min_counts, use 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 [Satija15], Cell Ranger [Zheng17] or SPRING [Weinreb17].

Parameters
data : AnnData, np.ndarray, sp.sparse

The (annotated) data matrix of shape n_obs × n_vars. Rows correspond to cells and columns to genes.

counts_per_cell_after : float or None, optional (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 : np.array, optional (default: None)

Precomputed counts per cell.

key_n_counts : str, optional (default: ‘n_counts’)

Name of the field in adata.obs where the total counts per cell are stored.

copy : bool, optional (default: False)

If an AnnData is passed, determines whether a copy is returned.

min_counts : int, optional (default: 1)

Cells with counts less than min_counts are filtered out during normalization.

Returns

Returns or updates adata with normalized version of the original adata.X, depending on copy.

Examples

>>> adata = AnnData(
>>>     data=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.]