適用于scRNA-seq的細(xì)胞通訊工具-1:CellphoneDB

先記錄一下,我安裝過程的慘痛經(jīng)歷??饶深,希望小伙伴們避免像我一樣入坑锦募。
起初每一次安裝,不論是使用conda還是pip工具馆纳,發(fā)現(xiàn)安裝好的CellphoneDB(4.0.0)在shell終端總是調(diào)用不了诗良,開始以為沒有設(shè)置好環(huán)境變量,就花了一些時間反復(fù)設(shè)置環(huán)境變量鲁驶,仍是沒有調(diào)用成功鉴裹。后來搜了下,說是python版本對其也有影響钥弯,然后就安裝了python3.8径荔,這一次在python編譯器cellphonedb可以被調(diào)用且為4.0.0版,但是shell終端還是用不了(由于目前很多教程都是基于shell運(yùn)行的)脆霎,因此我又折騰了一番总处,仍是沒有結(jié)果。后來在官網(wǎng)才意外發(fā)現(xiàn)睛蛛,他說CellphoneDB 4.0.0好像是只能在python里使用(那我這里多次安裝都是4.0.0的版本鹦马,可能是存在于我環(huán)境里的該軟件依賴包與4.0.0的可兼容,因此安裝不了其它低版本的吧~~)忆肾。言歸正傳荸频,接下來一起感受一下這個細(xì)胞通訊工具吧!

一客冈、安裝:在終端先創(chuàng)建一個新的環(huán)境旭从,下載適合cellphoneDB的python版本

conda create -n cpdb python=3.8

conda activate cpdb#激活環(huán)境

python3.8 -m pip3 install cellphonedb -i https://pypi.tuna.tsinghua.edu.cn/simple

打開3.8版本的python

python3.8

二、測試:是否安裝成功

import cellphonedb
cellphonedb.version  #4.0.0
from cellphonedb.src.core.methods import cpdb_statistical_analysis_method

三、使用:

1和悦、數(shù)據(jù)準(zhǔn)備退疫,前期使用R處理數(shù)據(jù)

pbmc <- readRDS("pbmc.rds")#這里直接讀入我處理的pbmc3k的示例數(shù)據(jù)

counts <- as.matrix(pbmc@assays$RNA@data)
write.table(counts,'./example_data/cellphonedb_count.txt', header = T,sep='\t', quote=F)

meta_data <- cbind(rownames(pbmc@meta.data), pbmc@meta.data[,'cell_type', drop=F]) 
meta_data <- as.matrix(meta_data)
meta_data[is.na(meta_data)] = "Unkown" #細(xì)胞類型不能為空
write.table(meta_data,'./example_data/cellphonedb_meta.txt', sep='\t', quote=F, row.names=F)

2、再次進(jìn)入python3.8,利用統(tǒng)計學(xué)分析推斷細(xì)胞間的通訊

import cellphonedb

cpdb_file_path = './example_data/cellphonedb.zip'
test_meta_file_path = './example_data/cellphonedb_meta.txt'
test_counts_file_path = './example_data/cellphonedb_count.txt'

from cellphonedb.src.core.methods import cpdb_statistical_analysis_method

deconvoluted, means, pvalues, significant_means = cpdb_statistical_analysis_method.call(
  cpdb_file_path = cpdb_file_path,
  meta_file_path = test_meta_file_path,
  counts_file_path = test_counts_file_path,
  counts_data = 'hgnc_symbol',#注意[ensembl | gene_name | hgnc_symbol] Type of gene 
  iterations = 100,
  threshold = 0.1,
  threads = 6,
  output_suffix = "pbmc",
  output_path = "./example_data/pbmc_out_path")
輸出文件

三鸽素、使用R對結(jié)果進(jìn)行可視化(主要是網(wǎng)絡(luò)圖和點(diǎn)圖蹄咖,python版還在開發(fā)中)

if (!requireNamespace("devtools", quietly = TRUE))
  install.packages("devtools")
if (!requireNamespace("BiocManager", quietly = TRUE))
  install.packages("BiocManager")
devtools::install_github('zktuong/ktplots', dependencies = TRUE)
setwd('./example_data/pbmc_out_path')
library(Seurat)
library(dplyr)
library(psych)
library(qgraph)
library(igraph)
library(tidyverse)
library(ktplots)
library(SingleCellExperiment)
library(reticulate)
data(cpdb_output)#provided an example dataset
pbmc <- readRDS("./example_data/pbmc.rds")
counts <- as.matrix(pbmc@assays$RNA@data)
meta_data <- cbind(rownames(pbmc@meta.data), pbmc@meta.data[,'cell_type', drop=F])  
meta_data <- as.matrix(meta_data)
meta_data[is.na(meta_data)] = "Unkown"

