跑錨點整合的時候遇到報錯
scRNA.anchors <- FindIntegrationAnchors(object.list = scRNAlist,
normalization.method = "SCT",
anchor.features = scRNA.features)
提示future.globals.maxSize
不足
解決辦法參考:stackoverflow
library(future)
# 3250*1024^2 = 3407872000
options(future.globals.maxSize= 4000000000) #大于3407872000即可
scRNA.anchors <- FindIntegrationAnchors(object.list = scRNAlist,
normalization.method = "SCT",
anchor.features = scRNA.features)
基于future的Seurat多線程并行策略
如何在Seurat中使用并行策略
在Seurat的 pipeline中符匾,我們是可以使用future框架進行并行運算的啊胶。更多說明可以參考future。要訪問 Seurat 中的并行函數(shù)版本趣倾,需要加載future
包并設置plan
某饰。plan將指定如何運行該函數(shù)善绎。默認行為是以非并行方式(按順序)進行诫尽。為了實現(xiàn)并行,我們通常建議"多線程"策略剂跟。默認情況下驹止,這將調用所有可用的核观蜗,但可以設置workers參數(shù)以限制同時活動future的數(shù)量。
library(future)
# check the current active plan
plan()
## sequential:
## - args: function (..., envir = parent.frame())
## - tweaked: FALSE
## - call: NULL
# change the current plan to access parallelization
plan("multiprocess", workers = 4)
plan()
## multiprocess:
## - args: function (..., envir = parent.frame(), workers = 4)
## - tweaked: TRUE
## - call: plan("multiprocess", workers = 4)
seurat的"futurized"功能
以下函數(shù)已被編寫可以利用future 框架抖仅,如果設置適當?shù)?code>plan撤卢,將進行并行梧兼。
- NormalizeData()
- ScaleData()
- JackStraw()
- FindMarkers()
- FindIntegrationAnchors()
- FindClusters() - if clustering over multiple resolutions
例如,要運行并行版本渡紫,只需要設置future 并照常調用FindMarkers()功能考赛。
例如在跑FindMarkers的時候
library(Seurat)
pbmc <- readRDS("../data/pbmc3k_final.rds")
# Enable parallelization
plan("multiprocess", workers = 4)
markers <- FindMarkers(pbmc, ident.1 = "NK", verbose = FALSE)
sequential vs. parallel
這里,我們將執(zhí)行一個簡單的比較唧喉,比較有和沒有并行運行的時間差異忍抽。注意,雖然我們預計使用并行策略將減少上述函數(shù)的運行時間干跛,但減少的幅度將取決于許多因素(例如數(shù)據(jù)集的大小锈锤、線程數(shù)闲询、系統(tǒng)的規(guī)格浅辙、future框架等)记舆。以下基準是在運行 Ubuntu 16.04.5 LTS 的計算機上執(zhí)行的,配置是 Intel(R) Core(TM) i7-6800K CPU @ 3.40GHz and 96 GB of RAM
library(ggplot2)
library(cowplot)
ggplot(timing.comparisons, aes(fxn, time)) + geom_bar(aes(fill = strategy), stat = "identity", position = "dodge") +
ylab("Time(s)") + xlab("Function") + theme_cowplot()
常見問題
我的進度欄去哪里了御蒲?
遺憾的是诊赊,在任何平行模式下運行這些函數(shù)時,您將失去進度欄碘箍。這是由于future
框架和 R 中的一些技術限制造成的鲸郊。如果要監(jiān)控函數(shù)進度,則需要放棄并行化四濒,選擇使用plan("sequential")职辨。如果我不斷看到以下錯誤,該怎么辦姆涩?
Error in getGlobalsAndPackages(expr, envir = envir, globals = TRUE) :
The total size of the X globals that need to be exported for the future expression ('FUN()') is X GiB.
This exceeds the maximum allowed size of 500.00 MiB (option 'future.globals.maxSize'). The X largest globals are ...
對于某些函數(shù)惭每,每個線程需要訪問某些全局變量。如果這些大于默認限制宏赘,將看到此錯誤黎侈。要繞過這一點,可以設置 options(future.globals.maxSize = X)贴汪,X 是字節(jié)中允許的最大值。因此业簿,要將其設置為1GB阳懂,可運行options(future.globals.maxSize = 1000 * 1024^2)。注意巷燥,這將增加RAM使用量号枕,因此請注意設置合適的數(shù)字。
參考:https://satijalab.org/seurat/articles/future_vignette.html