适用于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的初学使用先到这里吧,如有错误之处,请指正。谢谢!😊

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。