search_cds_nn_index: Search a nearest neighbor index that is stored in the cds.

View source: R/nearest_neighbors.R

search_cds_nn_indexR Documentation

Search a nearest neighbor index that is stored in the cds.

Description

Search a nearest neighbor index for cells near those in the query_matrix.

Usage

search_cds_nn_index(
  query_matrix,
  cds,
  reduction_method = c("UMAP", "PCA", "LSI", "Aligned", "tSNE"),
  k = 25,
  nn_control = list(),
  verbose = FALSE
)

Arguments

query_matrix

a reduced dimension matrix used to find the nearest neighbors in the index nn_index.

cds

a cell_data_set in which the nearest neighbor index is stored.

reduction_method

a string giving the reduced dimension matrix used to make the nearest neighbor index, and determines where the index is stored in the cell_data_set. Note: distances in tSNE space reflect spatial differences poorly so using nearest neighbors with it may be meaningless.

k

an integer for the number of nearest neighbors to return for each cell. Default is 25.

nn_control

a list of parameters used to make and search the nearest neighbors indexes. See the set_nn_control help for additional details. Note that if nn_control[['search_k']] is not defined, transfer_cell_labels will try to use search_k <- 2 * n_trees * k where n_trees is the value used to build the index. The default metric is cosine for reduction_methods PCA, LSI, and Aligned, and is euclidean for reduction_methods tSNE and UMAP.

verbose

a boolean indicating whether to emit verbose output.

Value

a list list(nn.idx, nn.dists) where nn.idx is a matrix of nearest neighbor indices and nn.dists is a matrix of the distance between the index given by the row number and the index given in nn.idx. If the same reduced dim matrix is used to make the index and search the index, the index given by the row number should be in the row, usually in the first column.

Examples

  
    cds <- load_a549()
    cds <- preprocess_cds(cds)
    cds <- make_cds_nn_index(cds, 'PCA')
    nn_res <- search_cds_nn_index(SingleCellExperiment::reducedDims(cds)[['PCA']], cds, 'PCA', 10)
  


cole-trapnell-lab/monocle3 documentation built on April 7, 2024, 9:24 p.m.