dynamo.tl.neighbors

dynamo.tl.neighbors(adata, X_data=None, genes=None, basis='pca', layer=None, n_pca_components=30, n_neighbors=30, method=None, metric='euclidean', metric_kwads=None, cores=1, seed=19491001, **kwargs)[source]

Function to search nearest neighbors of the adata object.

Parameters
  • adata (AnnData) – an Annodata object

  • X_data (np.ndarray (default: None)) – The user supplied data that will be used for nearest neighbor search directly.

  • genes (list or None (default: None)) – The list of genes that will be used to subset the data for nearest neighbor search. If None, all genes will be used.

  • basis (str (default: pca)) – The space that will be used for nearest neighbor search. Valid names includes, for example, pca, umap, velocity_pca or X (that is, you can use velocity for clustering), etc.

  • layers (str or list (default: all)) – The layer to be used for nearest neighbor search.

  • n_pca_components (‘int’ (optional, default 30)) – Number of PCA components. Applicable only if you will use pca basis for nearest neighbor search.

  • n_neighbors (int (optional, default 30)) – Number of nearest neighbors.

  • method (str or None (default: None)) – The methoed used for nearest neighbor search. If umap or pynn, it relies on pynndescent package’s NNDescent for fast nearest neighbor search.

  • metric (str or callable, default=’euclidean’) – The distance metric to use for the tree. The default metric is , and with p=2 is equivalent to the standard Euclidean metric. See the documentation of DistanceMetric for a list of available metrics. If metric is “precomputed”, X is assumed to be a distance matrix and must be square during fit. X may be a sparse graph, in which case only “nonzero” elements may be considered neighbors.

  • metric_params (dict, default=None) – Additional keyword arguments for the metric function.

  • cores (int (default: 1)) – The number of parallel jobs to run for neighbors search. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors.

  • seed (int (default 19491001)) – Random seed to ensure the reproducibility of each run.

  • kwargs – Additional arguments that will be passed to each nearest neighbor search algorithm.

Returns

adata – A updated anndata object that are updated with the indices, connectivity, distance to the .obsp, as well as a new neighbors key in .uns.

Return type

:AnnData