The SpatialExperiment package provides classes and methods for single cell spatial data handling.
This vignettes shows how to create a SpatialExperiment class by loading a seqFISH spatial dataset.
The seqFISH data are part of the BIRS Biointegration Workshop Hackathon previously published in Zhu et al. 2018.
if(!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager") BiocManager::install("SpatialExperiment")
We stored the provided seqFish and scRNA-seq data inside the SpatialExperiment external data seqFISH folder.
library(SpatialExperiment)
fishCoordFile <- system.file(file.path("extdata", "seqFISH", "fcortex.coordinates.txt"), package="SpatialExperiment") fishCoordinates <- read.table(fishCoordFile, header=FALSE, sep=" ") colnames(fishCoordinates) <- c("Cell_ID", "Irrelevant", "x", "y") fishCellLabsFile <- system.file(file.path("extdata", "seqFISH", "seqfish_cell_labels.tsv"), package="SpatialExperiment") fishCellLabels <- read.table(file=fishCellLabsFile, header=FALSE, sep="\t") colnames(fishCellLabels) <- c("Cell_ID", "cluster", "class", "classID", "Irrelevant", "Prob") fishFeatCountsFile <- system.file(file.path("extdata", "seqFISH", "seqfish_normalized_cortex_b2_testing.txt"), package="SpatialExperiment") fishFeaturesCounts <- read.table(file=fishFeatCountsFile, header=FALSE, sep="\t", row.names=1)
We can load the data inside the SpatialExperiment class. We then use the show method for looking at the class description.
se <- SpatialExperiment(rowData=rownames(fishFeaturesCounts), colData=fishCellLabels, assays=SimpleList(counts=as.matrix(fishFeaturesCounts)), spatialCoords=fishCoordinates) show(se)
With the aid of the spatialCoords methods we can get and set the spatial coordinates.
spatialCoords(se)
We create a fake fish coordinates data frame and overwrite the old one, showing that the y coordinates are identical to the x ones.
fakeFishCoords <- cbind(fishCoordinates[,c(1:3)], fishCoordinates[,3]) colnames(fakeFishCoords) <- c("Cell_ID", "Irrelevant", "x", "y") spatialCoords(se) <- fakeFishCoords spatialCoords(se)
sessionInfo()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.