knn_normalization.tl.knn_normalize#
- knn_normalization.tl.knn_normalize(data, calculate_neighbors_from='prot', preprocess_rna=True, log_transform=True, n_neighbors=None, pseudocount=5, max_iterations=25, mean='average', inplace=True, save_size_factors=False, verbose=True, preserve_total_counts=True)#
Normalize protein expression with KNN normalization.
- Parameters:
data (
AnnData|MuData) – AnnData object with protein expression counts or MuData object withprotandrnamodalities.calculate_neighbors_from (
Literal['prot','rna','use_existing_neighbors'] (default:'prot')) – Whether to use theprotor thernamodality to calculate neighbor cells. Ifuse_existing_neighbors, the neighbors already present in the protein data will be used.preprocess_rna (
bool(default:True)) – If using RNA to calculate neighbors, whether to preprocess the RNA data with library size normalization and log-transformation first.n_neighbors (
Optional[Integral] (default:None)) – Number of neighbors. IfNone, calculated automatically asmax(15, min(round(n_cells / 20), 300)).log_transform (
bool(default:True)) – Whether to log-transform the protein data.pseudocount (
Integral(default:5)) – Pseudocount to add before normalization to avoid zero-division errors.max_iterations (
Integral(default:25)) – Maximum number of iterations.mean (
Literal['average','geom_mean','trimmed_mean'] (default:'average')) – Type of mean to use:'average','geom_mean', or'trimmed_mean'.inplace (
bool(default:True)) – Whether to update the object in place or return a copy.save_size_factors (
bool(default:False)) – IfTrue, saves the final size factors todata.obs['size_factor']and the size factor history todata.obsm['size_factor_history'].verbose (
bool(default:True)) – Whether to print progress messages.preserve_total_counts (default:
True) – Whether to preserve total counts across iterations.
- Returns:
Normalized data will be written to
data(if it is an AnnData object) ordata.mod['prot'](if it is a MuData object) as an X matrix. If inplace is False, returns a new AnnData object (if input is AnnData) or a new MuData object (if input is MuData) with the normalized data.