❝前面提到 一眨眼CellphoneDB都更新到v5啦,今天就来看看它更新的绘图功能! ❞
老习惯,CellphoneDB 的官网给到你:https://cellphonedb.readthedocs.io/en/latest/
CellphoneDB 的一路更新历程,依然放出来,你每篇文献都下载下来看了吗看了吗看了吗?
CellphoneDB 对结果的可视化开发了两个包,一个R包 和一个对应的 python版本包:
先来看看 R版本的 ktplots!
## 使用西湖大学的 Bioconductor镜像
options(BioC_mirror="https://mirrors.westlake.edu.cn/bioconductor")
options("repos"=c(CRAN="https://mirrors.westlake.edu.cn/CRAN/"))
# 在线安装有点不好安装
# devtools::install_github("zktuong/ktplots", dependencies = TRUE)
# https://github.com/zktuong/ktplots/ 这里下载安装包 ktplots-master.zip
# 本地安装
devtools::install_local("ktplots-master.zip")
# 加载R包
library(ktplots)
这个数据来自:https://www.kidneycellatlas.org/,对应的文献 于2019年9月27号发表在Science杂志上,文献标题为《Spatiotemporal immune zonation of the human kidney》。这里作者直接放到了R包中,经过了降采样即抽取部分细胞的cellphoneDB结果。
此包绘图需要3个文件:
这里绘图需要理解一下 CellPhoneDB的结果 means.txt 和 pvalues.txt 每一列的含义,详细解释见:
https://cellphonedb.readthedocs.io/en/latest/RESULTS-DOCUMENTATION.html#output-files
library(SingleCellExperiment)
data(kidneyimmune)
# pvals <- read.delim("pvalues.txt", check.names = FALSE)
# means <- read.delim("means.txt", check.names = FALSE)
# decon = pd.read_csv("deconvoluted.txt", sep="\t")
# I've provided an example datasets
data(cpdb_output_stat) # ran with CellPhoneDB statistical analysis mode
data(cpdb_output_degs) # ran with CellPhoneDB degs analysis mode
「用于显示每个细胞类型对之间显著相互作用的数量」
使用这个重新实现的函数可以生成CellPhoneDB的原始热图图示:
# 互作热图
dim(pvals_stat)
pvals_stat[1:5,1:5]
# 绘图
plot_cpdb_heatmap(pvals = pvals_stat, cellheight = 10, cellwidth = 10)
差异分析模式:
# degs_analysis = TRUE
dim( rel_int_degs)
rel_int_degs[1:5,1:5]
plot_cpdb_heatmap(pvals = rel_int_degs, cellheight = 10, cellwidth = 10, degs_analysis = TRUE)
指定细胞亚群:
# 指定细胞亚群
dim(pvals_stat)
pvals_stat[1:5,1:5]
plot_cpdb_heatmap(pvals = pvals_stat, cell_types = c("NK cell", "pDC", "B cell", "CD8T cell"),
cellheight = 10, cellwidth = 10)
「显示所有选定细胞类型/相互作用对的显著相互作用。较大的点表示细胞类型对(x轴)的相互作用(y轴)是相关的,而颜色表示平均表达。」
plot_cpdb 函数:
可以指定某些特定配体受体,以及细胞亚群之间的通讯情况,下图展示的所有B cell 与其他所有细胞类型的 有 "PTPRC", "TNFSF13" 这两个基因的通讯结果:
# 气泡图
kidneyimmune
anno = colData(kidneyimmune)
plot_cpdb(
scdata = kidneyimmune,
cell_type1 = "B cell",
cell_type2 = ".", # this means all cell-types
celltype_key = "celltype",
means = means_stat,
pvals = pvals_stat,
genes = c("PTPRC", "TNFSF13"),
title = "interacting interactions!",
)
这个图跟以前的不一样还加了一个红色的外圈来表示这个通讯是不是具有统计学意义呀!
配受体互作的名字可以保持原始数据库中的:设置 keep_id_cp_interaction = TRUE
# 设置 keep_id_cp_interaction = TRUE
plot_cpdb(
scdata = kidneyimmune,
cell_type1 = "B cell",
cell_type2 = ".", # this means all cell-types
celltype_key = "celltype",
means = means_stat,
pvals = pvals_stat,
genes = c("PTPRC", "TNFSF13"),
title = "interacting interactions!",
keep_id_cp_interaction = TRUE,
)
配受体互作名字:
默认绘制所有显著意义的互作结果:
# 不指定配受体
plot_cpdb(
scdata = kidneyimmune,
cell_type1 = "B cell",
cell_type2 = ".",
celltype_key = "celltype",
means = means_stat,
pvals = pvals_stat,
)
ggsave(filename = "B_cells.png", width = 12,height = 10,bg="white")
还可以更改加的红色外圈展示方式,这种方式受到squidpy包的启发,设置 default_style = FALSE
# 设置 default_style = FALSE
plot_cpdb(
scdata = kidneyimmune,
cell_type1 = "B cell",
cell_type2 = ".",
celltype_key = "celltype",
means = means_stat,
pvals = pvals_stat,
genes = c("PTPRC", "CD40", "CLEC2D"),
default_style = FALSE
)
还可以对细胞亚群进行分组展示,以及配受体展示某一具体基因相关家族如 细胞因子家族chemokines:
设置 splitby_key = "Experiment" 和 gene_family = "chemokines"
# 对细胞亚群进行分组展示
data(cpdb_output) # this is a different dataset where the "Experiment" was appended to the "celltype"
plot_cpdb(
scdata = kidneyimmune,
cell_type1 = "B cell",
cell_type2 = "Neutrophil|MNPc|NK cell",
celltype_key = "celltype",
means = means,
pvals = pvals,
splitby_key = "Experiment",
gene_family = "chemokines"
)
还接受指定的配受体表格:
# 提供指定配受体表格绘制
df <- data.frame(set1 = c("CCR6", "CCL20", "CXCL10", "CCR3", "TNFRSF13C"),
set2 = c("CCL5", "CCR4", "PTPRC", "CD40", "CLEC2D"))
df
plot_cpdb(
scdata = kidneyimmune,
cell_type1 = "B cell",
cell_type2 = "CD4T cell",
celltype_key = "celltype",
means = means,
pvals = pvals,
splitby_key = "Experiment",
gene_family = c("set1", "set2"),
custom_gene_family = df,
)
「plot_cpdb2 为cellphonedb结果生成circos风格的线/弧/和弦图」
这个函数也是新增的:
### 玄图1
data(cpdb_output2) # legacy reasons
plot_cpdb2(
scdata = kidneyimmune,
cell_type1 = "B cell",
cell_type2 = ".",
celltype_key = "celltype", # column name where the cell ids are located in the metadata
means = means2,
pvals = pvals2,
deconvoluted = decon2, # new options from here on specific to plot_cpdb2
desiredInteractions = list( c("CD4T cell", "B cell"), c("B cell", "CD4T cell") ),
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( "CD4T cell" = "red", "B cell" = "blue" ),
)
这里展示了 "CD4T cell", "B cell" 这两种细胞间的具体通讯结果,通讯的连线不同的颜色代表不同的互作情况。
圆圈的颜色表示细胞类型,蓝色为 "B cell",红色为 "CD4T cell"。
「生成一个灵感来源于CellChat展示数据方式的和弦图! 用法与plot_cpdb2相似,但选项减少」
## 与cellchat类似的展示方式
plot_cpdb3(
scdata = kidneyimmune,
cell_type1 = "B cell",
cell_type2 = "CD4T cell|MNPd",
celltype_key = "celltype", # column name where the cell ids are located in the metadata
means = means_stat,
pvals = pvals_stat,
deconvoluted = decon_stat # new options from here on specific to plot_cpdb3
)
「新功能!展示特定交互的弦图的新方法! 用法与plot_cpdb3类似,但需要额外的交互选项」
# new
plot_cpdb4(
scdata = kidneyimmune,
interaction = "CLEC2D-KLRB1",
cell_type1 = "NK",
cell_type2 = "Mast",
celltype_key = "celltype",
means = means_stat,
pvals = pvals_stat,
deconvoluted = decon_stat
)
展示的是 "CLEC2D-KLRB1" 这对配受体在不同亚群之间的情况。
这里还有一个函数 geneDotPlot 可以绘制 基因的表达:
## 基因表达
library(ggplot2)
# Note, this conflicts with tidyr devel version
p <- geneDotPlot(
scdata = kidneyimmune, # object
genes = c("CD68", "CD80", "CD86", "CD74", "CD2", "CD5"), # genes to plot
celltype_key = "celltype", # column name in meta data that holds the cell-cluster ID/assignment
splitby_key = "Project", # column name in the meta data that you want to split the plotting by. If not provided, it will just plot according to celltype_key
standard_scale = TRUE ) +
theme(strip.text.x = element_text(angle = 0, hjust = 0, size = 7)) +
small_guide() +
small_legend()
p
横坐标的1,2表示metadata中的project。
我收录了一些文献中展示细胞通讯结果的图,来看看!
文献《Single-cell dissection of multifocal bladder cancer reveals malignant and immune cells variation between primary and recurrent tumor lesions》
今天分享到这,最重要的还是要看文献中怎么挑选通讯结果用于讲生物学故事!