SpatialFeatureExperiment-coercion | R Documentation |
The SpatialFeatureExperiment
class inherits from
SpatialExperiment
, which in turn inherits from
SingleCellExperiment
. A SpatialExperiment
object with
geometries in colGeometries
in the int_colData
,
rowGeometries
in the int_elementMetadata
, or
annotGeometries
in the int_metadata
can be directly converted
to SpatialFeatureExperiment
with as(spe,
"SpatialFeatureExperiment")
. A SpatialExperiment
object without the
geometries can also be converted; the coordinates in the spatialCoords
field will be used to make POINT geometries named "centroids" to add to
colGeometries
. The geometries can also be supplied separately when
using toSpatialFeatureExperiment
. Images are converted to SpatRaster
.
## S4 method for signature 'SpatialExperiment'
toSpatialFeatureExperiment(
x,
colGeometries = NULL,
rowGeometries = NULL,
annotGeometries = NULL,
spatialCoordsNames = c("x", "y"),
annotGeometryType = "POLYGON",
spatialGraphs = NULL,
spotDiameter = NA,
unit = NULL
)
## S4 method for signature 'SingleCellExperiment'
toSpatialFeatureExperiment(
x,
sample_id = "sample01",
spatialCoordsNames = c("x", "y"),
spatialCoords = NULL,
colGeometries = NULL,
rowGeometries = NULL,
annotGeometries = NULL,
annotGeometryType = "POLYGON",
spatialGraphs = NULL,
spotDiameter = NA,
scaleFactors = 1,
imageSources = NULL,
image_id = NULL,
loadImage = TRUE,
imgData = NULL,
unit = NULL
)
## S4 method for signature 'Seurat'
toSpatialFeatureExperiment(
x,
add_molecules = TRUE,
flip = c("geometry", "image", "none"),
image_scalefactors = c("lowres", "hires"),
unit = NULL,
BPPARAM = SerialParam()
)
x |
A |
colGeometries |
Geometry of the entities that correspond to the columns of the gene count matrix, such as cells and Visium spots. It must be a named list of one of the following:
In all cases, the data frame should specify
the same number of geometries as the number of columns in the gene count
matrix. If the column "barcode" is present, then it will be matched to
column names of the gene count matrix. Otherwise, the geometries are
assumed to be in the same order as columns in the gene count matrix. If the
geometries are specified in an ordinary data frame, then it will be
converted into |
rowGeometries |
Geometry associated with genes or features, which correspond to rows of the gene count matrix. |
annotGeometries |
Geometry of entities that do not correspond to columns
or rows of the gene count matrix, such as tissue boundary and pathologist
annotations of histological regions, and nuclei segmentation in a Visium
dataset. Also a named list as in |
spatialCoordsNames |
A |
annotGeometryType |
Character vector specifying geometry type of each
element of the list if |
spatialGraphs |
A named list of |
spotDiameter |
Spot diameter for technologies with arrays of spots of fixed diameter per slide, such as Visium, ST, DBiT-seq, and slide-seq. The diameter must be in the same unit as the coordinates in the *Geometry arguments. Ignored for geometries that are not POINT or MULTIPOINT. |
unit |
# Default unit is |
sample_id |
A |
spatialCoords |
A numeric matrix containing columns of spatial
coordinates, as in |
scaleFactors |
Optional scale factors associated with the image(s). This
can be provided as a numeric value, numeric vector, list, or file path to a
JSON file for the 10x Genomics Visium platform. For 10x Genomics Visium,
the correct scale factor will automatically be selected depending on the
resolution of the image from |
imageSources |
Optional file path(s) or URL(s) for one or more image sources. |
image_id |
Optional character vector (same length as
|
loadImage |
Logical indicating whether to load image into memory.
Default = |
imgData |
Optional |
add_molecules |
Logical, whether to add transcripts coordinates to an object. |
flip |
To flip the image, geometry coordinates, or none. Because the image has the origin at the top left while the geometry has origin at the bottom left, one of them needs to be flipped for them to match. If one of them is already flipped, then use "none". The image will not be flipped if it's GeoTIFF. |
image_scalefactors |
# A |
BPPARAM |
Deprecated when coercing from |
A SpatialFeatureExperiment
object
library(SpatialExperiment)
example(read10xVisium)
# There can't be duplicate barcodes
colnames(spe) <- make.unique(colnames(spe), sep = "-")
rownames(spatialCoords(spe)) <- colnames(spe)
sfe <- toSpatialFeatureExperiment(spe)
# For coercing Seurat to SFE see this -> ./vignettes/seurat_sfe_coerce.Rmd
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.