Build a k-nearest-neighbor or radius spatial network from raw Seurat spatial coordinates. Results are stored as named graphs in `srt@tools$SpatialNetwork`.
Arguments
- srt
A `Seurat` object.
- method
Network method, either `"knn"` or `"radius"`.
- image
Seurat image name. A single image is selected automatically; multi-image objects require an explicit value.
- coord.cols
Metadata columns used when the object has no image.
- k
Number of neighbors for `method = "knn"`.
- radius
Positive distance threshold for `method = "radius"`, expressed in the raw coordinate units.
- graph.name
Optional graph name. If `NULL`, a deterministic name is generated from the image, method, and method parameter.
- overwrite
Whether an existing graph with the same name may be replaced.
- verbose
Whether to print the message. Default is
TRUE.
Examples
counts <- matrix(
c(3, 1, 0, 2, 0, 4, 1, 0, 2, 1, 3, 0),
nrow = 3,
dimnames = list(paste0("gene", 1:3), paste0("spot", 1:4))
)
srt <- SeuratObject::CreateSeuratObject(counts)
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
srt$col <- c(0, 1, 0, 1)
srt$row <- c(0, 0, 1, 1)
srt <- RunSpatialNetwork(srt, k = 2, verbose = FALSE)
SpatialNetworkPlot(srt)