單細(xì)胞學(xué)習(xí)教程-Python+R學(xué)前準(zhǔn)備

Scripts for "Current best-practices in single-cell RNA-seq: a tutorial"

該教程來(lái)自已發(fā)表文獻(xiàn):

M.D. Luecken, F.J. Theis, "Current best practices in single-cell RNA-seq analysis: a tutorial", Molecular Systems Biology 15(6) (2019): e8746

https://pubmed.ncbi.nlm.nih.gov/31217225/

這篇論文被推薦到F1000上,因?yàn)樗谠擃I(lǐng)域具有特殊的意義。發(fā)表1年引用量91,還是很驚人的。

image.png

其GitHub存儲(chǔ)庫(kù)包含以下內(nèi)容:

  • 生成論文中圖形的腳本
  • 補(bǔ)充論文手稿的案例研究
  • 補(bǔ)充材料中標(biāo)記基因檢測(cè)研究的代碼

該存儲(chǔ)庫(kù)的主要部分是案例研究,其中將手稿中建立的最佳實(shí)踐應(yīng)用于來(lái)自Haber et al., Nature 551 (2018) 等人的小鼠小腸上皮區(qū)數(shù)據(jù)集,可從GEO獲得GSE92332。此案例分析可以在latest_notebook/old_releases/目錄下找到不同的版本。

plotting_scripts/ folder中的腳本復(fù)制手稿和補(bǔ)充材料中顯示的數(shù)字。這些腳本包含解釋每個(gè)步驟的注釋。plotting_scripts/ folder中沒(méi)有相應(yīng)腳本的每個(gè)圖形都取自案例研究或標(biāo)記基因研究。

如果有疑問(wèn)或問(wèn)題,請(qǐng)通過(guò)在此存儲(chǔ)庫(kù)中發(fā)布問(wèn)題來(lái)聯(lián)系作者。

如果本教程中的材料對(duì)您有用,請(qǐng)考慮引用上述出版物。

環(huán)境設(shè)置

感謝 Leander Dony,可以在 here 獲取一個(gè)運(yùn)行這個(gè)sc-tutorial的 docker container 工作環(huán)境. 如果您想要通過(guò)conda或在docker container外手動(dòng)設(shè)置環(huán)境,請(qǐng)按照以下說(shuō)明操作。

要運(yùn)行教程案例研究,必須安裝幾個(gè)軟件包。因?yàn)橥瑫r(shí)需要Rpython包,所以我們更喜歡使用conda環(huán)境。為了方便設(shè)置conda環(huán)境,我們提供了sc_tutorial_environment.yml文件,該文件包含所有conda和pip可安裝的依賴項(xiàng)。R依賴項(xiàng)(尚未作為conda包提供)必須安裝到環(huán)境中。

