First, we generate the spatial transcriptomics data with lattice
neighborhood, i.e. ST platform by using the function
gendata_RNAExp
in DR.SC
package.
library(DR.SC)
<- gendata_RNAExp(height=30, width=30,p=500, K=4)
seu head(seu@meta.data)
For function DR.SC
, users can specify the number of
clusters \(K\) or set K
to
be an integer vector by using modified BIC(MBIC) to determine \(K\). First, we try using user-specified
number of clusters. Then we show the version chosen by MBIC.
### Given K
library(Seurat)
<- NormalizeData(seu)
seu # choose 2000 variable features using Seurat
<- FindVariableFeatures(seu, nfeatures = 400)
seu <- DR.SC(seu, K=4, platform = 'ST', verbose=F) seu2
Using ARI to check the performance of clustering
::adjustedRandIndex(seu2$spatial.drsc.cluster, seu$true_clusters) mclust
Show the spatial scatter plot for clusters
spatialPlotClusters(seu2)
Show the tSNE plot based on the extracted features from DR-SC.
drscPlot(seu2)
Show the UMAP plot based on the extracted features from DR-SC.
drscPlot(seu2, visu.method = 'UMAP')
Use MBIC to choose number of clusters:
<- DR.SC(seu, q=10, K=2:6, platform = 'ST', verbose=F)
seu2 mbicPlot(seu2)
First, we select the spatilly variable genes using funciton
FindSVGs
.
### Given K
<- NormalizeData(seu, verbose=F)
seu # choose 400 spatially variable features using FindSVGs
<- FindSVGs(seu, nfeatures = 400, verbose = F)
seus <- DR.SC(seus, K=4, platform = 'ST', verbose=F) seu2
Using ARI to check the performance of clustering
::adjustedRandIndex(seu2$spatial.drsc.cluster, seu$true_clusters) mclust
Show the spatial scatter plot for clusters
spatialPlotClusters(seu2)
Show the tSNE plot based on the extracted features from DR-SC.
drscPlot(seu2)
Show the UMAP plot based on the extracted features from DR-SC.
drscPlot(seu2, visu.method = 'UMAP')
Use MBIC to choose number of clusters:
<- DR.SC(seus, q=10, K=2:6, platform = 'ST', verbose=F)
seu2 mbicPlot(seu2)
# or plot BIC or AIC
# mbicPlot(seu2, criteria = 'BIC')
# mbicPlot(seu2, criteria = 'AIC')
# tune pen.const
<- selectModel(seu2, pen.const = 0.7)
seu2 mbicPlot(seu2)
Conduct visualization of marker gene expression. ### Ridge plots Visualize single cell expression distributions in each cluster from Seruat.
<- FindAllMarkers(seu2)
dat suppressPackageStartupMessages(library(dplyr) )
# Find the top 1 marker genes, user can change n to access more marker genes
%>%group_by(cluster) %>%
dat top_n(n = 1, wt = avg_log2FC) -> top
<- top$gene
genes RidgePlot(seu2, features = genes, ncol = 2)
Visualize single cell expression distributions in each cluster
VlnPlot(seu2, features = genes, ncol=2)
We extract tSNE based on the features from DR-SC and then visualize feature expression in the low-dimensional space
<- RunTSNE(seu2, reduction="dr-sc", reduction.key='drsctSNE_')
seu2 FeaturePlot(seu2, features = genes, reduction = 'tsne' ,ncol=2)
The size of the dot corresponds to the percentage of cells expressing the feature in each cluster. The color represents the average expression level
DotPlot(seu2, features = genes)
Single cell heatmap of feature expression
# standard scaling (no regression)
%>%group_by(cluster) %>%
dat top_n(n = 30, wt = avg_log2FC) -> top
### select the marker genes that are also the variable genes.
<- intersect(top$gene, seu2[['RNA']]@var.features)
genes ## Change the HVGs to SVGs
# <- topSVGs(seu2, 400)
<- ScaleData(seu2, verbose = F)
seu2 DoHeatmap(subset(seu2, downsample = 500),features = genes, size = 5)
sessionInfo()