S3 generic function for coercing objects into a GraphSpace object.
Usage
as.GraphSpace(x, ...)
# Default S3 method
as.GraphSpace(x, ...)
# S3 method for class 'igraph'
as.GraphSpace(x, ...)
# S3 method for class 'tbl_graph'
as.GraphSpace(x, ...)
# S3 method for class 'data.frame'
as.GraphSpace(x, ...)
# S3 method for class 'DFrame'
as.GraphSpace(x, ...)
# S3 method for class 'matrix'
as.GraphSpace(x, ...)
# S3 method for class 'SpatialExperiment'
as.GraphSpace(x, assay = "counts", ...)
# S3 method for class 'Seurat'
as.GraphSpace(x, layer = NULL, space = c("embedding", "spatial"), ...)Arguments
- x
An object to be converted.
- ...
Additional arguments passed to coercion methods.
- assay
Name of the assay in the
SpatialExperimentobject from which data should be retrieved (seeassay).- layer
Name of the layer in the
Seuratobject from which node data should be retrieved (seeLayerData).- space
Character specifying the coordinate space used for node geometry. Either
"embedding"or"spatial". See details.
Details
Unified entry point for converting graph, spatial, and high-dimensional
data into a GraphSpace object.
Graph objects are imported either through native methods or via as_tbl_graph when available.
For Seurat objects, coordinate extraction depends on the
selected space:
space = "embedding"uses the first two dimensions returned byEmbeddings.space = "spatial"uses tissue coordinates returned byGetTissueCoordinates.
Assay data are stored in the data slot of the resulting
GraphSpace object. Node metadata from x@meta.data are
appended to the node table.
Examples
data('gtoy1', package = 'RGraphSpace')
# From igraph or tidygraph objects
gs <- as.GraphSpace(gtoy1)
#> Validating the 'igraph' object...
#> Ignoring graph-level attributes: 'name', 'mode', 'center'
#> Creating a 'GraphSpace' object...
gs <- as.GraphSpace(tidygraph::as_tbl_graph(gtoy1))
#> Validating the 'igraph' object...
#> Ignoring graph-level attributes: 'name', 'mode', 'center'
#> Creating a 'GraphSpace' object...
# From a data.frame of node coordinates (a graph without edges)
df <- data.frame(x = c(0, 1, 2), y = c(0, 1, 0),
row.names = c("a", "b", "c"))
gs <- as.GraphSpace(df)
#> Converting input data to an 'igraph' object...
#> Validating the 'igraph' object...
#> Creating a 'GraphSpace' object...