适用于scRNA-seq的细胞通讯工具-1:CellphoneDB

先记录一下,我安装过程的惨痛经历😭,希望小伙伴们避免像我一样入坑。
起初每一次安装,不论是使用conda还是pip工具,发现安装好的CellphoneDB(4.0.0)在shell终端总是调用不了,开始以为没有设置好环境变量,就花了一些时间反复设置环境变量,仍是没有调用成功。后来搜了下,说是python版本对其也有影响,然后就安装了python3.8,这一次在python编译器cellphonedb可以被调用且为4.0.0版,但是shell终端还是用不了(由于目前很多教程都是基于shell运行的),因此我又折腾了一番,仍是没有结果。后来在官网才意外发现,他说CellphoneDB 4.0.0好像是只能在python里使用(那我这里多次安装都是4.0.0的版本,可能是存在于我环境里的该软件依赖包与4.0.0的可兼容,因此安装不了其它低版本的吧~~)。言归正传,接下来一起感受一下这个细胞通讯工具吧!

一、安装:在终端先创建一个新的环境,下载适合cellphoneDB的python版本

conda create -n cpdb python=3.8

conda activate cpdb#激活环境

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、数据准备,前期使用R处理数据

pbmc <- readRDS("pbmc.rds")#这里直接读入我处理的pbmc3k的示例数据

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" #细胞类型不能为空
write.table(meta_data,'./example_data/cellphonedb_meta.txt', sep='\t', quote=F, row.names=F)

2、再次进入python3.8,利用统计学分析推断细胞间的通讯

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对结果进行可视化(主要是网络图和点图,python版还在开发中)

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指定互作细胞,如果不指定则默认所有细胞,split.by用于分组数据的
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()#由于打不开网站,因此没有下载到这个文件,在前面可以通过data(cpdb_output)加载出该文件的
也可加载示列数据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数据画出的图都不太好看,因此下面直接加载包中自带的示列数据进行演示
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

好了,关于CellphoneDB的初学使用先到这里吧,如有错误之处,请指正。谢谢!😊

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 218,036评论 6 506
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,046评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,411评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,622评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,661评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,521评论 1 304
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,288评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,200评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,644评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,837评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,953评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,673评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,281评论 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,889评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,011评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,119评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,901评论 2 355