Spatial transcriptomics


Spatial transcriptomic data with the Visium platform is in many ways similar to scRNAseq data. It contains UMI counts for 5-20 cells instead of single cells, but is still quite sparse in the same way as scRNAseq data is, but with the additional information about spatial location in the tissue.

Here we will first run quality control in a similar manner to scRNAseq data, then QC filtering, dimensionality reduction, integration and clustering. Then we will use scRNAseq data from mouse cortex to run LabelTransfer to predict celltypes in the Visium spots.

We will use two Visium spatial transcriptomics dataset of the mouse brain (Sagittal), which are publicly available from the 10x genomics website. Note, that these dataset have already been filtered for spots that does not overlap with the tissue.

Load packages

mkdir -p data/visium/Posterior
mkdir -p data/visium/Anterior

cd data/visium/Posterior

curl -o V1_Mouse_Brain_Sagittal_Posterior_filtered_feature_bc_matrix.tar.gz https://cf.10xgenomics.com/samples/spatial-exp/1.1.0/V1_Mouse_Brain_Sagittal_Posterior/V1_Mouse_Brain_Sagittal_Posterior_filtered_feature_bc_matrix.tar.gz
tar xvzf V1_Mouse_Brain_Sagittal_Posterior_filtered_feature_bc_matrix.tar.gz

curl -o V1_Mouse_Brain_Sagittal_Posterior_spatial.tar.gz https://cf.10xgenomics.com/samples/spatial-exp/1.1.0/V1_Mouse_Brain_Sagittal_Posterior/V1_Mouse_Brain_Sagittal_Posterior_spatial.tar.gz
tar xvzf V1_Mouse_Brain_Sagittal_Posterior_spatial.tar.gz
rm *.tar.gz

cd ../Anterior

curl -o V1_Mouse_Brain_Sagittal_Anterior_filtered_feature_bc_matrix.tar.gz https://cf.10xgenomics.com/samples/spatial-exp/1.1.0/V1_Mouse_Brain_Sagittal_Anterior/V1_Mouse_Brain_Sagittal_Anterior_filtered_feature_bc_matrix.tar.gz
tar xvzf V1_Mouse_Brain_Sagittal_Anterior_filtered_feature_bc_matrix.tar.gz

curl -o V1_Mouse_Brain_Sagittal_Anterior_spatial.tar.gz https://cf.10xgenomics.com/samples/spatial-exp/1.1.0/V1_Mouse_Brain_Sagittal_Anterior/V1_Mouse_Brain_Sagittal_Anterior_spatial.tar.gz
tar xvzf V1_Mouse_Brain_Sagittal_Anterior_spatial.tar.gz
rm *.tar.gz
cd ..
##   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
##                                  Dload  Upload   Total   Spent    Left  Speed
## 
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0 54.8M    0  270k    0     0  1557k      0  0:00:36 --:--:--  0:00:36 1548k
  9 54.8M    9 5054k    0     0  4298k      0  0:00:13  0:00:01  0:00:12 4294k
 17 54.8M   17 9726k    0     0  4474k      0  0:00:12  0:00:02  0:00:10 4472k
 26 54.8M   26 14.4M    0     0  4655k      0  0:00:12  0:00:03  0:00:09 4655k
 33 54.8M   33 18.5M    0     0  4541k      0  0:00:12  0:00:04  0:00:08 4540k
 41 54.8M   41 22.7M    0     0  4491k      0  0:00:12  0:00:05  0:00:07 4593k
 50 54.8M   50 27.5M    0     0  4567k      0  0:00:12  0:00:06  0:00:06 4630k
 58 54.8M   58 31.9M    0     0  4563k      0  0:00:12  0:00:07  0:00:05 4602k
 66 54.8M   66 36.6M    0     0  4588k      0  0:00:12  0:00:08  0:00:04 4546k
 75 54.8M   75 41.4M    0     0  4619k      0  0:00:12  0:00:09  0:00:03 4685k
 81 54.8M   81 44.8M    0     0  4515k      0  0:00:12  0:00:10  0:00:02 4539k
 89 54.8M   89 49.1M    0     0  4503k      0  0:00:12  0:00:11  0:00:01 4423k
 98 54.8M   98 53.7M    0     0  4521k      0  0:00:12  0:00:12 --:--:-- 4460k