sce <- SingleCellExperiment(assays = list(counts = counts),colData = meta_data)

pvals <- read.delim("statistical_analysis_pvalues_pbmc.txt", check.names = FALSE)
means <- read.delim("statistical_analysis_means_pbmc.txt", check.names = FALSE)
#這里的cell_type1、2指定互作細(xì)胞付鹿,如果不指定則默認(rèn)所有細(xì)胞,split.by用于分組數(shù)據(jù)的
plot_cpdb(cell_type1 = 'T', cell_type2 = 'Mono',scdata = sce,
          idents = 'cell_type', # column name where the cell ids are located in the metadata
          #split.by = 'Experiment', # column name where the grouping column is. Optional.
          means = means, pvals = pvals,
          genes = c("XCR1", "CXCL10", "CCL5")) +
  small_axis(fontsize = 3) + small_grid() + small_guide() + small_legend(fontsize = 2) # some helper functions included in ktplots to help with the plotting
image1.png
plot_cpdb(cell_type1 = 'DC', cell_type2 = '', scdata = sce,
          idents = 'cell_type', means = means, pvals = pvals,
          gene.family = 'chemokines',highlight = 'blue',keep_significant = F, noir = TRUE) + 
  small_guide() + small_axis() + small_legend(keysize=.5)
image2.png

plot_cpdb2繪制圈圖:

deconvoluted <- read.delim('statistical_analysis_deconvoluted_pbmc.txt', check.names = FALSE)
interaction_annotation <- read.delim()#由于打不開網(wǎng)站蕊肥,因此沒有下載到這個文件愕掏,在前面可以通過data(cpdb_output)加載出該文件的
也可加載示列數(shù)據(jù)data(cpdb_output2),我這里仍使用的pbmc3k:
plot_cpdb2(cell_type1 = 'DC', cell_type2 = 'NK',
           scdata = sce,
           idents = 'cell_type', # column name where the cell ids are located in the metadata
           means = means,
           pvals = pvals,
           deconvoluted = deconvoluted, # new options from here on specific to plot_cpdb2
           desiredInteractions = list(
             c('DC', 'NK'),
             c('NK', 'DC')),
           interaction_grouping = interaction_annotation,
           edge_group_colors = c(
             "Activating" = "#e15759",
             "Chemotaxis" = "#59a14f",
             "Inhibitory" = "#4e79a7",
             "Intracellular trafficking" = "#9c755f",
             "DC_development" = "#B07aa1",
             "Unknown" = "#e7e7e7"
           ),
           node_group_colors = c(
             "DC" = "red",
             "NK" = "blue"),
           keep_significant_only = TRUE,
           standard_scale = TRUE,
           remove_self = TRUE)
image3.png
plot_cpdb2(cell_type1 = "B|DC|NK", # same usage style as plot_cpdb
           cell_type2 = "CD4 T",
           idents = 'cell_type',
           #split.by = 'treatment_group_1',
           scdata = sce,
           means = means,
           pvals = pvals,
           deconvoluted = deconvoluted, # new options from here on specific to plot_cpdb2
           gene_symbol_mapping = 'index', # column name in rowData holding the actual gene symbols if the row names is ENSG Ids. Might be a bit buggy
           desiredInteractions = list(c('B', 'Naive CD4 T'), c('B', 'Memory CD4 T'), c('DC', 'Naive CD4 T'), c('DC', 'Memory CD4 T'), c('NK', 'Naive CD4 T'), c('NK', 'Memory CD4 T')),
           interaction_grouping = interaction_annotation,
           edge_group_colors = c("Activating" = "#e15759", "Chemotaxis" = "#59a14f", "Inhibitory" = "#4e79a7", "   Intracellular trafficking" = "#9c755f", "DC_development" = "#B07aa1"),
           node_group_colors = c("B" = "#86bc86", "DC" = "#79706e", "NK" = "#ff7f0e", 'Naive CD4 T' = "#bcbd22"  ,'Memory CD4 T' = "#17becf"),
           keep_significant_only = TRUE,
           standard_scale = TRUE,
           remove_self = TRUE)
image4.png

plot_cpdb3

