bioalpha.singlecell.tools.umap

bioalpha.singlecell.tools.umap(adata: AnnData, n_neighbors: int | None = None, min_dist: float = 0.5, spread: float = 1.0, n_components: int = 2, maxiter: int | None = None, alpha: float = 1.0, gamma: float = 1.0, negative_sample_rate: int = 5, init_pos: Literal['spectral', 'random', 'pca'] | ndarray | None = 'spectral', random_state: None | int | RandomState = 0, a: float | None = None, b: float | None = None, copy: bool = False, neighbors_key: str | None = None, n_pcs: int | None = None, use_rep: str | None = None, rep_name: str = 'X_umap', **kwargs) AnnData | None

Embed the neighborhood graph using UMAP (Uniform Manifold Approximation and Projection).

Parameters:
  • adata (AnnData) – The annotated data matrix of shape n_obs x n_vars. Rows correspond to cells and columns to genes.

  • n_neighbors (Optional[int], default = None) – The number of nearest neighbors to use to construct the target simplcial set. If n_neighbors is None, use n_samples instead.

  • min_dist (float, default = 0.5) – 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. The default of in the umap-learn package is 0.1.

  • spread (float, default = 1.0) – The effective scale of embedded points. In combination with min_dist this determines how clustered/clumped the embedded points are.

  • n_components (int, default = 2) – The number of dimensions of the embedding.

  • maxiter (Optional[int], default = None) – The number of iterations (epochs) of the optimization. Called n_epochs in the original UMAP.

  • alpha (float, default = 1.0) – The initial learning rate for the embedding optimization.

  • gamma (float, default = 1.0) – Weighting applied to negative samples in low dimensional embedding optimization. Values higher than one will result in greater weight being given to negative samples.

  • negative_sample_rate (int, default = 5) – The number of negative edge/1-simplex samples to use per positive edge/1-simplex sample in optimizing the low dimensional embedding.

  • init_pos (Optional[Union["spectral", "random", "pca", np.ndarray]], default = "spectral") – How to initialize the low dimensional embedding. Called in the _sctools.dimred.umap. Using 2 first PCA components for initialization if init_pos="pca".

  • random_state (Optional[Union[int, RandomState]], default = 0) – If int, random_state is the seed used by the random number generator; If RandomState or Generator, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

  • a (Optional[float], default = None) – More specific parameters controlling the embedding. If None these values are set automatically as determined by min_dist and spread.

  • b (Optional[float], default = None) – More specific parameters controlling the embedding. If None these values are set automatically as determined by min_dist and spread.

  • copy (bool, default = False) – Whether to copy adata or modify it inplace.

  • neighbors_key (Optional[str], default = None) – If not specified, umap looks .uns["neighbors"] for neighbors settings and .obsp["connectivities"] for connectivities (default storage places for pp.neighbors). If specified, umap looks .uns[neighbors_key] for neighbors settings and .obsp[.uns[neighbors_key]["connectivities_key"]] for connectivities.

  • n_pcs (Optional[int], default = None,) – Use this many PCs. If n_pcs==0 use .X if use_rep is None.

  • use_rep (Optional[str], default = None) – Use the indicated representation. "X" or any key for .obsm is valid. If None, the representation is chosen automatically: For .n_vars < 50, .X is used, otherwise “X_pca” is used. If “X_pca” is not present, it’s computed with default parameters.

  • rep_name (str, default = "X_umap") – Representation name that will be saved in adata.obsm

  • kwargs (dict) – Any additional arguments will be passed to _sctools.dimred.tsne.

Returns:

adata – If copy=True it returns or else adds fields to adata:

  • .obsm[rep_name] UMAP coordinates of data.

Return type:

AnnData