rapids_singlecell.tl.embedding_density#
- rapids_singlecell.tl.embedding_density(adata, use='umap', *, groupby=None, components=None, out=False, basis=None, key_added=None)[source]#
Calculate the density of cells in an embedding (per condition).
Gaussian kernel density estimation is used to calculate the density of cells in an embedded space. This can be performed per category over a categorical cell annotation. The cell density can be plotted using the
pl.embedding_densityfunction. Note that density values are scaled to be between 0 and 1. Thus, the density value at each cell is only comparable to densities in the same category. This function was written by Sophie Tritschler and implemented into Scanpy by Malte Luecken.- Parameters:
- adata
AnnData The annotated data matrix.
- use
MultiAcc|str|Default(default:'umap') The embedding over which the density will be calculated, e.g.
A.obsm['X_umap'], or the name of a basis found inadata.obsm[basis]oradata.obsm[f"X_{basis}"]. Strings are basis names, unless the scanpy v2 preset is active, where they are resolved byanndata.acc.AdAcc.resolve(), e.g.'obsm.X_umap'.- groupby
AdRef|str|None(default:None) Categorical
.obscolumn for which densities are calculated per category, e.g.A.obs['batch']or its name.- components
str|Sequence[str] (default:None) The embedding dimensions over which the density should be calculated. This is limited to two components.
- out
AdRef|str|bool(default:False) Where to write the densities, e.g.
A.obs['k'](or'obs.k'); the parameters then go to.uns['k_params']. IfTrue, the densities are returned instead of written. IfFalse, they are written to.obs['[basis]_density_[groupby]'].
- adata
- Return type:
- Returns:
The densities if
out=True, elseNone. Setsadata.obs[key]andadata.uns[f'{key}_params'], wherekeydefaults to[basis]_density_[groupby],[basis]being one ofumap,diffmap,pca,tsne, ordraw_graph_fa.