Spatial Transcriptomics Data Processing

Author

Ahmed M. Elhossiny

1 Setup & Data Loading

Here we load essential packages and visium_samples_manifest.xlsx from the data directory, that includes information and metadata about visium samples. We use Seurat v5 (Hao et al. 2023) as data container for processing and visualization. The columns used from this manifest are:

Column Description Example
patient_id patient/donor identifier patient_1
cellranger_3.0.1_output_path path to the SpaceRanger outs directory path/to/sample_1/outs

Note: this is a separate file from the visium_samples_manifest.txt used in SpaceRanger Alignment, which is formatted for the alignment shell script rather than for loading into R.

Code
suppressPackageStartupMessages({
  library(Seurat)
  library(tidyverse)
  library(parallel)
  library(scCustomize)
  library(SPATA2)
  library(qs)
  library(CellChat)
})

# loading manifest ------------------------------------------------------------

visium_samples <- readxl::read_xlsx("../data/visium_samples_manifest.xlsx")

# processing data ------------------------------------------------------------

outputDir <- "outputs/Preprocessing/spatial_seurat_objects/"
dir.create(outputDir, showWarnings = F, recursive = T)

2 Seurat Object Preparation

Here we generate spatial Seurat objects for each patient sample, and save them separately. They will be merged later in Clustering Analysis with deconvolution and clustering results

Code
lapply(visium_samples$patient_id, function(x){
  message(x)
  path <- visium_samples %>% filter(patient_id == x) %>% pull(cellranger_3.0.1_output_path)
  seurat_obj <- Load10X_Spatial(path)
  seurat_obj <- NormalizeData(seurat_obj)
  seurat_obj <- ScaleData(seurat_obj)
  saveRDS(seurat_obj, paste0(outputDir, x,".rds"))
})

References

Hao, Yuhan, Tim Stuart, Madeline H Kowalski, et al. 2023. “Dictionary Learning for Integrative, Multimodal and Scalable Single-Cell Analysis.” Nature Biotechnology, ahead of print. https://doi.org/10.1038/s41587-023-01767-y.