Extract spatial coordinates and (optionally) cluster assignments from
a Seurat object, a SpatialExperiment object,
or a user-supplied data frame.
Arguments
- data
A
Seuratobject, aSpatialExperimentobject, or a data frame containing spatial coordinates.- cluster_col
Character scalar specifying the metadata column name containing cluster assignments. If
NULL, a default is used depending on the input object type:"seurat_clusters"forSeuratobjects"cluster"forSpatialExperimentobjects"cluster"fordata.frameobjects
- extract_cluster
Logical indicating whether to extract cluster information. If
FALSE, only spatial coordinates and cell IDs are returned. Default isTRUE.- ...
Additional arguments (unused).
Value
A data frame containing columns x, y, and cell,
and optionally cluster.
For Seurat and SpatialExperiment
inputs, only these standardized columns are returned.
For data.frame
input, additional columns present in the input may also be retained.
Details
This is an S3 generic with methods implemented for
Seurat, SpatialExperiment, and data.frame.
Examples
coords <- readRDS(system.file(
"extdata", "MouseBrainCoords.rds",
package = "SpNeigh"
))
head(extractCoords(coords))
#> x y cell cluster
#> 1 1898.815 2540.963 1 4
#> 2 1895.305 2532.627 2 4
#> 3 2368.073 2534.409 3 2
#> 4 1903.726 2560.010 4 4
#> 5 1917.481 2543.132 5 4
#> 6 1926.540 2560.044 6 4
head(extractCoords(coords, extract_cluster = FALSE))
#> x y cell cluster
#> 1 1898.815 2540.963 1 4
#> 2 1895.305 2532.627 2 4
#> 3 2368.073 2534.409 3 2
#> 4 1903.726 2560.010 4 4
#> 5 1917.481 2543.132 5 4
#> 6 1926.540 2560.044 6 4