scanpy.tl.diffmap#
- scanpy.tl.diffmap(adata, n_comps=15, *, rng=None, use=None, out=False, neighbors_key=None, copy=False)[source]#
Diffusion Maps [Coifman et al., 2005, Haghverdi et al., 2015, Wolf et al., 2018].
Diffusion maps [Coifman et al., 2005] have been proposed for visualizing single-cell data by Haghverdi et al. [2015]. This tool uses the adapted Gaussian kernel suggested by Haghverdi et al. [2016] with the implementation of Wolf et al. [2018].
The width (“sigma”) of the connectivity kernel is implicitly determined by the number of neighbors used to compute the single-cell graph in
neighbors(). To reproduce the original implementation using a Gaussian kernel, usemethod=='gauss'inneighbors(). To use an exponential kernel, use the defaultmethod=='umap'. Differences between these options shouldn’t usually be dramatic.Array type support# Array type
supported
… experimentally in dask
Array✅
❌
✅
❌
- Parameters:
- adata
AnnData Annotated data matrix.
- n_comps
int(default:15) The number of dimensions of the representation.
- rng
int|integer|Sequence[int] |SeedSequence|Generator|BitGenerator|None(default:None) Random number generation to control stochasticity.
If a type:
SeedLikevalue, it’s used to seed a new random number generator; If anumpy.random.Generator,rng’s state will be directly advanced; IfNone, a non-reproducible random number generator is used. Seenumpy.random.default_rng()for more details.The default value matches legacy scanpy behavior and will change to
Nonein scanpy 2.0.- use
GraphAcc|str|None(default:None) The neighborhood graph (connectivities) to use, e.g.
A.obsp['k']aftersc.pp.neighbors(adata, out=A.obsp['k']), or any other graph.strs areresolve()d, e.g.'obsp.k'. IfNone, the oneneighbors()wrote by default. Distances and parameters are used from whereneighbors()stored them alongside it, if they exist.- out
MultiAcc|str|bool(default:False) Where to write the embedding. Given by an accessor, e.g.
A.obsm['diffmap'].strs areanndata.acc.AdAcc.resolve()d. Accompanyingunsentries are stored under the same key. IfTrue, the embedding is returned instead of written. IfFalse, it is written to.obsm['X_diffmap']and the eigenvalues to.uns['diffmap_evals'](.obsm['diffmap']and.uns['diffmap']['evals']ifscanpy.settings.presetisScanpyV2Preview).- neighbors_key
str|None(default:None) Deprecated since version 1.13.0: Use
useinstead, e.g.use=A.obsp['k_connectivities']forneighbors_key='k'.If not specified, diffmap looks in .uns[‘neighbors’] for neighbors settings and .obsp[‘connectivities’] and .obsp[‘distances’] for connectivities and distances, respectively (default storage places for pp.neighbors). If specified, diffmap looks in .uns[neighbors_key] for neighbors settings and .obsp[.uns[neighbors_key][‘connectivities_key’]] and .obsp[.uns[neighbors_key][‘distances_key’]] for connectivities and distances, respectively.
- copy
bool(default:False) Deprecated since version 1.13.0: Copy
adatabefore calling this function instead.Return a copy instead of writing to adata.
- adata
- Return type:
- Returns:
Returns the embedding if
out=True, elseNone. By default sets the following fields (seeoutfor others):adata.obsm['X_diffmap']numpy.ndarray(dtypefloat)Diffusion map representation of data, which is the right eigen basis of the transition matrix with eigenvectors as columns.
adata.uns['diffmap_evals']numpy.ndarray(dtypefloat)Array of size (number of eigen vectors). Eigenvalues of transition matrix.
Notes
The 0-th column in
adata.obsm["X_diffmap"]is the steady-state solution, which is non-informative in diffusion maps. Therefore, the first diffusion component is at index 1, e.g.adata.obsm["X_diffmap"][:,1]