plot_cpdb3(cell_type1 = 'T', cell_type2 = 'Mono',
    scdata = sce,
    idents = 'cell_type', # column name where the cell ids are located in the metadata
    means = means,
    pvals = pvals,
    deconvoluted = deconvoluted,
    keep_significant_only = TRUE,
    standard_scale = TRUE,
    remove_self = TRUE)
image5.png

plot_cpdb4

#這里由于上面的pbmc數(shù)據(jù)畫出的圖都不太好看,因此下面直接加載包中自帶的示列數(shù)據(jù)進(jìn)行演示
data(kidneyimmune)
data(cpdb_output2)
plot_cpdb4(
    interaction = 'CLEC2D-KLRB1',
    cell_type1 = 'NK', cell_type2 = 'Mast',
    scdata = kidneyimmune,
    idents = 'celltype',
    means = means2,
    pvals = pvals2,
    deconvoluted = decon2,
    keep_significant_only = TRUE,
    standard_scale = TRUE)
image6.png
plot_cpdb4(
        interaction = c('CLEC2D-KLRB1', 'CD40-CD40LG'),
        cell_type1 = 'NK|B', cell_type2 = 'Mast|CD4T',
        scdata = kidneyimmune,
        idents = 'celltype',
        means = means2,
        pvals = pvals2,
        deconvoluted = decon2,
        desiredInteractions = list(
            c('NK cell', 'Mast cell'),
            c('NK cell', 'NKT cell'),
            c('NKT cell', 'Mast cell'),
            c('B cell', 'CD4T cell')),
        keep_significant_only = TRUE)
image7.png

好了,關(guān)于CellphoneDB的初學(xué)使用先到這里吧场躯,如有錯誤之處诅妹,請指正郎汪。謝謝森瘪!??

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市吵血,隨后出現(xiàn)的幾起案子谎替,更是在濱河造成了極大的恐慌,老刑警劉巖蹋辅,帶你破解...
    沈念sama閱讀 206,839評論 6 482
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件钱贯,死亡現(xiàn)場離奇詭異,居然都是意外死亡侦另,警方通過查閱死者的電腦和手機(jī)秩命,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,543評論 2 382
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來褒傅,“玉大人弃锐,你說我怎么就攤上這事〉钔校” “怎么了霹菊?”我有些...
    開封第一講書人閱讀 153,116評論 0 344
  • 文/不壞的土叔 我叫張陵,是天一觀的道長支竹。 經(jīng)常有香客問我旋廷,道長,這世上最難降的妖魔是什么唾戚? 我笑而不...
    開封第一講書人閱讀 55,371評論 1 279
  • 正文 為了忘掉前任柳洋,我火速辦了婚禮待诅,結(jié)果婚禮上叹坦,老公的妹妹穿的比我還像新娘。我一直安慰自己卑雁,他們只是感情好募书,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,384評論 5 374
  • 文/花漫 我一把揭開白布绪囱。 她就那樣靜靜地躺著,像睡著了一般莹捡。 火紅的嫁衣襯著肌膚如雪鬼吵。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,111評論 1 285
  • 那天篮赢,我揣著相機(jī)與錄音齿椅,去河邊找鬼。 笑死启泣,一個胖子當(dāng)著我的面吹牛涣脚,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播寥茫,決...
    沈念sama閱讀 38,416評論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼遣蚀,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了纱耻?” 一聲冷哼從身側(cè)響起芭梯,我...
    開封第一講書人閱讀 37,053評論 0 259
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎弄喘,沒想到半個月后玖喘,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,558評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡蘑志,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,007評論 2 325
  • 正文 我和宋清朗相戀三年芒涡,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片卖漫。...
    茶點(diǎn)故事閱讀 38,117評論 1 334
  • 序言:一個原本活蹦亂跳的男人離奇死亡费尽,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出羊始,到底是詐尸還是另有隱情旱幼,我是刑警寧澤,帶...
    沈念sama閱讀 33,756評論 4 324
  • 正文 年R本政府宣布突委,位于F島的核電站柏卤,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏匀油。R本人自食惡果不足惜缘缚,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,324評論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望敌蚜。 院中可真熱鬧桥滨,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,315評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至喻括,卻和暖如春邀杏,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背唬血。 一陣腳步聲響...
    開封第一講書人閱讀 31,539評論 1 262
  • 我被黑心中介騙來泰國打工望蜡, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人拷恨。 一個月前我還...
    沈念sama閱讀 45,578評論 2 355
  • 正文 我出身青樓泣特,卻偏偏與公主長得像,于是被迫代替她去往敵國和親挑随。 傳聞我的和親對象是個殘疾皇子状您,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,877評論 2 345