The package can be loaded with the command:
To fit DR-SC model, we first require to create a Seurat object with meta.data including spatial coordinates in columns must named “row” (x coordinates) and “col” (y coordinates)!
We start this tutorial with creating the Seurat object. Users who are familar with Seurat object, can skip this subsection and go to next subsection.
First, we load the subset data of DLPFC 151510, dlpfc151510. Although it is saved as a Seurat object prepared for DR-SC, we re-create the Seurat object to show how to prepare the Seurat object for DR-SC.
Second, we create a Seurat object using the count matrix in dlpfc151510 and the spatial coordinates in the meta.data slot.
library(Seurat)
count <- dlpfc151510@assays$RNA@counts
meta_data <- data.frame(row=dlpfc151510@meta.data$row, col=dlpfc151510@meta.data$col, annotation=dlpfc151510$annotation)
row.names(meta_data) <- colnames(count)
## create Seurat object
dlpfc151510 <- CreateSeuratObject(counts=count, meta.data = meta_data)
head(dlpfc151510)
Until now, the data preparation with Seurat object format is finished, and we can go to next step: preprocessing.
This preprocessing includes Log-normalization and feature selection. Here we select highly variable genes for example first. The selected genes’ names are saved in “seu@assays$RNA@var.features”
We fit the DR-SC model by using the highly variable genes.
Show the tSNE plot based on the extracted features from DR-SC.
Show the UMAP plot based on the extracted features from DR-SC.
In spatially resolved transcriptomics data analysis, we recommend users using the spatially variable genes for analysis. We embeded the method SPARK-X (developed by Xiang Zhou’s Lab) into DR.SC package, which can be called using FindSVGs
. The selected genes’ names are also saved in “seus@assays$RNA@var.features” and the order is determined by the statistical significance, where the gene with highest significance ranks first. We note there are some difference between SVGs and HVGs.
# choose 480 spatially variable features
seus <- FindSVGs(seu, nfeatures = 480)
seus@assays$RNA@var.features[1:10]
We fit DR-SC model by using the selected spatially variable genes.
Next, we show the application of DR-SC in visualization. First, we can visualize the clusters from DR-SC on the spatial coordinates.
We can also visualize the clusters from DR-SC on the two-dimensional tSNE based on the extracted features from DR-SC.
Similarly, can also visualize the clusters from DR-SC on the two-dimensional UMAP based on the extracted features from DR-SC.
Since DR.SC uses the Seurat object to save results, all visualization functions in Seurat package can used to visualize the results of DR-SC, such as ridge plot, feature plot, dot plot and so on. ### Ridge plots we show the application of DR-SC in differential expression analysis. Find the marker genes in SVGs for each clusters.
SVGs <- topSVGs(seus, ntop = 400)
dat <- FindAllMarkers(seus, features = SVGs)
head(dat)
library(dplyr, verbose=F)
top2 <- dat %>%
group_by(cluster) %>%
top_n(n = 2, wt = avg_log2FC)
top2
Visualize single cell expression distributions in each cluster from Seruat.
Visualize single cell expression distributions in each cluster
We extract tSNE based on the features from DR-SC and then visualize feature expression in the low-dimensional space
The size of the dot corresponds to the percentage of cells expressing the feature in each cluster. The color represents the average expression level
Single cell heatmap of feature expression
We set the argument variable.type=‘SVGs’ (default option) to use the spatially variable genes.
Plot the MBIC curve
Show the spatial scatter plot for clusters
Show the tSNE plot based on the extracted features from DR-SC.