系列回顧:
ArchR官網(wǎng)教程學(xué)習(xí)筆記1:Getting Started with ArchR
ArchR官網(wǎng)教程學(xué)習(xí)筆記2:基于ArchR推測(cè)Doublet
ArchR官網(wǎng)教程學(xué)習(xí)筆記3:創(chuàng)建ArchRProject
ArchR官網(wǎng)教程學(xué)習(xí)筆記4:ArchR的降維
ArchR官網(wǎng)教程學(xué)習(xí)筆記5:ArchR的聚類
在ArchR中溃睹,使用UMAP或t-SNE等嵌入方法在降維空間中可實(shí)現(xiàn)單細(xì)胞的可視化欠窒。這些嵌入方法各有其獨(dú)特的優(yōu)點(diǎn)和缺點(diǎn)。我們稱這些為“嵌入”,是因?yàn)樗鼈儑?yán)格用于可視化clusters,而不是用于識(shí)別clusters(LSI子空間中完成)。UMAP和t-SNE的主要區(qū)別在于對(duì)細(xì)胞或clusters間距離的解釋。t-SNE被設(shè)計(jì)用來(lái)保存數(shù)據(jù)中的局部結(jié)構(gòu),而UMAP被設(shè)計(jì)用來(lái)保存數(shù)據(jù)中的局部結(jié)構(gòu)和大部分全局結(jié)構(gòu)肌幽。理論上,這意味著兩個(gè)clusters之間的距離在t-SNE中不具有信息性抓半,而在UMAP中具有信息性喂急。例如,在t-SNE上笛求,如果觀察到cluster A比cluster C更靠近c(diǎn)luster B廊移,那么t-SNE就不允許你下結(jié)論說(shuō)A比C更接近B。相反探入,UMAP的設(shè)計(jì)是為了允許這種類型的比較狡孔,但值得注意的是,UMAP是一種新的方法蜂嗽,很多研究者仍然使用t-SNE苗膝。
需要注意的是,t-SNE和UMAP都不是自然確定的(相同的輸入總是給出完全相同的輸出)植旧。然而辱揭,與UMAP相比,t-SNE在多次相同輸入的結(jié)果中顯示出了更多的隨機(jī)性病附。此外问窃,當(dāng)使用相同的隨機(jī)種子(seed
)時(shí),uwot
包中實(shí)現(xiàn)的UMAP是確定性的胖喳。使用UMAP還是t-SNE的選擇是有細(xì)微差別的,但在我們的經(jīng)驗(yàn)中贮竟,UMAP非常適合多種數(shù)據(jù)集丽焊,這是我們對(duì)scATAC-seq數(shù)據(jù)的標(biāo)準(zhǔn)選擇较剃。UMAP的運(yùn)行速度也比t-SNE快。最重要的是技健,使用UMAP写穴,你可以創(chuàng)建一個(gè)嵌入并將新樣本投射到嵌入中,而使用t-SNE是不可能的雌贱,因?yàn)閠-SNE中數(shù)據(jù)的擬合和預(yù)測(cè)是同時(shí)發(fā)生的啊送。
無(wú)論選擇哪種方法,輸入?yún)?shù)都可能對(duì)結(jié)果的嵌入產(chǎn)生巨大影響欣孤。因此馋没,理解各種輸入?yún)?shù)并調(diào)整它們以最佳地滿足數(shù)據(jù)的需要是很重要的。ArchR實(shí)現(xiàn)了一組默認(rèn)的輸入?yún)?shù)降传,這些參數(shù)適用于大多數(shù)數(shù)據(jù)集篷朵,但實(shí)際上并沒(méi)有一組參數(shù)能夠?yàn)榧?xì)胞數(shù)、復(fù)雜性和質(zhì)量差異很大的數(shù)據(jù)集生成理想的結(jié)果婆排。
(一)UMAP
在ArchR里運(yùn)行UMAP声旺,使用addUMAP()
:
> projHeme2 <- addUMAP(
ArchRProj = projHeme2,
reducedDims = "IterativeLSI",
name = "UMAP",
nNeighbors = 30,
minDist = 0.5,
metric = "cosine"
)
你還可以查看你現(xiàn)在的這個(gè)ArchRProject里有哪些嵌入:
> projHeme2@embeddings
List of length 1
names(1): UMAP
要繪制UMAP結(jié)果,我們使用plotEmbedding()
函數(shù)段只,并傳遞我們剛剛生成的UMAP嵌入的名稱(“UMAP”)腮猖。我們可以通過(guò)使用顏色組合colorBy
告訴ArchR如何為細(xì)胞上色,它會(huì)告訴ArchR使用哪個(gè)矩陣來(lái)查找指定的metadata列來(lái)命名:
> p1 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Sample", embedding = "UMAP")
> p1
上面是使用的“樣品”來(lái)給細(xì)胞上色赞枕,我們也可以使用clusters來(lái)給細(xì)胞上色:
> p2 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Clusters", embedding = "UMAP")
> p2
我們還可以把兩張圖并排同時(shí)顯示澈缺,參數(shù)type = "h"表示水平放置:
> ggAlignPlots(p1, p2, type = "h")
保存圖片:
> plotPDF(p1,p2, name = "Plot-UMAP-Sample-Clusters.pdf", ArchRProj = projHeme2, addDOC = FALSE, width = 5, height = 5)
上一章我們還用了scran方法進(jìn)行了聚類,現(xiàn)在也可以使用plotEmbedding()對(duì)其進(jìn)行可視化:
> p1 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Sample", embedding = "UMAP")
> p1
> p2 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "ScranClusters", embedding = "UMAP")
> p2
> ggAlignPlots(p1, p2, type = "h") #并排展示圖片
> plotPDF(p1,p2, name = "Plot-UMAP-Sample-ScranClusters.pdf", ArchRProj = projHeme2, addDOC = FALSE, width = 5, height = 5)
(二)t-SNE
我們使用addTSNE()
函數(shù)在ArchR里運(yùn)行t-SNE:
> projHeme2 <- addTSNE(
ArchRProj = projHeme2,
reducedDims = "IterativeLSI",
name = "TSNE",
perplexity = 30
)
> projHeme2@embeddings
List of length 2
names(2): UMAP TSNE
t-SNE的可視化:
> p1 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Sample", embedding = "TSNE")
> p1
> p2 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Clusters", embedding = "TSNE")
> p2
> ggAlignPlots(p1, p2, type = "h")
> plotPDF(p1,p2, name = "Plot-TSNE-Sample-Clusters.pdf", ArchRProj = projHeme2, addDOC = FALSE, width = 5, height = 5)
同樣的鹦赎,我們也可以使用t-SNE來(lái)可視化scran聚類結(jié)果:
> p1 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Sample", embedding = "TSNE")
> p1
> p2 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "ScranClusters", embedding = "TSNE")
> p2
> ggAlignPlots(p1, p2, type = "h")
> plotPDF(p1,p2, name = "Plot-tSNE-Sample-ScranClusters.pdf", ArchRProj = projHeme2, addDOC = FALSE, width = 5, height = 5)
(三)在Harmony之后降維
在前一章中谍椅,我們通過(guò)addHarmony()
函數(shù)使用Harmony
執(zhí)行批次效應(yīng)修正,創(chuàng)建了一個(gè)名為“Harmony”的reducedDims
對(duì)象古话。我們可以通過(guò)使用UMAP或t-SNE可視化嵌入來(lái)評(píng)估Harmony的效果雏吭。
用相同的參數(shù)重復(fù)UMAP嵌入,只不過(guò)是用“Harmony” reducedDims 對(duì)象(前面我們用的對(duì)象都是迭代LSI對(duì)象):
> projHeme2 <- addUMAP(
ArchRProj = projHeme2,
reducedDims = "Harmony",
name = "UMAPHarmony",
nNeighbors = 30,
minDist = 0.5,
metric = "cosine"
)
> projHeme2@embeddings
List of length 3
names(3): UMAP TSNE UMAPHarmony
可視化:
> p3 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Sample", embedding = "UMAPHarmony")
> p3
> p4 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Clusters", embedding = "UMAPHarmony")
> p4
> ggAlignPlots(p3, p4, type = "h")
> plotPDF(p1,p2,p3,p4, name = "Plot-UMAP2Harmony-Sample-Clusters.pdf", ArchRProj = projHeme2, addDOC = FALSE, width = 5, height = 5)
用t-SNE對(duì)Harmony對(duì)象進(jìn)行分析:
> projHeme2 <- addTSNE(
ArchRProj = projHeme2,
reducedDims = "Harmony",
name = "TSNEHarmony",
perplexity = 30
)
> projHeme2@embeddings
List of length 4
names(4): UMAP TSNE UMAPHarmony TSNEHarmony
可視化:
> p3 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Sample", embedding = "TSNEHarmony")
> p3
> p4 <- plotEmbedding(ArchRProj = projHeme2, colorBy = "cellColData", name = "Clusters", embedding = "TSNEHarmony")
> p4
> ggAlignPlots(p3, p4, type = "h")
> plotPDF(p1,p2,p3,p4, name = "Plot-TSNE2Harmony-Sample-Clusters.pdf", ArchRProj = projHeme2, addDOC = FALSE, width = 5, height = 5)