10x-Visum Spatial Data Analysis

knitr::opts_chunk$set(echo = TRUE)

Introduction

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 .

Installation

if(!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("SpatialExperiment")

Loading required libraries

library("SpatialExperiment")
library("Matrix")
library("rjson")

Data Loading

Examples data files have been downloaded from the 10x site, Mouse adult brain

Features

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)

Spatial Coordinates

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"))

Image paths

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)

Spatial Scale Factors

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)

VisiumExperiment

Creation

Creating VisiumExperiment class within 10x Visium data.

ve <- VisiumExperiment(rowData=featuresEx, colData=barcodesEx, 
                            assays=c(counts=countsEx), 
                            spatialCoords=tissPosEx,
                            scaleFactors=scalefactors)
ve

Methods

Retrieving Spatial Coordinates

The spatialCoords methods can be used to retrieve the spatial coordinates., It can be used also to update the values.

spatialCoords(ve)

Image get/set

Image paths can be handled with the VisiumExperiment class by aid of the imagePaths methods.

imagePaths(ve) <- imageFilePath
imagePaths(ve)

Scale Factors

Scale Factors stored during VisiumExperiment class creation can be get/set with scaleFactors method.

scaleFactors(ve)

Number of array barcoded-spots covered by tissue

The isInTissue method can be used to know which and how many spots are covered by the tissue.

sum(isInTissue(ve))
ve[isInTissue(ve)]

Session Info

sessionInfo()


Try the SpatialExperiment package in your browser

Any scripts or data that you put into this service are public.

SpatialExperiment documentation built on Nov. 8, 2020, 7:35 p.m.