****pySCENIC全部往期精彩系列:
1骗爆、PySCENIC(一):python版單細(xì)胞轉(zhuǎn)錄組轉(zhuǎn)錄因子分析
2碉哑、PySCENIC(二):pyscenic單細(xì)胞轉(zhuǎn)錄組轉(zhuǎn)錄因子分析
3食拜、PySCENIC(三):pyscenic單細(xì)胞轉(zhuǎn)錄因子分析可視化
4鸵熟、PySCENIC(四):pyscenic結(jié)果之差異轉(zhuǎn)錄因子分析及其他可視化首先說(shuō)一句,我們之前也發(fā)過(guò)R語(yǔ)言版本的SCENIC负甸,但是后來(lái)我們感覺(jué)容易出錯(cuò)流强,而且費(fèi)時(shí),所以就沒(méi)有再探究過(guò)呻待〈蛟拢可是總是有小伙伴喜歡跑R,然后說(shuō)這里錯(cuò)了蚕捉,那里找不見(jiàn)奏篙,其實(shí)我們的帖子寫(xiě)于2022年,但是數(shù)據(jù)庫(kù)已經(jīng)更新了,去官網(wǎng)下載新的數(shù)據(jù)庫(kù)秘通,不能無(wú)腦跑代碼为严』砘ぃ回到pySCENIC,之前我們寫(xiě)過(guò)整個(gè)系列4篇帖子般哼,分析可視化都是很完善了瓦宜』屑可是近期跑的時(shí)候發(fā)現(xiàn)在第一步有點(diǎn)問(wèn)題蔑祟,要么跑不動(dòng)告材,要么出錯(cuò)枷踏,懷疑是軟件和數(shù)據(jù)庫(kù)沒(méi)有更新的緣故凿可,故而更新一下測(cè)試稿静。這個(gè)帖子主要有兩部分內(nèi)容梭冠。
Section1
首先準(zhǔn)備單細(xì)胞數(shù)據(jù),我們準(zhǔn)備了27001個(gè)基因6000個(gè)細(xì)胞的數(shù)據(jù):提取表達(dá)數(shù)據(jù)改备,這些操作和之前的一樣控漠,沒(méi)有區(qū)別。
#====================================================================================
# 1悬钳、R中提取seurat單細(xì)胞counts矩陣
#====================================================================================
setwd("D:/KS項(xiàng)目/公眾號(hào)文章/pySCENIC更新")
library(Seurat)
dim(uterus)
# [1] 27001 27914
table(uterus$orig.ident)
# AEH EEC HC
# 9525 12033 6356
#對(duì)于每個(gè)樣本抽取2000個(gè)細(xì)胞進(jìn)行分析盐捷,這里只是演示,太多細(xì)胞沒(méi)有意義,也是為了降低文件大小
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個(gè)細(xì)胞進(jìn)行演示
# [1] 27001 6000
#提取表達(dá)矩陣默勾,用于后續(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好了滞诺。準(zhǔn)備的數(shù)據(jù)集也用最新的。數(shù)據(jù)庫(kù)網(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ù)庫(kù)下載
#1炫隶、Databases ranking the whole genome :https://resources.aertslab.org/cistarget/databases/
#我這里是人的:#需要下載什么淋叶。自己實(shí)際選擇
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
這是所有軟件版本
分析的話(huà)很好辦煞檩,還是和之前一樣,標(biāo)準(zhǔn)的3步栅贴。第一步我們花了大概12多小時(shí)斟湃。后面的步驟就比較快了。運(yùn)行是沒(méi)有任何問(wèn)題檐薯。甚至最后的結(jié)果loom文件我們用之前的R可視化代碼直接“閉眼”運(yùn)行凝赛,沒(méi)有任何問(wèn)題,所以在這里出問(wèn)題的小伙伴,考慮下自己數(shù)據(jù)的問(wèn)題哄酝,軟件的問(wèn)題友存。
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
到這里我們還想探討一個(gè)問(wèn)題,那就是第一步為什么那么慢陶衅,如果仔細(xì)了解過(guò)的話(huà)都知道屡立,第一步的目的是推斷轉(zhuǎn)錄因子與提供的表達(dá)矩陣基因的共表達(dá)模塊,所以慢就是因?yàn)榛蚨嗖缶郧懊嫖覀兊谝徊骄褪且驗(yàn)檫\(yùn)行了所有的基因膨俐。這里我們測(cè)試了兩個(gè)數(shù)據(jù),一個(gè)是1000個(gè)基因1500個(gè)細(xì)胞罩句,一個(gè)是1000個(gè)6000個(gè)細(xì)胞焚刺,發(fā)現(xiàn)運(yùn)行時(shí)間是一樣的。
#一個(gè)比對(duì)
#1000個(gè)基因1500個(gè)細(xì)胞的運(yùn)行時(shí)間
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個(gè)基因6000個(gè)細(xì)胞的運(yùn)行時(shí)間
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.
所以我們建議在運(yùn)行之前门烂,可以對(duì)基因進(jìn)行過(guò)濾乳愉,例如只有幾個(gè)細(xì)胞表達(dá)的基因,或者大多數(shù)細(xì)胞表達(dá)為0的基因可以過(guò)濾后在進(jìn)行分析屯远,因?yàn)檫@些基因沒(méi)有實(shí)質(zhì)的意義和貢獻(xiàn)蔓姚,對(duì)于數(shù)據(jù)的分析結(jié)果也沒(méi)有影響,還能提高效率慨丐。這個(gè)思路我認(rèn)為是沒(méi)有什么問(wèn)題的坡脐。
Section2
Section1的方式我們之前的帖子說(shuō)過(guò),相信很多小伙伴已經(jīng)了解掌握了房揭,只需要更新數(shù)據(jù)庫(kù)和軟件即可备闲。那么這一部分我們?cè)黾拥氖抢胐ocker鏡像進(jìn)行pyscenic分析。關(guān)于docker這里不展開(kāi)說(shuō)捅暴,可以自行百度恬砂。其實(shí)愛(ài)學(xué)習(xí)的小伙伴在pyscenic官網(wǎng)的步驟中已經(jīng)看到了作者講的,docker鏡像分析的步驟伶唯。docker的一個(gè)優(yōu)勢(shì)是速快稍微快一點(diǎn)觉既,不容易出錯(cuò)惧盹,我們也測(cè)試了乳幸,好像是快那么一點(diǎn)。docker的安裝需要root權(quán)限钧椰,所以不懂linux的小伙伴最好不要?jiǎng)哟舛希驗(yàn)閟udo很容易搞壞電腦。如果是服務(wù)器嫡霞,一般共享的也沒(méi)root權(quán)限瓶埋。docker的安裝可聯(lián)系管理員。本地的linux子系統(tǒng)當(dā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é)束后按照之前的帖子進(jìn)行下游的分析和可視化即可挤悉。這就是pyscenic的全部?jī)?nèi)容了。時(shí)不時(shí)更新下數(shù)據(jù)庫(kù)巫湘,更新下軟件装悲,切記不可拿到別人的代碼不思考便運(yùn)行,不可能順利拿到結(jié)果尚氛。覺(jué)得分享有用的點(diǎn)個(gè)贊诀诊、分享一下再走唄!當(dāng)然了一般的共享服務(wù)器是沒(méi)有root權(quán)限的阅嘶,也不可能用sudo命令進(jìn)行操作属瓣。可以參考我們專(zhuān)屬的服務(wù)器:專(zhuān)屬注冊(cè)鏈接:https://www.xiyoucloud.net/aff/OXAAYEPJ