Seurat Weekly NO.4 || 高效數(shù)據(jù)管理

在這里,和國際同行一起學(xué)習(xí)單細(xì)胞數(shù)據(jù)分析。

單細(xì)胞轉(zhuǎn)錄組數(shù)據(jù)分析框架是成熟的,所謂降維聚類必知必會嘛。這一點(diǎn)也不影響數(shù)據(jù)分析過程的非線性過程,我們知道,在數(shù)據(jù)科學(xué)中降維聚類均屬于探索性數(shù)據(jù)分析手段。探索時貪婪,驗(yàn)證時謹(jǐn)慎。在處理單細(xì)胞轉(zhuǎn)錄組數(shù)據(jù)的時候,往往時螺旋式的,不時會有反復(fù)。這個過程就需要我們有數(shù)據(jù)管理的策略,好在Seurat的S4結(jié)構(gòu)為我們的數(shù)據(jù)管理做好了準(zhǔn)備。

  • 記錄分析過程

數(shù)據(jù)分析的時候,會需要看不同參數(shù)下的數(shù)據(jù)表現(xiàn),比如分群的resolution,差異分析的不同方法(或不同分組)。這時候我們?nèi)绻軌蛴涗浵聛砻看畏治龅拿?時間等,在復(fù)盤或重現(xiàn)分析的時候就方便很多。Seurat為我們提供了commands Slot。如我們可以這樣查看之前的分析命令:

library(Seurat)
library(SeuratData)
pbmc3k.final -> pbmc

pbmc@commands$RunUMAP.RNA.pca

Command: RunUMAP(pbmc3k.final, dims = 1:10)
Time: 2020-04-30 12:55:01
dims : 1 2 3 4 5 6 7 8 9 10 
reduction : pca 
assay : RNA 
umap.method : uwot 
n.neighbors : 30 
n.components : 2 
metric : cosine 
learning.rate : 1 
min.dist : 0.3 
spread : 1 
set.op.mix.ratio : 1 
local.connectivity : 1 
repulsion.strength : 1 
negative.sample.rate : 5 
uwot.sgd : FALSE 
seed.use : 42 
angular.rp.forest : FALSE 
verbose : TRUE 
reduction.name : umap 
reduction.key : UMAP_ 

Seurat的主要分析函數(shù)都內(nèi)置了LogSeuratCommand函數(shù),在完成計算之后,把計算參數(shù)記錄在pbmc@commands中。我們當(dāng)然也可以自己往這里面寫入提示自己的信息:

pbmc@commands$菜鳥團(tuán)數(shù)據(jù)分析 <- stringr::str_glue(paste0(Sys.time(),"\ninitiation: \n你的名字"))
pbmc@commands$菜鳥團(tuán)數(shù)據(jù)分析

2020-12-03 20:37:28
initiation: 
你的名字
  • 自己寫的函數(shù)

進(jìn)階階段肯定是在自己的單細(xì)胞轉(zhuǎn)錄分析函數(shù)中加入LogSeuratCommand了,這樣我們對數(shù)據(jù)做的每一次分析參數(shù)都會保留下來了。那么,問題來了,我們的函數(shù)可不可以寫在Seurat內(nèi)部呢?

顯然是可以的,Seurat為我們提供了toolsSlot。也就是不管我們引入的函數(shù)也好,自己寫的函數(shù)也好,均可與Seurat合為一體,當(dāng)然,函數(shù)名要注意一下,一如Tools函數(shù)的幫助文檔里備注的一樣:

For developers: set tool data using Tool<-. Tool<- will automatically set the name of the tool to the function that called Tool<-, so each function gets one entry in the tools list and cannot overwrite another function's entry. The automatic naming will also remove any method identifiers (eg. RunPCA.Seurat will become RunPCA); please plan accordingly.

  • 存儲數(shù)據(jù)

我們知道Seurat為單細(xì)胞轉(zhuǎn)錄組分析過程存下了counts/data/scale.data三張表達(dá)譜,還還有一系列的降維的坐標(biāo)等。如果我們有臨床信息還可以存在meta.data里,但是要是還有其他信息呢?比如差異基因列表。這時候,可以存在misc Slot里面,省的每次重新計算或者省去寫出讀入的操作。

Idents(pbmc) <- "seurat_clusters"
pbmc@misc$clustersmk <- FindAllMarkers(pbmc)

Idents(pbmc) <- "seurat_annotations"
pbmc@misc$celltypesmk <- FindAllMarkers(pbmc)

如有感興趣的基因集也可以存在其中,經(jīng)典的marker存在這里不是很方便嗎?

pbmc@misc$chemokines   <- grep("^CXC|CCL|CCR|CX3|XCL|XCR", rownames(pbmc),value = T)
  • 快速讀取

隨著單細(xì)胞的通量越來越大,我們的Seurat對象也越來越大(另一方面是Seurat存的數(shù)據(jù)越來越多)。每天來到辦公室第一件事就是讀入一個Seurat對象,如何才能快速讀取呢?介紹saveRDS的一個參數(shù)。

?saveRDS

compress
a logical specifying whether saving to a named file is to use "gzip" compression, or one of "gzip", "bzip2" or "xz" to indicate the type of compression to be used. Ignored if file is a conne

t1=proc.time()
saveRDS(pbmc,'pbmc1.rds',compress = F)
t2=proc.time()
t=t2-t1
print(paste0('執(zhí)行時間:',t[3][[1]],'秒'))
[1] "執(zhí)行時間:1.83000000000015秒"
t1=proc.time()
saveRDS(pbmc,'pbmc.rds')
t2=proc.time()
t=t2-t1
print(paste0('執(zhí)行時間:',t[3][[1]],'秒'))
[1] "執(zhí)行時間:27.6600000000001秒"

犧牲存儲換取時間,數(shù)十倍的差別,數(shù)據(jù)稍微大點(diǎn),這就夠喝杯咖啡的了。


參考:
https://github.com/satijalab/seurat/wiki
https://www.cnblogs.com/maoerbao/p/11694958.html

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容