nichepca.graph_construction.knn_graph

Contents

nichepca.graph_construction.knn_graph#

nichepca.graph_construction.knn_graph(adata, knn, obsm_key='spatial', undirected=True, remove_self_loops=False, p=2, verbose=True, return_graph=False)#

Construct a k-nearest neighbors graph.

Parameters:
  • adata (AnnData) – Annotated data object.

  • knn (int) – Number of nearest neighbors.

  • obsm_key (str (default: 'spatial')) – Key in obsm attribute where the spatial data is stored.

  • undirected (bool (default: True)) – Whether to create an undirected graph.

  • remove_self_loops (bool (default: False)) – Whether to remove self-loops.

  • p (int (default: 2)) – The norm to calculate the distance.

  • verbose (bool (default: True)) – Whether to print graph statistics.

  • return_graph (bool, default False) – Whether to return the graph instead of storing it in adata.

Returns:

None