SpatialExperiment-methods {SpatialExperiment} | R Documentation |
The SpatialExperiment
class provides a family of methods to get
and set spatial data attributes in SpatialExperiment
objects.
Spatial attributes include spatialData
, spatialCoords
,
imgData
, and scaleFactors
.
## S4 method for signature 'SpatialExperiment' spatialData(x, spatialCoords = FALSE, colData = FALSE) ## S4 replacement method for signature 'SpatialExperiment,DFrame' spatialData(x) <- value ## S4 replacement method for signature 'SpatialExperiment,'NULL'' spatialData(x) <- value ## S4 method for signature 'SpatialExperiment' spatialDataNames(x) ## S4 replacement method for signature 'SpatialExperiment,character' spatialDataNames(x) <- value ## S4 replacement method for signature 'SpatialExperiment,'NULL'' spatialDataNames(x) <- value ## S4 method for signature 'SpatialExperiment' spatialCoords(x) ## S4 replacement method for signature 'SpatialExperiment,matrix' spatialCoords(x) <- value ## S4 replacement method for signature 'SpatialExperiment,'NULL'' spatialCoords(x) <- value ## S4 method for signature 'SpatialExperiment' spatialCoordsNames(x) ## S4 replacement method for signature 'SpatialExperiment,character' spatialCoordsNames(x) <- value ## S4 replacement method for signature 'SpatialExperiment,'NULL'' spatialCoordsNames(x) <- value ## S4 method for signature 'SpatialExperiment' scaleFactors(x, sample_id = TRUE, image_id = TRUE) ## S4 method for signature 'SpatialExperiment' imgData(x) ## S4 replacement method for signature 'SpatialExperiment,DataFrame' imgData(x) <- value ## S4 replacement method for signature 'SpatialExperiment,'NULL'' imgData(x) <- value
x |
A |
spatialCoords |
Logical specifying whether to include columns from
|
colData |
Logical or character vector specifying any additional columns
from |
value |
Replacement value for replacement methods. |
sample_id |
Logical value or character vector specifying sample
identifier(s) for |
image_id |
Logical value or character vector specifying image
identifier(s) for |
Additional details for each type of data attribute are provided below.
spatialData
and spatialCoords
are distinguished
as follows: spatialData
is a DataFrame
containing all the data
associated with the spatial information (optionally including spatial
coordinates from spatialCoords
), while spatialCoords
is a
numeric matrix containing only the defined spatial coordinates (e.g. columns
x
and y
).
Return value varies depending on method, as described below.
spatialData(x)
: The spatialData
getter provides the
optional arguments spatialCoords
and colData
, which can be used
to include the columns of spatial coordinates (spatialCoords
) and any
additional columns from colData
in the output DataFrame
.
spatialData(x) <- value
: The spatialData
setter expects
a data.frame
or DataFrame
with the defined column names for the
spatial coordinates. Spatial coordinate names can be set with the
spatialCoordNames
setter, and are set as c("x", "y")
by default
by the SpatialExperiment
constructor. If the input does not
contain an in_tissue
column, this will be included with a default
value of 1
.
spatialCoords(x)
: Getter for numeric matrix of spatial coordinates.
spatialCoords(x) <- value
: Setter for numeric matrix of spatial coordinates.
spatialDataNames(x)
: Returns the column names of the
spatialData
DataFrame
.
spatialDataNames(x) <- value
: Setter to replace column names
in the spatialData
DataFrame
.
spatialCoordsNames(x)
: Returns the defined names of the
spatial coordinates (e.g. c("x", "y")
).
spatialCoordsNames(x) <- value
: Setter to define the names of the spatial coordinate columns.
imgData(x)
: Getter to return the imgData
DataFrame
.
imgData(x) <- value
: Setter to provide a DataFrame
object as imgData
of the SpatialExperiment
object.
scaleFactors(x, sample_id, image_id)
: Getter to return the
scale factors associated with the sample_id
(s) and image_id
(s)
provided. This is related to the stored image(s) in the
SpatialExperiment
imgData
structure. See argument descriptions
for further details.
example(read10xVisium) # spatialData returns a DataFrame spatialData(spe) # spatialCoords returns a numeric matrix head(spatialCoords(spe)) # spatialData replacement method spdata <- spatialData(spe) spdata$array_col <- spdata$array_row spatialData(spe) <- spdata # return additional columns for spatialData spatialData(spe, spatialCoords=TRUE, colData="sample_id") # change spatial coordinate names spatialCoordsNames(spe) spatialCoordsNames(spe) <- c("x", "y") head(spatialCoords(spe)) # imgData and scale factors imgData(spe) scaleFactors(spe) # tabulate number of spots mapped to tissue table( in_tissue = spe$in_tissue, sample_id = spe$sample_id)