Given a SpatialExperiment-class
object, first as.Seurat()
is run, which operates on
SingleCellExperiment-class
objects. The remaining components (images, spatial coordinates) are added
manually. The actual appearance of images are buggy for now.
spe_to_seurat(
spe,
spatial_cols = c(tissue = "in_tissue", row = "array_row", col = "array_col", imagerow =
"pxl_row_in_fullres", imagecol = "pxl_col_in_fullres"),
verbose = TRUE
)
A
SpatialExperiment-class with
colData()
or spatialCoords()
columns given by spatial_cols
. This does not have to be a stitched
spe
object as this function should work with any type of spe
objects.
A character(5)
named vector mapping which colData(spe)
or spatialCoords(spe)
columns contain the tissue
, row
, col
,
imagerow
, and imagecol
information expected by Seurat.
A logical(1)
vector. If TRUE
, print status update
about the conversion process. This information can be useful for debugging.
A Seurat
object.
Note that only the lowres
images from imgData(spe)
will be used.
## Download some example data
spe_unstitched <- spatialLIBD::fetch_data(
type = "spatialDLPFC_Visium_example_subset"
)[seq(100), seq(100)]
#> 2024-10-03 14:59:10.874685 loading file /github/home/.cache/R/BiocFileCache/28342ab2682_spatialDLPFC_spe_subset_example.rds%3Fdl%3D1
## Make the column names unique
colnames(spe_unstitched) <- spatialLIBD::add_key(spe_unstitched)$key
#> Overwriting 'spe$key'. Set 'overwrite = FALSE' if you do not want to overwrite it.
## Convert from a SpatialExperiment to a Seurat object
seur <- spe_to_seurat(spe_unstitched)
#> Running 'as.Seurat(spe)'...
#> Warning: Keys should be one or more alphanumeric characters followed by an underscore, setting key from pc. to pc_
#> Warning: Keys should be one or more alphanumeric characters followed by an underscore, setting key from tsne. to tsne_
#> Warning: Keys should be one or more alphanumeric characters followed by an underscore, setting key from umap. to umap_
#> Warning: Keys should be one or more alphanumeric characters followed by an underscore, setting key from PC to PC_
#> Warning: Keys should be one or more alphanumeric characters followed by an underscore, setting key from UMAP to UMAP_
#> Warning: Keys should be one or more alphanumeric characters followed by an underscore, setting key from TSNE_perplexity80_ to TSNEperplexity80_
#> Warning: Keys should be one or more alphanumeric characters followed by an underscore, setting key from UMAP to UMAP_
#> Warning: Key ‘UMAP_’ taken, using ‘umapharmony_’ instead
#> Adding spot coordinates and images for sample Br6432_ant...
#> Returning converted object...
seur
#> An object of class Seurat
#> 100 features across 100 samples within 1 assay
#> Active assay: originalexp (100 features, 0 variable features)
#> 2 layers present: counts, data
#> 8 dimensional reductions calculated: X10x_pca, X10x_tsne, X10x_umap, PCA, UMAP, TSNE_perplexity80, HARMONY, UMAP.HARMONY
#> 1 image present: Br6432_ant
## Example with an stitched SPE object
if (!exists("spe")) {
spe <- spatialLIBD::fetch_data(type = "visiumStitched_brain_spe")
}
#> 2024-10-03 14:59:15.3522 loading file /github/home/.cache/R/BiocFileCache/1bd64fd865f7_visiumStitched_brain_spe.rds%3Frlkey%3Dnq6a82u23xuu9hohr86oodwdi%26dl%3D1
seur_stitched <- spe_to_seurat(spe[seq(100), seq(100)])
#> Running 'as.Seurat(spe)'...
#> Warning: Keys should be one or more alphanumeric characters followed by an underscore, setting key from PC to PC_
#> Adding spot coordinates and images for sample Br2719...
#> Returning converted object...
## Let's look at our resulting Seurat object
seur_stitched
#> An object of class Seurat
#> 100 features across 100 samples within 1 assay
#> Active assay: originalexp (100 features, 0 variable features)
#> 2 layers present: counts, data
#> 1 dimensional reduction calculated: PCA
#> 1 image present: Br2719