最近開發的空間基因表達技術,如空間轉錄組學可以在保留空間背景的同時,全面測量轉錄組譜。然而,現有的空間基因表達數據分析方法往往不能有效利用空間信息,不能解決技術分辨率有限的問題。
在空間數據的分析中,痛點像單細胞轉錄組一樣也是:聚類。我們希望聚出來的類不僅在uamp、tsne這樣的空間中是清楚明了的,也希望在空間坐標中也是這樣。同時也希望找到空間特異的基因表達模式。今天給大家介紹的BayesSpace,正是在做這方面的努力。
BayesSpace是一種完全貝葉斯統計方法,用于聚類分析來增強空間轉錄組數據的分辨率,并且可以無縫集成到當前的轉錄組分析工作流程中。BayesSpace利用多元t分布對基因表達的低維表示進行建模,然后通過Potts模型合并空間信息,這使得相鄰點屬于同一簇。這種方法借鑒了用于圖像分析的成熟的空間統計方法。有效地利用空間信息可以極大地提高了空間數據聚類的性能。
在算法考慮并鼓勵鄰居點屬于同一個簇的原則也可以用來提高點的分辨率到“子點(sub-spot)”水平。這里鼓勵子點屬于同一個簇。子點水平表達有時候并不能直接觀察到,但可以通過反復抖動點水平表達值,通過MCMC進行估計。在實踐中,bayesspace分辨率增強的聚類可以識別重要的生物結構,否則可能會錯過。
我們從10X下載他們做的示例數據,并安裝好了BayesSpace,下面讓我們探索一番,并與Seurat的聚類結果做一個比較。
library(SpatialExperiment)
library(SingleCellExperiment)
library(ggplot2)
library(BayesSpace)
library(Seurat)
library(cowplot)
allcolour=c("#DC143C","#0000FF","#20B2AA","#FFA500","#9370DB","#98FB98","#F08080","#1E90FF","#7CFC00","#FFFF00",
"#808000","#FF00FF","#FA8072","#7B68EE","#9400D3","#800080","#A0522D","#D2B48C","#D2691E","#87CEEB","#40E0D0","#5F9EA0",
"#FF1493","#0000CD","#008B8B","#FFE4B5","#8A2BE2","#228B22","#E9967A","#4682B4","#32CD32","#F0E68C","#FFFFE0","#EE82EE",
"#FF6347","#6A5ACD","#9932CC","#8B008B","#8B4513","#DEB887") # 我最愛的顏色搭配
分別用BayesSpaceh和Seurat讀入數據,這里小哥給Seurat的函數都加Seurat::以表示來自Seurat,以此提示親們函數的來源。同時創建sce和seo兩個對象。
sce <- readVisium("E:\\learnscanpy\\data\\V1_Breast_Cancer_Block_A_Section_1_spatial\\")
sce
seo<-Seurat::Load10X_Spatial("E:\\learnscanpy\\data\\V1_Breast_Cancer_Block_A_Section_1_spatial\\")
seo
先走我們熟悉的Seurat空間流程:
plot1 <- Seurat::VlnPlot(seo, features = "nCount_Spatial", pt.size = 0.1) + NoLegend()
plot2 <- Seurat::SpatialFeaturePlot(seo, features = "nCount_Spatial") + theme(legend.position = "right")
plot_grid(plot1, plot2)
Seurat 默認聚類方法:
seo <- Seurat::SCTransform(seo, assay = "Spatial", return.only.var.genes = FALSE, verbose = FALSE)
seo <- Seurat::RunPCA(seo, assay = "SCT", verbose = FALSE)
seo <- Seurat::FindNeighbors(seo, reduction = "pca", dims = 1:30)
seo <- Seurat::FindClusters(seo, verbose = FALSE)
seo <- Seurat::RunUMAP(seo, reduction = "pca", dims = 1:30)
p1 <- Seurat::DimPlot(seo, reduction = "umap", label = TRUE)
p2 <- Seurat::SpatialDimPlot(seo, label = TRUE, label.size = 3)
plot_grid(p1, p2)
下面我們來用BayesSpace的一般聚類方法,對數據進行聚類。
set.seed(1314)
?spatialPreprocess
sce <- scater::logNormCounts(sce)
sce <- spatialPreprocess(sce, platform="Visium",
n.PCs=7, n.HVGs=2000, log.normalize=FALSE)
sce <- qTune(sce, qs=seq(2, 10), platform="Visium", d=7)
qPlot(sce)
sce
class: SingleCellExperiment
dim: 33538 3813
metadata(2): BayesSpace.data chain.h5
assays(2): counts logcounts
rownames(33538): MIR1302-2HG FAM138A ... AC213203.1 FAM231C
rowData names(3): gene_id gene_name is.HVG
colnames(3813): CAGGATCCGCCCGACC-1 CACGATTGGTCGTTAA-1 ... CGCAGTTCTATCTTTC-1 GACAGGTAATCCGTGT-1
colData names(9): spot in_tissue ... cluster.init spatial.cluster
reducedDimNames(1): PCA
altExpNames(0):
推薦聚類個數:
雖然看到聚成8個是可以的,但是為了和Seurat有一定程度的比較,我們決定用10。
sce <- spatialCluster(sce, q=10, platform="Visium", d=7,
init.method="mclust", model="t", gamma=2,
nrep=1000, burn.in=100, # nrep建議大于10000 ,奈何我們為了演示只能犧牲點了
save.chain=TRUE)
比較一下二者的區別,為了顏色更加明顯,我們用黑色的背景:
p3 <-SpatialDimPlot(seo, label = T, label.size = 3)+ ggtitle("Seurat") +DarkTheme()
p4 <- clusterPlot(sce,label = "spatial.cluster" )+ ggtitle("BayesSpace")+DarkTheme()
plot_grid(p3, p4)
可以看到,Seurat默認的聚類方法在空間上有一定的混雜,雖然BayesSpace的一般聚類也有一些。但是BayesSpace還為我們準備了spatialEnhance()函數,可以增強主成分的分辨率,并將這些pc和預測的子點分辨率的聚類標簽添加到新的聚類單元中。正如上面我們對spatialCluster()的演示一樣,我們在這個示例中使用的迭代次數(nrep=1000)要少于我們在實踐中推薦的次數(nrep=100000或更大)。
sce.enhanced <- spatialEnhance(sce, q=10, platform="Visium", d=7,
model="t", gamma=2,
jitter_prior=0.3, jitter_scale=3.5,
nrep=1000, burn.in=100, # 為了向內存妥協
save.chain=T)
增強的singlecelexperimental包括原始sce中的父點索引(spot.idx)以及子點索引。它向原始spot坐標添加偏移量,并提供增強的集群標簽(spatial.cluster)。
DataFrame with 6 rows and 9 columns
spot.idx subspot.idx spot.row spot.col row col imagerow imagecol spatial.cluster
<numeric> <integer> <integer> <integer> <numeric> <numeric> <numeric> <numeric> <numeric>
subspot_1.1 1 1 1 49 1.333333 49.3333 4362.18 10258.5 4
subspot_2.1 2 1 0 50 0.333333 50.3333 4125.18 10395.5 6
subspot_3.1 3 1 1 51 1.333333 51.3333 4363.18 10531.5 4
subspot_4.1 4 1 0 52 0.333333 52.3333 4126.18 10668.5 6
subspot_5.1 5 1 1 53 1.333333 53.3333 4363.18 10804.5 4
subspot_6.1 6 1 0 54 0.333333 54.3333 4126.18 10941.5 4
我們也將兩者做一個比較:
clusterPlot(sce.enhanced,label = "spatial.cluster" )+ ggtitle("enhanced")+DarkTheme()
bayesspace可視化基因可以提高基因表達的分辨率。BayesSpace處理基因表達矩陣的主成分,spatialEnhance()函數計算增強分辨率的PC向量。增強的基因表達不是直接計算,而是使用回歸算法輸入,對于每個基因訓練一個使用每個位點的PC載體的模型來預測位點水平的基因表達,并使用擬合的模型從子位點PCs中預測子點表達。
基因表達增強是在enhanceFeatures()函數中實現的。BayesSpace默認情況下使用xgboost預測表達式,但是線性回歸和狄利克雷回歸也可以通過model參數使用。在使用xgboost時,我們建議通過將nrounds參數設置為0來自動調優它,盡管這是以增加運行時為代價的(實際中比預先指定的nrounds要慢約4倍)。
enhanceFeatures()可用于計算所有基因或感興趣基因子集的子點水平表達。在這里,我們將通過增強四種標記基因的表達來證明:PMEL(黑色素瘤),CD2 (t細胞),CD19 (b細胞)和COL1A1(成纖維細胞)。
markers <- c("PMEL", "CD2", "CD19", "COL1A1")
sce.enhanced <- enhanceFeatures(sce.enhanced, sce,
feature_names=markers,
nrounds=0)
enhanced.plots <- purrr::map(markers, function(x) featurePlot(sce.enhanced, x))
spot.plots <- purrr::map(markers, function(x) featurePlot(sce, x))
patchwork::wrap_plots(c(enhanced.plots, spot.plots), ncol=4)
雖然我們的marker只是根據推測來選的,很明顯可以看出,enhanced之后基因的表達模式更加凸顯,而未處理的基因表達規律不強。
BayesSpace enables the robust characterization of spatial gene expression architecture in tissue sections at increased resolution
https://research.fredhutch.org/gottardo/en/blog/bayesspace.html
https://www.biorxiv.org/content/10.1101/2020.09.04.283812v1