scimilarity.cell_search_knn#

class scimilarity.cell_search_knn.CellSearchKNN(model_path, use_gpu=False)[source]#

Bases: CellEmbedding

A class for searching similar cells using cell embeddings kNN.

Parameters:
  • model_path (str) –

  • use_gpu (bool) –

get_nearest_neighbors(embeddings, k=50, ef=100)[source]#

Get nearest neighbors. Used by classes that inherit from CellEmbedding and have an instantiated kNN.

Parameters:
Returns:

  • nn_idxs (numpy.ndarray) – A 2D numpy array of nearest neighbor indices [num_cells x k].

  • nn_dists (numpy.ndarray) – A 2D numpy array of nearest neighbor distances [num_cells x k].

Return type:

Tuple[numpy.ndarray, numpy.ndarray]

Examples

>>> nn_idxs, nn_dists = get_nearest_neighbors(embeddings)
load_knn_index(knn_file)[source]#

Load the kNN index file

Parameters:

knn_file (str) – Filename of the kNN index.