This Rmarkdown file will load all libraries and the dataset for use in today’s workshop.
Rerun these commands to restart at any of the subsequent steps.
Load all libraries used today. They are already installed on these VMs.
library(tidyverse)
library(patchwork) # + / notation for side-by-side ggplots
library(SpatialFeatureExperiment) # The data object we will work with - inherits from single cell experiment
library(Voyager) # Package with alot of useful plotting and spatial methods.
library(alabaster.sfe) # An efficient way to save SFE objects to disk. "Builds upon the existing ArtifactDB project, expending alabaster.spatial for language agnostic on disk serialization of SpatialFeatureExperiment. "
library(DT) # For pretty html rendering of big tables.
library(scuttle) # Useful SCE functions like 'aggregateAcrossCells'
library(scater) # Useful SCE functions like 'plotExpression'
library(limma) # for differential expression
library(edgeR) # for differential expression
library(spicyR) # For testing celltype coocurance
This workshop will use CosMx Spatial Molecular Imager (SMI) data from the paper “Macrophage and neutrophil heterogeneity at single-cell spatial resolution in human inflammatory bowel disease” (Garrido-Trigo et al. 2023) - link: https://www.nature.com/articles/s41467-023-40156-6
We will be using a small subset of data from that study, which has already been preprocessed. We will also be loading some derived data saved in some other objects. Here we specify their location.
spe_02_banksy_niches_file <- file.path("data/GSE234713_CosMx_IBD_sfe_mini_02_banksy_niches")
spe_pseudobulk_by_celltype_file <- file.path("data/GSE234713_CosMx_IBD_sfe_mini_pseudobulk_by_celltype.RDS")
spe_pseudobulk_by_niche_file <- file.path("data/GSE234713_CosMx_IBD_sfe_mini_pseudobulk_by_niche.RDS")
spe_pseudobulk_by_celltype_in_niche_file <- file.path("data/GSE234713_CosMx_IBD_sfe_mini_pseudobulk_by_celltype_in_niche.RDS")
Here we load the preprocessed data.
Our main data object is a SpatialFeatureExperiment (SFE) object - which behaves like other data formats in the bioconductor ecosystem (SingleCellExperiment, SummarisedExperiment).
It was saved using the alabaster system (designed for handling large datasets like this) spatialFeatureExperiment, so we load it with the special readObject() function from that package.
We also make two single-sample subsets that we’ll keep using for plotting.
# Load a spatialFeatureExperiment object (a type of SingleCellExperiment)
sfe <- readObject(spe_02_banksy_niches_file)
## >>> Reading SpatialExperiment
## >>> Reading colgeometries
# And subset to one sample, for later plotting.
sfe.sample.HC <- sfe[,sfe$tissue_sample == 'HC_b']
sfe.sample.CD <- sfe[,sfe$tissue_sample == 'CD_a']