100 54.8M  100 54.8M    0     0  4535k      0  0:00:12  0:00:12 --:--:-- 4432k
## filtered_feature_bc_matrix/
## filtered_feature_bc_matrix/barcodes.tsv.gz
## filtered_feature_bc_matrix/matrix.mtx.gz
## filtered_feature_bc_matrix/features.tsv.gz
##   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
##                                  Dload  Upload   Total   Spent    Left  Speed
## 
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  7 9480k    7  754k    0     0  2328k      0  0:00:04 --:--:--  0:00:04 2328k
 59 9480k   59 5679k    0     0  4296k      0  0:00:02  0:00:01  0:00:01 4293k
100 9480k  100 9480k    0     0  4436k      0  0:00:02  0:00:02 --:--:-- 4438k
## spatial/
## spatial/tissue_positions_list.csv
## spatial/tissue_hires_image.png
## spatial/scalefactors_json.json
## spatial/aligned_fiducials.jpg
## spatial/detected_tissue_image.jpg
## spatial/tissue_lowres_image.png
##   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
##                                  Dload  Upload   Total   Spent    Left  Speed
## 
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  5 54.8M    5 3006k    0     0  2965k      0  0:00:18  0:00:01  0:00:17 2968k
 13 54.8M   13 7438k    0     0  3749k      0  0:00:14  0:00:01  0:00:13 3747k
 21 54.8M   21 11.7M    0     0  4041k      0  0:00:13  0:00:02  0:00:11 4039k
 30 54.8M   30 16.8M    0     0  4321k      0  0:00:12  0:00:03  0:00:09 4321k
 39 54.8M   39 21.8M    0     0  4482k      0  0:00:12  0:00:04  0:00:08 4481k
 48 54.8M   48 26.7M    0     0  4570k      0  0:00:12  0:00:05  0:00:07 4897k
 57 54.8M   57 31.6M    0     0  4631k      0  0:00:12  0:00:06  0:00:06 4981k
 66 54.8M   66 36.2M    0     0  4651k      0  0:00:12  0:00:07  0:00:05 5014k
 75 54.8M   75 41.1M    0     0  4685k      0  0:00:11  0:00:08  0:00:03 4975k
 84 54.8M   84 46.2M    0     0  4739k      0  0:00:11  0:00:09  0:00:02 4995k
 92 54.8M   92 50.5M    0     0  4710k      0  0:00:11  0:00:10  0:00:01 4877k
100 54.8M  100 54.8M    0     0  4709k      0  0:00:11  0:00:11 --:--:-- 4820k
## filtered_feature_bc_matrix/
## filtered_feature_bc_matrix/barcodes.tsv.gz
## filtered_feature_bc_matrix/features.tsv.gz
## filtered_feature_bc_matrix/matrix.mtx.gz
##   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
##                                  Dload  Upload   Total   Spent    Left  Speed
## 
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
 24 9017k   24 2174k    0     0  3446k      0  0:00:02 --:--:--  0:00:02 3446k
 81 9017k   81 7342k    0     0  4480k      0  0:00:02  0:00:01  0:00:01 4480k
100 9017k  100 9017k    0     0  4612k      0  0:00:01  0:00:01 --:--:-- 4612k
## spatial/
## spatial/tissue_positions_list.csv
## spatial/tissue_hires_image.png
## spatial/scalefactors_json.json
## spatial/detected_tissue_image.jpg
## spatial/tissue_lowres_image.png
## spatial/aligned_fiducials.jpg
BiocManager::install("DropletUtils", update = F)
devtools::install_github("RachelQueen1/Spaniel", ref = "Development", upgrade = F, 
    dependencies = F)

library(Spaniel)
library(biomaRt)

suppressPackageStartupMessages(require(Matrix))
suppressPackageStartupMessages(require(dplyr))
suppressPack