cellflow.preprocessing.compute_wknn

cellflow.preprocessing.compute_wknn(ref_adata=None, query_adata=None, n_neighbors=30, ref_rep_key='X_pca', query_rep_key='X_pca', uns_key_added='wknn', query2ref=True, ref2query=False, weighting_scheme='jaccard_square', top_n=None, copy=False)[source]

Compute the weighted k-nearest neighbors graph between the reference and query datasets

Parameters:
  • ref_adata (AnnData) – An AnnData object with the reference representation to build ref-query neighbor graph

  • query_adata (AnnData) – An AnnData object with the query representation to build ref-query neighbor graph

  • n_neighbors (int) – Number of neighbors per cell

  • ref_rep_key (str) – Key in obsm of ref_adata containing the reference representation

  • query_rep_key (str) – Key in obsm of query_adata containing the query representation

  • uns_key_added (str) – Key to store the weighted k-nearest neighbors graph in uns

  • query2ref (bool) – Consider query-to-ref neighbors

  • ref2query (bool) – Consider ref-to-query neighbors

  • weighting_scheme (Optional[Literal['top_n', 'jaccard', 'jaccard_square']]) –

    How to weight edges in the ref-query neighbor graph. Options are:

    • None: No weighting

    • 'top_n': Binaries edges based on the top top_n neighbors.

    • 'jaccard': Weight edges based on the Jaccard index.

    • 'jaccard_square': Weight edges based on the square of the Jaccard index.

  • top_n (int | None) – The number of top neighbors to consider

  • copy (bool) – Return a copy of ref_adata instead of updating it in place

Return type:

AnnData | None

Returns:

: If copy is True, returns a new AnnData object with the weighted k-nearest neighbors stored in uns. Otherwise, updates adata in place.

Sets the following fields:

  • .uns[uns_key_added]: Weighted k-nearest neighbors graph