分享

scRNA分析 | 解决可能的报错,从0开始教你完成细胞通讯分析-cellphoneDB

 生信补给站 2022-12-06 发布于北京

CellPhoneDB是一个受配体及其相互作用的数据库,整合了UniProt, ensemble, PDB, IMEx,IUPHAR等数据库的信息CellPhoneDB数据库概况如下图所示


本文将从头开始介绍(1)如何安装cellphonedb以及解决可能的报错,(2)如何下载cellphonedb数据库,(3)单细胞数据提取输入文件 以及(4)简单的可视化.

一 cellphonedb准备

1,cellphonedb安装

考虑到不同的生信软件对于python 或者 R 的版本要求不一致,建议建立一个独立的python环境。官网https://github.com/ventolab/CellphoneDB介绍了conda 和 virtualenv 2种方式,这里使用conda的方式。

1) Create python=>3.6 environment

conda create -n cpdb python=3.7

2) Activate environment

source activate cpdb

3) Install CellPhoneDB

pip install cellphonedb

ERROR1:如果这一步出现如下报错

解决方式就是先安装一下rpy2

conda install -c conda-forge rpy2

安装之后再安装pipinstallcellphonedb 即可。

检测方式:在终端输入cellphonedb ,出现如下截图的提示则安装成功,cellphonedb主要commands有四个,本文主要介绍一下红框内的method和plot,database也很重要 。

安装成功!

2,下载cellphoneDB数据库

一般直接默认选择最新的版本。

(1)使用上述的database参数下载数据库文件,cellphonedb database download

[ ][APP][05/12/22-17:19:52][INFO] Downloading release v4.0.0 of CellPhoneDB database[ ][APP][05/12/22-17:20:06][INFO] Download completed![ ][APP][05/12/22-17:20:06][INFO] Copying database to xxx/releases/v4.0.0

(2)在https://github.com/ventolab/CellphoneDB-data 网址手动下载cellphone.db文件 。

以上两种方式均可以,记清楚数据库文件所在的路径就可以。

3,准备输入文件

在单细胞的seuratObject文件中提取矩阵文件和注释文件,这里以以一个样本为例

library(Seurat) library(tidyverse)load("sce.anno.RData")#使用一个样本作为示例test <- subset(sce2, sample == "P01")
#注释文件meta_data <- test@meta.data %>% rownames_to_column("Cell") %>% select(Cell,celltype) write.table(meta_data, 'test_meta.txt', sep='\t', quote=F, row.names=F)
#矩阵文件test@assays$RNA@data[1:4,1:4]write.table(as.matrix(test@assays$RNA@data), 'test_count.txt', sep='\t', quote=F)
test@assays$RNA@data[1:4,1:4]4 x 4 sparse Matrix of class "dgCMatrix" K16733_AAACATACTCGTTT-1 K16733_AAAGCAGAACGTTG-1 K16733_AAAGCAGACTGAGT-1 K16733_AAAGGCCTGCTCCT-1MIR1302-2HG . . . .FAM138A . . . .OR4F5 . . . .AL627309.1                        .                       .                       .                       .

将上述的test_count.txt ,test_meta.txt 和 cellphone.db文件,上传到终端。

二 cellphonedb 计算

1,method-计算通讯关系

(1)首先使用method参数进行主要的细胞通讯计算

cellphonedb method statistical_analysis test_meta.txt test_count.txt --database ./cellphone.db --counts-data=gene_name --output-path

主要参数:

--database  :cellphonedb数据库文件

--counts-data :count 矩阵是基因名格式,添加参数--counts-data=gene_name ;如果行名为ensemble名称的话,可以使用默认值。

--output-path  :输出路径

其他一些默认参数:Threshold:0.1 Iterations:1000 Debug-seed:-1 Threads:4 Precision:3

(2)运算完成后,会在输出路径下得到以下4个文件:

deconvoluted.txt:基因在亚群中的平均表达量
mean.txt:每对受体-配体的平均表达量
pvalues.txt:每对受体-配体的p值
significant_means.txt:每对受体-配体显著性结果的平均表达量值

2, cellphonedb可视化

cellphonedb提供了plot函数可以进行简单的可视化

#气泡图cellphonedb plot dot_plot #热图cellphonedb plot heatmap_plot test_meta.txt

ERROR2:如果出现如下报错

ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/proj/cellphone_env2/lib/python3.7/site-packages/markupsafe/__init__.py)

解决方式:可以将markupsafe降为2.0.1 。

 pip install markupsafe==2.0.1

ERROR3:出现如下报错,提示没有ggplot2

解决方式:安装R环境以及对应的R包

conda install -c conda-forge r-base=3.6.2 # if not installed alreadyconda install -c conda-forge  r-ggplot2conda install -c conda-forge r-pheatmap

之后再运行plot即可得到以下2张图

至此cellphonedb的主要分析就完成了!

A:当然希望你不会遇到以上ERROR,如果遇到了那就解决就完事。

B:当然也可以根据method得到的4个结果文件,使用ggplot2或其他R包自行绘制 (以待后续)。

参考资料: https://github.com/Teichlab/cellphonedb

◆ ◆ ◆  ◆ 

精心整理(含图PLUS版)|R语言生信分析,可视化(R统计,ggplot2绘图,生信图形可视化汇总)

    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多