要設(shè)置conda小環(huán)境,必須遵循以下說(shuō)明。

  1. 使用 sc_tutorial_environment.yml 設(shè)置小環(huán)境.

    conda env create -f sc_tutorial_environment.yml
    
  2. 確保環(huán)境可以從R找到gsl庫(kù)。這可以通過(guò)設(shè)置CFLAGSLDFLAGS環(huán)境變量來(lái)完成(請(qǐng)參見(jiàn)https://bit.ly/2CjJsgn)。在這里,我們對(duì)它們進(jìn)行設(shè)置,以便每次激活環(huán)境時(shí)都能正確設(shè)置它們。

    cd YOUR_CONDA_ENV_DIRECTORY
    mkdir -p ./etc/conda/activate.d
    mkdir -p ./etc/conda/deactivate.d
    touch ./etc/conda/activate.d/env_vars.sh
    touch ./etc/conda/deactivate.d/env_vars.sh
    

    其中YOUR_CONDA_ENV_DIRECTORY可以通過(guò)運(yùn)行conda info--envs,使用您的CONDA環(huán)境名對(duì)應(yīng)的目錄(默認(rèn)為sc-tutorail)找到。

    WHILE NOT IN THE ENVIRONMENT(!!!!) 打開(kāi)./etc/conda/activate.d/env_vars.sh下的env_vars.sh文件,輸入如下內(nèi)容:

    #!/bin/sh
    
    CFLAGS_OLD=$CFLAGS
    export CFLAGS_OLD
    export CFLAGS="`gsl-config --cflags` ${CFLAGS_OLD}"
     
    LDFLAGS_OLD=$LDFLAGS
    export LDFLAGS_OLD
    export LDFLAGS="`gsl-config --libs` ${LDFLAGS_OLD}"
    

    然后修改 ./etc/conda/deactivate.d/env_vars.sh 文件:

    #!/bin/sh
     
    CFLAGS=$CFLAGS_OLD
    export CFLAGS
    unset CFLAGS_OLD
     
    LDFLAGS=$LDFLAGS_OLD
    export LDFLAGS
    unset LDFLAGS_OLD
    

    再次注意,這些文件應(yīng)該在不在環(huán)境中時(shí)寫(xiě)入。否則,您可能會(huì)覆蓋base環(huán)境中的CFLAGS和LDFLAGS環(huán)境變量!

  3. 如果您在sc_tutorial_environment.yml文件中更改了環(huán)境名稱,請(qǐng)通過(guò)conda activate sc-tutorialconda activate ENV_NAME進(jìn)入環(huán)境。

  4. 打開(kāi)R并通過(guò)以下命令安裝依賴R包:

    install.packages(c('devtools', 'gam', 'RColorBrewer', 'BiocManager'))
    update.packages(ask=F)#這一指令會(huì)更新所有的R包,耗時(shí)較長(zhǎng)慎重使用
    BiocManager::install(c("scran","MAST","monocle","ComplexHeatmap","slingshot","clusterExperiment"))
    

這些步驟應(yīng)該設(shè)置一個(gè)環(huán)境,以便在Linux系統(tǒng)上使用教程工作流程執(zhí)行單細(xì)胞分析。請(qǐng)注意,我們?cè)贛ac OS上遇到了Conda環(huán)境的問(wèn)題。當(dāng)使用Mac OS時(shí),我們建議不帶conda安裝軟件包,使用單獨(dú)安裝的pythonR版本?;蛘?,您也可以嘗試使用基本conda環(huán)境并安裝所有軟件包,如conda_env_instructions_for_mac.txt文件中所述。在基礎(chǔ)環(huán)境中,R應(yīng)該可以找到相關(guān)的gsl庫(kù),所以應(yīng)該不需要設(shè)置LDFLAGSCFLAGS。

還要注意的是,conda和pip并不總是和睦相處。Conda開(kāi)發(fā)人員建議首先安裝所有conda包,然后在conda包不可用的地方安裝pip包。因此,在環(huán)境中安裝更多的conda包可能會(huì)導(dǎo)致問(wèn)題。因此,請(qǐng)啟動(dòng)一個(gè)新環(huán)境,并首先重新安裝所有conda包。

如果您更喜歡手動(dòng)設(shè)置環(huán)境,本文檔末尾提供了所有軟件包要求的列表。

下載數(shù)據(jù)

如上所述,案例研究的數(shù)據(jù)來(lái)自GSE92332。要運(yùn)行所示的案例研究,您必須下載此數(shù)據(jù)并將其放入正確的文件夾中。解壓數(shù)據(jù)需要targunzip,這兩個(gè)命令應(yīng)該在大多數(shù)系統(tǒng)上都已可用。如果您要克隆GitHub存儲(chǔ)庫(kù)并將案例研究腳本放在latest_notebook/文件夾中,則可以從存儲(chǔ)案例研究ipynb文件的位置通過(guò)以下命令完成此操作:

