pySCENIC單細胞轉(zhuǎn)錄因子分析更新:數(shù)據(jù)庫、軟件更新

****pySCENIC全部往期精彩系列
1、PySCENIC(一):python版單細胞轉(zhuǎn)錄組轉(zhuǎn)錄因子分析
2、PySCENIC(二):pyscenic單細胞轉(zhuǎn)錄組轉(zhuǎn)錄因子分析
3、PySCENIC(三):pyscenic單細胞轉(zhuǎn)錄因子分析可視化
4、PySCENIC(四):pyscenic結(jié)果之差異轉(zhuǎn)錄因子分析及其他可視化首先說一句,我們之前也發(fā)過R語言版本的SCENIC,但是后來我們感覺容易出錯,而且費時,所以就沒有再探究過。可是總是有小伙伴喜歡跑R,然后說這里錯了,那里找不見,其實我們的帖子寫于2022年,但是數(shù)據(jù)庫已經(jīng)更新了,去官網(wǎng)下載新的數(shù)據(jù)庫,不能無腦跑代碼?;氐絧ySCENIC,之前我們寫過整個系列4篇帖子,分析可視化都是很完善了??墒墙谂艿臅r候發(fā)現(xiàn)在第一步有點問題,要么跑不動,要么出錯,懷疑是軟件和數(shù)據(jù)庫沒有更新的緣故,故而更新一下測試。這個帖子主要有兩部分內(nèi)容。

Section1

首先準備單細胞數(shù)據(jù),我們準備了27001個基因6000個細胞的數(shù)據(jù):提取表達數(shù)據(jù),這些操作和之前的一樣,沒有區(qū)別。

#====================================================================================
#                               1、R中提取seurat單細胞counts矩陣
#====================================================================================

setwd("D:/KS項目/公眾號文章/pySCENIC更新")
library(Seurat)
dim(uterus)
# [1] 27001 27914
table(uterus$orig.ident)
# AEH   EEC    HC 
# 9525 12033  6356
#對于每個樣本抽取2000個細胞進行分析,這里只是演示,太多細胞沒有意義,也是為了降低文件大小
Idents(uterus) <- 'orig.ident'
sce_test <- subset(x = uterus, downsample = 2000)
table(sce_test$orig.ident)
# AEH  EEC   HC 
# 2000 2000 2000 
table(sce_test$celltype)
# Ciliated epithelial cells           Endothelial cells                 Lymphocytes 
# 427                         631                        2844 
# Macrophages         Smooth muscle cells         Stromal fibroblasts 
# 110                         474                         593 
# Unciliated epithelial cells 
# 921 

dim(sce_test)#我們用這6000個細胞進行演示
# [1] 27001  6000


#提取表達矩陣,用于后續(xù)分析
Idents(sce_test) <- 'celltype'
write.csv(t(as.matrix(sce_test@assays$RNA@counts)),file = "sce_exp.csv")
saveRDS(sce_test, file = 'sce_test.rds')

我們這次干脆一不做二不休,將之前的pyscenic的環(huán)境刪除干凈,重新建立環(huán)境,重新下載最新版軟件pyscenic0.12.1好了。準備的數(shù)據(jù)集也用最新的。數(shù)據(jù)庫網(wǎng)址:https://resources.aertslab.org/cistarget/databases/,需要什么自己下載選擇即可。


#刪除之前的環(huán)境,重新建立環(huán)境并下載軟件
conda info --envs
conda env remove -n pyscenic
#創(chuàng)建環(huán)境
conda create -y -n pyscenic python=3.7
conda activate pyscenic
pip install pyscenic -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
pip install scanpy -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com


#需要的數(shù)據(jù)庫下載
#1、Databases ranking the whole genome  :https://resources.aertslab.org/cistarget/databases/
#我這里是人的:#需要下載什么。自己實際選擇
wget https://resources.aertslab.org/cistarget/databases/homo_sapiens/hg38/refseq_r80/mc_v10_clust/gene_based/hg38_10kbp_up_10kbp_down_full_tx_v10_clust.genes_vs_motifs.rankings.feather

