snapatac2.tl.umap#
- snapatac2.tl.umap(adata, n_comps=2, use_dims=None, use_rep='X_spectral', key_added='umap', random_state=0, inplace=True, **kwargs)[source]#
Compute a UMAP embedding from an existing representation.
Use this function after computing a low-dimensional representation such as
X_spectral. Pass a NumPy array directly when you want the embedding returned instead of written to an AnnData object.Anti-Patterns#
Do NOT set
inplace=Truewhen passing a raw NumPy array; arrays cannot store.obsmresults and the embedding is returned instead.Do NOT pass cluster labels through
key_added; this key namesadata.obsm["X_" + key_added], notadata.obs.
- param adata:
Annotated data object containing
adata.obsm[use_rep], or a numeric matrix with shape(n_cells, n_features).- type adata:
AnnData|AnnDataSet|ndarray- param n_comps:
Number of UMAP dimensions to compute.
- type n_comps:
- param use_dims:
Dimensions from
use_repto use. If an integer, use the firstuse_dimscolumns; if a list, use those column indices; if None, use all columns.- type use_dims:
- param use_rep:
Key in
adata.obsmcontaining the input representation.- type use_rep:
- param key_added:
Suffix for the output key
adata.obsm["X_" + key_added].- type key_added:
- param random_state:
Random seed passed to
umap.UMAP.- type random_state:
- param inplace:
If True, store the embedding in
adata.obsm; if False, return it.- type inplace:
- type **kwargs:
- param **kwargs:
Additional keyword arguments passed to
umap.UMAP.- returns:
If
inplace=Trueandadatais an AnnData object, stores the embedding inadata.obsm["X_" + key_added]and returns None. Otherwise, returns the embedding with shape(n_cells, n_comps).- rtype:
Examples
>>> import numpy as np >>> import snapatac2 as snap >>> X = np.random.default_rng(0).normal(size=(20, 5)) >>> embedding = snap.tl.umap(X, n_comps=2, inplace=False, n_neighbors=5) >>> embedding.shape (20, 2)