Skip to content

msmu.tl.umap

Calculate UMAP embedding for a given modality in MuData object.

References

McInnes, L., Healy, J., & Melville, J. (2018). UMAP: Uniform Manifold Approximation and Projection for Dimension Reduction. arXiv preprint arXiv:1802.03426.

Parameters:

Name Type Description Default
mdata MuData

MuData object containing the data.

required
modality str

The modality to perform UMAP on.

required
n_components int

The dimension of the space to embed into. This defaults to 2 to provide easy visualization, but can reasonably be set to any integer value in the range 2 to 100.

2
n_neighbors int | None

The size of local neighborhood (in terms of number of neighboring sample points) used for manifold approximation. Larger values result in more global views of the manifold, while smaller values result in more local data being preserved. In general values should be in the range 2 to 100.

15
layer str | None

Layer to use for quantification aggregation. If None, the default layer (.X) will be used. Defaults to None.

None
metric str

The metric to use to compute distances in high dimensional space. If a string is passed it must match a valid predefined metric. If a general metric is required a function that takes two 1d arrays and returns a float can be provided. For performance purposes it is required that this be a numba jit'd function. Valid string metrics include:

  • euclidean
  • manhattan
  • chebyshev
  • minkowski
  • canberra
  • braycurtis
  • mahalanobis
  • wminkowski
  • seuclidean
  • cosine
  • correlation
  • haversine
  • hamming
  • jaccard
  • dice
  • russelrao
  • kulsinski
  • ll_dirichlet
  • hellinger
  • rogerstanimoto
  • sokalmichener
  • sokalsneath
  • yule

Metrics that take arguments (such as minkowski, mahalanobis etc.) can have arguments passed via the metric_kwds dictionary. At this time care must be taken and dictionary elements must be ordered appropriately; this will hopefully be fixed in the future.

'euclidean'
init str

How to initialize the low dimensional embedding. Options are:

  • 'spectral': use a spectral embedding of the fuzzy 1-skeleton
  • 'random': assign initial embedding positions at random.
  • 'pca': use the first n_components from PCA applied to the input data.
  • 'tswspectral': use a spectral embedding of the fuzzy 1-skeleton, using a truncated singular value decomposition to "warm" up the eigensolver. This is intended as an alternative to the 'spectral' method, if that takes an excessively long time to complete initialization (or fails to complete).
  • A numpy array of initial embedding positions.
'random'
min_dist float

The effective minimum distance between embedded points. Smaller values will result in a more clustered/clumped embedding where nearby points on the manifold are drawn closer together, while larger values will result on a more even dispersal of points. The value should be set relative to the spread value, which determines the scale at which embedded points will be spread out.

0.1
random_state int | None

RandomState instance or None, optional (default: None) If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

None
key_added str

Base key used for UMAP outputs. Results are stored in: - .obsm[key_added] for embedding coordinates - .uns[key_added] for embedding metadata Defaults to "X_umap".

'X_umap'
**kwargs Any

Additional keyword arguments passed to UMAP constructor.

{}

Returns:

Type Description
MuData

Updated MuData object with UMAP results.