接上一節(jié)(【視頻教程】Cellphonedb v5更新:python版Scanpy單細(xì)胞分析后續(xù)之cpdb細(xì)胞通訊)。我們通過(guò)對(duì)cpdb結(jié)果的整合得到cpdb_pbmc_summary,這里我們對(duì)結(jié)果進(jìn)行可視化,主要是弦圖的可視化,看了一下,之前好像對(duì)于cpdb沒(méi)有做過(guò)太多的弦圖。為了方便,我們借助了R包和一些文章,然后進(jìn)行了修改,包裝為可視化函數(shù),方便使用。完整代碼已發(fā)布微信VIP群,請(qǐng)自行下載!視頻解說(shuō)見(jiàn)B站:https://www.bilibili.com/video/BV1V4DVY8Ehq/?spm_id_from=333.999.0.0&vd_source=05b5479545ba945a8f5d7b2e7160ea34首先我們用整合結(jié)果做個(gè)常見(jiàn)的氣泡圖,就會(huì)很簡(jiǎn)單,可以篩選需要展示的互作,結(jié)果可以自行修飾。
setwd('D:\\KS項(xiàng)目\\公眾號(hào)文章\\cpdb結(jié)果可視化之-氣泡圖-弦圖')
df <- read.csv('./cpdb_pbmc_summary.txt', header = T, sep = '\t', row.names = 1)
# plot dotplot ------------------------------------------------------------
#提取需要的互作
# unique(df$celltype_pair)
df_sce <- df[df$celltype_pair %in% c("B|B","B|CD14 Monocytes","B|CD4 T","B|CD8 T","B|Dendritic",
"B|FCGR3A Monocytes","B|NK","B|FCGR3A Monocytes"),]
#篩選顯著的互作
df_sce <- df_sce[df_sce$pval <=0.05,]
colnames(df)
# [1] "interacting_pair" "celltype_pair" "mean" "pval"
library(ggplot2)
#ggplot作圖
ggplot(df_sce, aes(x=celltype_pair, y=interacting_pair,
size= -log10(pval+0.001), color=mean)) +
geom_point(stat = "identity")+
geom_point(aes(size= -log10(pval+0.001)), shape = 21, colour="black", stroke=1)+
theme_bw()+
scale_y_discrete(limits=rev)+
scale_fill_viridis_c(option = "magma", guide = "colourbar", aesthetics = "color", direction=-1)+
theme(axis.text.x = element_text(size = 10, angle=45, hjust=1, vjust=1, colour = 'black'),
axis.text.y = element_text(size = 10, colour = 'black'),
axis.title.x = element_text(face='bold', size=12),
axis.title.y = element_text(face='bold', size=12))+
xlab("Cell_pair") + ylab("ligand_receptor pair")

弦圖1:這個(gè)靈感來(lái)自于(R語(yǔ)言弦圖繪制-(單細(xì)胞互作弦圖))。有一個(gè)包italk也是分析互作的,但是我覺(jué)得它的可視化還挺好,可以直接拿來(lái)用,之前也演示了cellchat的結(jié)果,這里我們將LRPlot函數(shù)進(jìn)行修改,能夠適用于于我們的分析可視化:展示不同細(xì)胞之間的互作,以及受配體對(duì),如果需要展示特定的,可以自行篩選數(shù)據(jù)!
# plot circle -------------------------------------------------------------
library(tidyr)
library(dplyr)
library(iTALK)
library(circlize)
# circle_plot1 ------------------------------------------------------------
#挑選顯著互作
df_sig <- df[df$pval <=0.05 & df$mean >= 2,]
df_sig <- df_sig %>% separate(celltype_pair, c("source", "target"), "\\|")
df_sig <- df_sig %>% separate(interacting_pair, into = c("ligand", "receptor"), sep = "_", extra = "merge")
#可以選擇自己需要展示的受配體展示,挑選數(shù)據(jù)即可
#這里我直接按照mean排序,選擇前40可視化
df_sig <- df_sig[order(-df_sig$mean),]
df_sig_plot <- df_sig[1:40,]
# colnames(df_sig)[3] <- "cell_from"
# colnames(df_sig)[4] <- "cell_to"
#
#
# df_sig <- df_sig %>%
# select(1:2, cell_from_mean_exprs = 3, 4:ncol(.)) %>%
# mutate(cell_from_mean_exprs = df_sig$mean)
#
#
# df_sig <- df_sig %>%
# select(1:2, cell_from_mean_exprs = 3, 4:ncol(.)) %>%
# mutate(cell_from_mean_exprs = df_sig$mean)
#設(shè)置顏色
gene_col<-structure(c(rep('#CC3333',length(df_sig_plot$ligand)),
rep("#006699",length(df_sig_plot$receptor))),
names=c(df_sig_plot$ligand,df_sig_plot$receptor))
cell_col <- structure(c("#d2981a", "#a53e1f", "#457277", "#8f657d", "#42819F", "#86AA7D", "#CBB396"),
names=unique(df_sig_plot$source))#設(shè)置細(xì)胞顏色
#弦圖連線體現(xiàn)source cell,link_cols = T,不設(shè)置link.arr.col
ks_iTALK_LRPlot(df_sig_plot,#挑選前40作圖
link_cols = T,
link.arr.lwd=df_sig_plot$mean,
link.arr.width=0.1,
link.arr.type = "triangle",
link.arr.length = 0.1,
# link.arr.col = alpha("#47B9B5",0.4),#連線顏色設(shè)置
print.cell = T,
track.height_1=uh(5, "mm"),
track.height_2 = uh(10, "mm"),
annotation.height_1=0.02,
annotation.height_2=0.02,
text.vjust = "0.1cm",
gene_col = gene_col,
cell_col = cell_col)
#弦圖連線不體現(xiàn)source cell,link_cols = F,設(shè)置link.arr.col
ks_iTALK_LRPlot(df_sig_plot,#挑選前40作圖
link_cols = F,
link.arr.lwd=df_sig_plot$mean,
link.arr.width=0.1,
link.arr.type = "triangle",
link.arr.length = 0.1,
link.arr.col = alpha("#47B9B5",0.4),#連線顏色設(shè)置
print.cell = T,
track.height_1=uh(5, "mm"),
track.height_2 = uh(10, "mm"),
annotation.height_1=0.02,
annotation.height_2=0.02,
text.vjust = "0.1cm",
gene_col = gene_col,
cell_col = cell_col)

弦圖2:
這個(gè)是參考了一篇《Nature》文章的方式,具體文獻(xiàn)參見(jiàn):reference:A prenatal skin atlas reveals immune regulation of human skin morphogenesis,https://doi.org/10.1038/s41586-024-08002-x,文章提供了代碼可以學(xué)習(xí)一下非常好。展示是將source cell/ligands和receiver cell/receptor結(jié)合展示,最好是展示特定的受配體和特定細(xì)胞,我們也將這個(gè)過(guò)程修改為函數(shù)。
# circle_plot2 ------------------------------------------------------------
#挑選自己感興趣的細(xì)胞進(jìn)行可視化,選擇顯著的互作
df_sig <- df[df$pval <=0.05,]
cell_inter = c('NK|CD14 Monocytes', 'NK|FCGR3A Monocytes')
LR = c('CD1D_LILRB2', 'CD44_TYROBP', 'CD48_CD244',"HLA-F_KIR3DL2")
ks_comm_chordDiagram(data = df_sig,
cell_inter = cell_inter,
LR=LR,
group=c("NK"='#0c0459',
"CD14 Monocytes"='#F09709',
"FCGR3A Monocytes"='#47B9B5'),
text_size=0.8)