cd ../  #To get to the main github repo folder
mkdir -p data/Haber-et-al_mouse-intestinal-epithelium/
cd data/Haber-et-al_mouse-intestinal-epithelium/
wget ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE92nnn/GSE92332/suppl/GSE92332_RAW.tar
mkdir GSE92332_RAW
tar -C GSE92332_RAW -xvf GSE92332_RAW.tar
gunzip GSE92332_RAW/*_Regional_*

我們?cè)趎otebook末尾簡(jiǎn)要比較結(jié)果的帶注釋的數(shù)據(jù)集可以從相同的GEO訪問(wèn)ID(GSE92332)獲得??梢允褂靡韵旅瞰@?。?/p>

cd data/Haber-et-al_mouse-intestinal-epithelium/
wget ftp://ftp.ncbi.nlm.nih.gov/geo/series/GSE92nnn/GSE92332/suppl/GSE92332_Regional_UMIcounts.txt.gz
gunzip GSE92332_Regional_UMIcounts.txt.gz

Case study notes

我們已經(jīng)注意到,可視化、降維和聚類(因此也包括所有下游結(jié)果)等結(jié)果在不同的系統(tǒng)上可能會(huì)給出略有不同的結(jié)果。這與后端使用的數(shù)字庫(kù)有關(guān)。因此,我們不能保證筆記本的重新運(yùn)行將生成完全相同的clusters結(jié)果。

雖然所有的結(jié)果在質(zhì)量上都是相似的,但是在不同的系統(tǒng)之間,特別是對(duì)于干細(xì)胞、TA細(xì)胞和腸系祖細(xì)胞,將細(xì)胞分配到簇中的情況可能會(huì)有所不同。為了顯示預(yù)期的多樣性,我們將縮小的案例研究筆記本上傳到alternative_clustering_results/文件夾。

請(qǐng)注意,使用參數(shù)svd_solver='arpack'運(yùn)行sc.pp.pca()會(huì)大大降低系統(tǒng)之間的可變性,但是輸出并不完全相同。

為其他數(shù)據(jù)集調(diào)整pipeline:

pipeline被設(shè)計(jì)成可以很容易地適應(yīng)新的數(shù)據(jù)集。但是,當(dāng)前工作流程的一般適用性有幾個(gè)限制。在為您自己的數(shù)據(jù)集調(diào)整pipeline時(shí),請(qǐng)考慮以下事項(xiàng):

1.rpy2不支持稀疏數(shù)據(jù)格式(Sparse data),因此不支持任何集成的R命令。可以使用以下代碼將數(shù)據(jù)集轉(zhuǎn)換為密集格式:adata.X = adata.X.toarray()。

2.案例研究假設(shè)輸入數(shù)據(jù)為UMIS單細(xì)胞protocol獲取的計(jì)數(shù)數(shù)據(jù)。如果輸入數(shù)據(jù)是全長(zhǎng)讀取數(shù)據(jù),則可以考慮用包括基因長(zhǎng)度歸一化(例如,TPM)的另一種方法來(lái)替換歸一化方法。

手動(dòng)安裝軟件包要求

運(yùn)行案例研究notebook的第一個(gè)版本需要以下軟件包。有關(guān)更多版本,請(qǐng)參閱latest_notebook/old_releases/文件夾中的README.md。

General:

  • Jupyter notebook
  • IRKernel
  • rpy2
  • R >= 3.4.3
  • Python >= 3.5

Python:

  • scanpy
  • numpy
  • scipy
  • pandas
  • seaborn
  • louvain>=0.6
  • python-igraph
  • gprofiler-official (from Case study notebook 1906 version)
  • python-gprofiler from Valentine Svensson's github (vals/python-gprofiler)
    • only needed for notebooks before version 1906
  • ComBat python implementation from Maren Buettner's github (mbuttner/maren_codes/combat.py)
    • only needed for scanpy versions before 1.3.8 which don't include sc.pp.combat()

R:

  • scater
  • scran
  • MAST
  • gam
  • slingshot (change DESCRIPTION file for R version 3.4.3)
  • monocle 2
  • limma
  • ComplexHeatmap
  • RColorBrewer
  • clusterExperiment
  • ggplot2
  • IRkernel

手動(dòng)安裝中可能的錯(cuò)誤來(lái)源:

For R 3.4.3:

When using Slingshot in R 3.4.3, you must pull a local copy of slingshot via the github repository and change the DESCRIPTION file to say R>=3.4.3 instead of R>=3.5.0.

For R >= 3.5 and bioconductor >= 3.7:

The clusterExperiment version that comes for bioconductor 3.7 has slightly changed naming convention. clusterExperiment() is now called ClusterExperiment(). The latest version of the notebook includes this change, but when using the original notebook, please note that this may throw an error.

For rpy2 < 3.0.0:

Pandas 0.24.0 is not compatible with rpy2 < 3.0.0. When using old versions of rpy2, please downgrade pandas to 0.23.X. Please also note that Pandas 0.24.0 requires anndata version 0.6.18 and scanpy version > 1.37.0.

For enrichment analysis with g:profiler:

Ensure that the correct g:profiler package is used for the notebook. Notebooks until 1904 use python-gprofiler from valentine svensson's github, and Notebooks from 1906 use the gprofiler-official package from the g:profiler team.

If not R packages can be found:

Ensure that IRkernel has linked the correct version of R with your jupyter notebook. Check instructions at https://github.com/IRkernel/IRkernel.

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容