knitr::opts_chunk$set(echo = TRUE)
The SpatialExperiment package provides classes and methods for single cell spatial data handling.
The VisiumExperiment class exteds the SpatialExperiment class by providing more specific attributes and methods for the 10x-Genomics Visium experiments data.
This vignettes shows how to create a VisiumExperiment class by loading a Mouse Coronal 10x-Genomics Visium spatial dataset.
Dataset downloaded from 10x-Genomics website .
if(!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager") BiocManager::install("SpatialExperiment")
library("SpatialExperiment") library("Matrix") library("rjson")
Examples data files have been downloaded from the 10x site, Mouse adult brain
Loading features and count matrix.
barcodesFile <- system.file(file.path("extdata", "10x_visium", "barcodes.tsv"), package="SpatialExperiment") barcodesEx <- read.csv(barcodesFile, sep="\t", header=FALSE, col.names=c("Cell_ID")) featuresFile <- system.file(file.path("extdata", "10x_visium", "features.tsv"), package="SpatialExperiment") featuresEx <- read.csv(featuresFile, sep="\t", header=FALSE, col.names=c("Feature_ID", "Feature_name", "Feature_type")) countsFile <- system.file(file.path("extdata", "10x_visium", "matrix.mtx"), package="SpatialExperiment") countsEx <- readMM(file=countsFile)
Loading Spatial coordinates of the tissue section.
posFile <- system.file(file.path("extdata", "10x_visium", "tissue_positions_list.tsv"), package="SpatialExperiment") tissPosEx <- read.csv(posFile, sep="\t", header=FALSE, col.names=c("Cell_ID", "in_tissue", "array_row", "array_col", "pxl_col_in_fullres", "pxl_row_in_fullres"))
10x-Genomics Visium experiments comes out with images in different resolutions for tissue spots locations.
imageFilePath <- list.files(system.file(file.path("extdata", "10x_visium", "images"), package="SpatialExperiment"), full.names=TRUE)
Scale factors for the given three 10x Visium image formats transformations.
scaleFile <- system.file(file.path("extdata", "10x_visium", "scalefactors_json.json"), package="SpatialExperiment") scalefactors <- fromJSON(file=scaleFile)
Creating VisiumExperiment class within 10x Visium data.
ve <- VisiumExperiment(rowData=featuresEx, colData=barcodesEx, assays=c(counts=countsEx), spatialCoords=tissPosEx, scaleFactors=scalefactors) ve
The spatialCoords methods can be used to retrieve the spatial coordinates., It can be used also to update the values.
spatialCoords(ve)
Image paths can be handled with the VisiumExperiment class by aid of the
imagePaths
methods.
imagePaths(ve) <- imageFilePath imagePaths(ve)
Scale Factors stored during VisiumExperiment class creation can be get/set
with scaleFactors
method.
scaleFactors(ve)
The isInTissue method can be used to know which and how many spots are covered by the tissue.
sum(isInTissue(ve)) ve[isInTissue(ve)]
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.