Expand knn graph to increase the number of neighbours
Source:R/expand_knn_graph.R
ExpandNeighbours.Rd
Expand a knn graph to increase the number of nearest neighbours using Dijkstra's algorithm, or a diffusion algorithm. Dijkstra's algorithm is used to prepare for LISI score, while diffusion is suited for preparing to compute the kBET score. Beware that diffusion is designed to work on connectivity matrices and is not adequate for distance-based networks.
Usage
ExpandNeighbours(
object,
graph.name = "RNA_nn",
new.graph.name = NULL,
graph.type = c("distances", "connectivities"),
k.target = 90L,
do.symmetrize = FALSE,
algo = c("dijkstra", "diffusion"),
which.dijkstra = c("auto", "igraph", "fast", "slow"),
dijkstra.ncores = 1L,
dijkstra.tol = 1L,
diffusion.iter = 26L,
assay = NULL,
verbose = TRUE
)
# S4 method for class 'Seurat'
ExpandNeighbours(
object,
graph.name = "RNA_nn",
new.graph.name = NULL,
graph.type = c("distances", "connectivities"),
k.target = 90L,
do.symmetrize = FALSE,
algo = c("dijkstra", "diffusion"),
which.dijkstra = c("auto", "igraph", "fast", "slow"),
dijkstra.ncores = 1L,
dijkstra.tol = 1L,
diffusion.iter = 26L,
assay = NULL,
verbose = TRUE
)
Arguments
- object
a
Seurat
,Graph
orNeighbor
object- graph.name
name of a
Graph
orNeighbor
instance stored in theSeurat object
.- new.graph.name
name of the return
Graph
to store in theSeurat object
.- graph.type
One of "distances" or "connectivities", indicating the type of metric stored in the graph object.
- k.target
number of nearest neighbours to reach
- do.symmetrize
whether to make the input graph symmetric if necessary. See Details section for further explanations
- algo
One of "dijkstra" or "diffusion". "diffusion" is suited for connectivity matrices only
- which.dijkstra
one of "igraph", "fast" or "slow". "auto" (default) chooses for you. See Details section
- dijkstra.ncores
number of cores to use for Dijkstra's algorithm. Ignored when
which.dijkstra = "igraph"
- dijkstra.tol
number of sequential iterations with identical best neighbours found to consider that Dijkstra's algorithm should be stopped. Ignored when
which.dijkstra = "igraph"
- diffusion.iter
maximum number of iterations to reach
k.target
- assay
name of the assay to store in the output
Graph
- verbose
whether to print progress messages
Details
The approximate nature of the nearest neighbour search algorithm used to compute the knn graph makes the resulting adjacency matrix asymmetric. It means that \(cell_i\) can be a nearest neighbour of \(cell_j\) while the reverse is not true even though the distance between \(cell_i\) and \(cell_j\) is lower than the distance between \(cell_j\) and some of its nearest neighbours.
One can choose to keep the graph as it is and consider it as a directed graph
(do.symmetrize = FALSE
).
The alternative solution is to use all computed distances to extend the knn
graph by making the matrix symmetric. Note that connectivity graphs are
already symmetric, so the argument value should have no effect on the result.