学习,记录,分享。
细胞通讯学习-cellchat
1 安装依赖
按照官方文档说明,先安装4个依赖
- NMF (>= 0.23.0)
- circlize (>= 0.4.12)
- ComplexHeatmap
- UMAP(python包)
已经安装过的可以直接跳过。首先安装R包:
代码语言:javascript复制install.packages('NMF') #成功,可能会遇到缺少其他依赖包的报错,缺啥补啥就行
#如果遇到R版本报错,在R终端先运行以下代码:
Sys.setenv(R_REMOTES_NO_ERRORS_FROM_WARNINGS=TRUE)
#剩下两个包
devtools::install_github("jokergoo/circlize") #成功
devtools::install_github("jokergoo/ComplexHeatmap") #成功
安装python包:
代码语言:javascript复制pip install umap-learn #这个在终端运行,有的可能需要用pip3
2 安装cellchat
以上依赖都安装完后,使用以下代码安装cellchat:
代码语言:javascript复制devtools::install_github("sqjin/CellChat")
报错,CMake was not found on the PATH. Please install CMake.
因为我是用conda配置环境,这里用conda来安装:
代码语言:javascript复制conda install cmake
在R终端继续安装cellchat:
继续报错,缺少一堆依赖包:ERROR: dependencies ‘RSpectra’, ‘RcppEigen’, ‘ggpubr’, ‘BiocNeighbors’ are not available for package ‘CellChat’.
缺啥装啥:
代码语言:javascript复制BiocManager::install(c('RSpectra', 'RcppEigen', 'ggpubr', 'BiocNeighbors'))
#中间遇到依赖问题,conda解决
conda install r-RcppEigen r-ggpubr r-RSpectra -c conda-forge
安装好后继续安装cellchat:
遇到提示:pragma clang diagnostic pop;报错:r: no member named 'Rlog1p' in namespace 'std'; did you mean 'log1p'?r: no member named 'Rlog1p' in namespace 'std'; did you mean 'log1p'?
google后,在github查到这是M芯片的mac会有的问题:
R on ARM Mac M1:load failed for ‘stats’ and Rlog1p error #163
解决办法,终端运行:
代码语言:javascript复制export PKG_CPPFLAGS="-DHAVE_WORKING_LOG1P"
再打开R终端运行:
代码语言:javascript复制devtools::install_github("sqjin/CellChat")
3 准备数据
需要准备一个标注好细胞类型的单细胞数据,这里选择seurat官方的pbmc3k数据:
pbmc3k下载地址: https://cf.10xgenomics.com/samples/cell/pbmc3k/pbmc3k_filtered_gene_bc_matrices.tar.gz
seurat流程标注细胞类型:
代码语言:javascript复制library(tidyverse)
library(Seurat)
# 数据预处理和降维聚类
pbmc3k <- Read10X('../data/pbmc3k/filtered_gene_bc_matrices/hg19/') %>%
CreateSeuratObject(project = 'pbmc3k', min.cells = 3, min.features = 200) %>%
AddMetaData(., PercentageFeatureSet(., pattern = "^MT-"), col.name = 'percent.mt') %>%
subset(subset = nFeature_RNA > 200 & nFeature_RNA < 2500 & percent.mt < 5) %>%
NormalizeData() %>%
FindVariableFeatures() %>%
ScaleData() %>%
RunPCA() %>%
FindNeighbors(dims = 1:10) %>%
FindClusters(resolution = 0.5) %>%
RunUMAP(dims = 1:10)
DimPlot(pbmc3k, label = T)
ggsave('plot/pbmc3k_orig_umap.png')
# 标注
new.cluster.ids <- c("Naive CD4 T", "CD14 Mono", "Memory CD4 T", "B", "CD8 T", "FCGR3A Mono",
"NK", "DC", "Platelet")
names(new.cluster.ids) <- levels(pbmc3k)
pbmc3k <- RenameIdents(pbmc3k, new.cluster.ids)
DimPlot(pbmc3k, reduction = "umap", label = TRUE, pt.size = 0.5) NoLegend()
ggsave('plot/pbmc3k_anno_umap.png')
# 保存数据
write_rds(pbmc3k, 'data/pbmc3k_anno.rds')
数据已经标注好,接下来可以走单个数据的细胞通讯分析了。
参考资料
- cellchat官方教程(https://github.com/sqjin/CellChat)