#2、Motif to TF annotations database 
wget https://resources.aertslab.org/cistarget/motif2tf/motifs-v10nr_clust-nr.hgnc-m0.001-o0.0.tbl

#3、A list of transcription factors 
wget https://resources.aertslab.org/cistarget/tf_lists/allTFs_hg38.txt

這是所有軟件版本

image.png

分析的話很好辦,還是和之前一樣,標準的3步。第一步我們花了大概12多小時。后面的步驟就比較快了。運行是沒有任何問題。甚至最后的結(jié)果loom文件我們用之前的R可視化代碼直接“閉眼”運行,沒有任何問題,所以在這里出問題的小伙伴,考慮下自己數(shù)據(jù)的問題,軟件的問題。


pyscenic grn --num_workers 10 \
--sparse \
--method grnboost2 \
--output grn.csv \
sce.loom \
allTFs_hg38.txt

pyscenic ctx --num_workers 10 \
--output regulons.csv \
--expression_mtx_fname sce.loom \
--mode "custom_multiprocessing" \
--motifs-v10nr_clust-nr.hgnc-m0.001-o0.0.tbl\
grn.csv \
hg38_10kbp_up_10kbp_down_full_tx_v10_clust.genes_vs_motifs.rankings.feather


pyscenic aucell --num_workers 6 \
--output sample_SCENIC.loom \
sce.loom \
regulons.csv
image.png

到這里我們還想探討一個問題,那就是第一步為什么那么慢,如果仔細了解過的話都知道,第一步的目的是推斷轉(zhuǎn)錄因子與提供的表達矩陣基因的共表達模塊,所以慢就是因為基因多,所以前面我們第一步就是因為運行了所有的基因。這里我們測試了兩個數(shù)據(jù),一個是1000個基因1500個細胞,一個是1000個6000個細胞,發(fā)現(xiàn)運行時間是一樣的。

#一個比對
#1000個基因1500個細胞的運行時間
2023-05-30 09:06:44,608 - pyscenic.cli.pyscenic - INFO - Loading expression matrix.
2023-05-30 09:06:44,765 - pyscenic.cli.pyscenic - INFO - Inferring regulatory networks.
2023-05-30 09:09:02,645 - pyscenic.cli.pyscenic - INFO - Writing results to file.

#1000個基因6000個細胞的運行時間
2023-05-30 09:32:42,268 - pyscenic.cli.pyscenic - INFO - Loading expression matrix.
2023-05-30 09:32:42,531 - pyscenic.cli.pyscenic - INFO - Inferring regulatory networks.
2023-05-30 09:35:03,436 - pyscenic.cli.pyscenic - INFO - Writing results to file.

所以我們建議在運行之前,可以對基因進行過濾,例如只有幾個細胞表達的基因,或者大多數(shù)細胞表達為0的基因可以過濾后在進行分析,因為這些基因沒有實質(zhì)的意義和貢獻,對于數(shù)據(jù)的分析結(jié)果也沒有影響,還能提高效率。這個思路我認為是沒有什么問題的。

Section2

Section1的方式我們之前的帖子說過,相信很多小伙伴已經(jīng)了解掌握了,只需要更新數(shù)據(jù)庫和軟件即可。那么這一部分我們增加的是利用docker鏡像進行pyscenic分析。關(guān)于docker這里不展開說,可以自行百度。其實愛學習的小伙伴在pyscenic官網(wǎng)的步驟中已經(jīng)看到了作者講的,docker鏡像分析的步驟。docker的一個優(yōu)勢是速快稍微快一點,不容易出錯,我們也測試了,好像是快那么一點。docker的安裝需要root權(quán)限,所以不懂linux的小伙伴最好不要動,因為sudo很容易搞壞電腦。如果是服務(wù)器,一般共享的也沒root權(quán)限。docker的安裝可聯(lián)系管理員。本地的linux子系統(tǒng)當然是可以安裝的。


