
Compute Nearest Neighbor Graphs
computeNearestNeighbors.Rd
General, flexible function to create NN graphs within SpatialMap objects. Returns a SpatialMap object with NN objects added to Regions or Analyses.
Usage
computeNearestNeighbors(
object,
name,
method = c("knn", "frnn", "snn", "del"),
representation,
k = 30,
eps = 50,
kt = NULL,
jp = FALSE,
data.slot = NULL,
query = NULL,
...
)
Arguments
- object
A SpatialMap object
- name
A custom name for the graph. By default, will be named according to the representation, method, and parameter specified (e.g.
umap_knn_5
,pca_frnn_50
,spatial_del
).- method
'knn'
,'frnn'
,'snn'
, or'del'
. The vignette on advanced spatial analyses contains an in-depth description (vignette("Tutorial_Advanced_spatial")
) although this functionality can be more general!- representation
Which representation's embeddings should be used to compute the graph?
- k
The number of K-nearest neighbors
- eps
The radius for fixed-radius nearest neighbors
- kt
minimum threshold on the number of shared nearest neighbors to build the shared nearest neighbor graph. Edges are only preserved if
kt
or more neighbors are shared.- jp
In regular sNN graphs, two points that are not neighbors can have shared neighbors. Javis and Patrick (1973) requires the two points to be neighbors, otherwise the count is zeroed out.
TRUE
uses this behavior.- data.slot
A data slot to use (i.e. look for nearest neighbors in raw or normalized biomarker expression space). See
Data()
for details. PassNULL
torepresentation
to use this parameter. Currently only supported for"knn"
.- query
Another matrix to compute NNs against (optional, currently only supported for createFixedRadiusNNGraph.Region)
- ...
Additional parameters passed to the NN methods.
Details
NN methods and parameters are passed as arguments to the function, which dispatches downstream functions to implement KNN, sNN, frNN, or Delaunay Triangulation methods.
method = "knn"
:createKNNGraph.Region()
method = "snn"
:createSharedNNGraph.Region()
method = "frnn"
:createFixedRadiusNNGraph.Region()
method = "del"
:createDelaunayTriangulation.Region()
The vignette on advanced spatial analyses contains an in-depth description of each method
(vignette("Tutorial_Advanced_spatial")
) but this functionality can be more generally applied to non-spatial
representations!