build_knn_graph: Build kNN graph

View source: R/build_knn_graph.R

build_knn_graphR Documentation

Build kNN graph

Description

Build kNN graph either from distance (from == "dist") or from coordinates (from == "coordinates")

Usage

build_knn_graph(
  X,
  k = 5,
  from = c("dist", "coordinates"),
  use.nn2 = TRUE,
  return_neighbors_order = FALSE,
  dist_method = "euclidean",
  cor_method = "pearson",
  p = 2,
  directed = FALSE,
  DoSNN = FALSE,
  which.snn = c("bluster", "dbscan"),
  pruning = NULL,
  kmin = 0,
  ...
)

Arguments

X

either distance or matrix of coordinates (rows are samples and cols are coordinates)

k

kNN parameter

from

from which data type to build kNN network: "dist" if X is a distance (dissimilarity) or "coordinates" if X is a matrix with coordinates as cols and cells as rows

use.nn2

whether use nn2 method to buid kNN network faster (available only for "coordinates" option)

return_neighbors_order

whether return order of neighbors (not available for nn2 option)

dist_method

method to compute dist (if X is a matrix of coordinates) available: c("cor", "euclidean", "maximum", "manhattan", "canberra", "binary", "minkowski")

cor_method

if distance is computed as correlation (dist_method == "cor), which type of correlation to use (available: "pearson", "kendall", "spearman")

p

p param in "dist" function

directed

whether to build a directed graph

DoSNN

whether to apply shared nearest neighbors (default is FALSE)

which.snn

whether to use neighborsToSNNGraph or sNN for sNN graph construction

pruning

quantile to perform edge pruning (default is NULL - no pruning applied) based on PCA distance distribution

kmin

keep at least kmin edges in single-cell graph when pruning applied (idnored if is.null(pruning))

...

other parameters of neighborsToSNNGraph or sNN

Value

a list with components

  • graph.knn - igraph object

  • order - Nxk matrix with indices of k nearest neighbors ordered by relevance (from 1st to k-th)


SuperCell documentation built on Oct. 25, 2024, 5:07 p.m.