#安裝docker,需要root權(quán)限
# 參考:
# 知乎:https://zhuanlan.zhihu.com/p/433898505
# docker官網(wǎng):https://docs.docker.com/engine/install/ubuntu/
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

docker --help

# Usage:  docker [OPTIONS] COMMAND
# 
# A self-sufficient runtime for containers
# 
# Common Commands:
#   run         Create and run a new container from an image
# exec        Execute a command in a running container
# ps          List containers
# build       Build an image from a Dockerfile
# pull        Download an image from a registry
# push        Upload an image to a registry
# images      List images
# login       Log in to a registry

sudo service docker start
service docker status

安裝好docker后,我們就可以下載pyscenic了。

#docker安裝最新版pyscenic
sudo docker pull aertslab/pyscenic:0.12.1
# sudo: /etc/sudoers.d is owned by uid 1000000, should be 0
# [sudo] password for tq_ziv: 
#   0.12.1: Pulling from aertslab/pyscenic
# 1efc276f4ff9: Pull complete 
# 126aaa6587b8: Pull complete 
# 0dd06b55ca68: Pull complete 
# 3950cece0b72: Pull complete 
# a4cc5c9d5acb: Pull complete 
# bdf10448670a: Pull complete 
# 6c5350e3d2c5: Pull complete 
# Digest: sha256:0c06b8b0a00117e1a4b61303e9ad775bf53c9e410d4c344151c15bf0d143a288
# Status: Downloaded newer image for aertslab/pyscenic:0.12.1
# docker.io/aertslab/pyscenic:0.12.1

# pySCENIC CLI version + ipython kernel + scanpy.
docker pull aertslab/pyscenic_scanpy:0.12.1_1.9.1

分析也是基本的三部:


#run pyscenic
#step1
sudo docker run -it --rm \
     -v /home/tq_ziv/pyscenic:/pyscenic aertslab/pyscenic:0.12.1 \
     pyscenic grn \
     --num_workers 10 \
     --method grnboost2 \
     --output /pyscenic/grn.csv \
     --sparse \
     /pyscenic/sce.loom \
     /pyscenic/allTFs_hg38.txt

#step2
sudo docker run -it --rm \
     -v /home/tq_ziv/pyscenic:/pyscenic aertslab/pyscenic:0.12.1 \
     pyscenic ctx \
     /pyscenic/grn.csv \
     /pyscenic/hg38_10kbp_up_10kbp_down_full_tx_v10_clust.genes_vs_motifs.rankings.feather \
     --annotations_fname /pyscenic/motifs-v10nr_clust-nr.hgnc-m0.001-o0.0.tbl \
     --expression_mtx_fname /pyscenic/sce.loom \
     --mode "custom_multiprocessing" \
     --output /pyscenic/regulons.csv \
     --num_workers 10

#step3
sudo docker run -it --rm \
     -v /home/tq_ziv/pyscenic:/pyscenic aertslab/pyscenic:0.12.1 \
     pyscenic aucell \
     /pyscenic/sce.loom \
     /pyscenic/regulons.csv \
     -o /pyscenic/sample_SCENIC.loom \
     --num_workers 6

這樣就完成了,分析結(jié)束后按照之前的帖子進行下游的分析和可視化即可。這就是pyscenic的全部內(nèi)容了。時不時更新下數(shù)據(jù)庫,更新下軟件,切記不可拿到別人的代碼不思考便運行,不可能順利拿到結(jié)果。覺得分享有用的點個贊、分享一下再走唄!當然了一般的共享服務(wù)器是沒有root權(quán)限的,也不可能用sudo命令進行操作??梢詤⒖嘉覀儗俚姆?wù)器:專屬注冊鏈接:https://www.xiyoucloud.net/aff/OXAAYEPJ

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

相關(guān)閱讀更多精彩內(nèi)容

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