| buildSpatialGraph {imcRtools} | R Documentation |
Function to define cell-cell interactions via distance-based expansion, delaunay triangulation or k nearest neighbor detection.
buildSpatialGraph(
object,
img_id,
type = c("expansion", "knn", "delaunay"),
k = NULL,
directed = TRUE,
k_max_dist = NULL,
threshold = NULL,
coords = c("Pos_X", "Pos_Y"),
name = NULL,
BNPARAM = KmknnParam(),
BPPARAM = SerialParam(),
...
)
object |
a |
img_id |
single character indicating the |
type |
single character specifying the type of graph to be build.
Supported entries are |
k |
(when |
directed |
(when |
k_max_dist |
(when |
threshold |
(when |
coords |
character vector of length 2 specifying the names of the
|
name |
single character specifying the name of the graph. |
BNPARAM |
a |
BPPARAM |
a |
... |
additional parameters passed to the
|
returns a SpatialExperiment or SingleCellExperiment
containing the graph in form of a SelfHits object in
colPair(object, name).
This function defines interacting cells in different ways. They are based on the cells' centroids and do not incorporate cell shape or area.
1. When type = "expansion", all cells within the radius
threshold are considered interacting cells.
2. When type = "delaunay", interacting cells are found via a delaunay
triangulation of the cells' centroids.
3. When type = "knn", interacting cells are defined as the k
nearest neighbors in the 2D spatial plane.
The directed parameter only affects graph construction via k nearest
neighbor search. For directed = FALSE, each interaction will be
stored as mutual edge (e.g. node 2 is connected to node 10 and vise versa).
For type = "expansion" and type = "delaunay", each edge is
stored as mutual edge by default.
The graph is stored in form of a SelfHits object in
colPair(object, name). This object can be regarded as an edgelist
and coerced to an igraph object via
graph_from_edgelist(as.matrix(colPair(object, name))).
When finding interactions via expansion or knn, the
findNeighbors or
findKNN functions are used, respectively. Both
functions accept the BNPARAM parameter via which the graph
construction method can be defined (default
KmknnParam). For an overview on the different
algorithms, see
BiocNeighborParam. Within the
BiocNeighborParam object, distance can be set to
"Euclidean" (default), "Manhattan" or "Cosine".
Nils Eling (nils.eling@dqbm.uzh.ch)
findNeighbors for the function finding
interactions via expansion
findKNN for the function finding interactions
via nearest neighbor search
triangulate for the function finding interactions
via delaunay triangulation
plotSpatial for visualizing spatial graphs
path <- system.file("extdata/mockData/steinbock", package = "imcRtools")
spe <- read_steinbock(path)
# Constructing a graph via expansion
spe <- buildSpatialGraph(spe, img_id = "sample_id",
type = "expansion", threshold = 10)
colPair(spe, "expansion_interaction_graph")
# Constructing a graph via delaunay triangulation
spe <- buildSpatialGraph(spe, img_id = "sample_id",
type = "delaunay")
colPair(spe, "delaunay_interaction_graph")
# Constructing a graph via k nearest neighbor search
spe <- buildSpatialGraph(spe, img_id = "sample_id",
type = "knn", k = 5)
colPair(spe, "knn_interaction_graph")