首先祝大家新年快樂窟她!新的一年paper多多纳账,順順利利兄旬!
cpplot
:
Visualize the results of cell-cell communication analysis based on CellPhoneDB
整理了“TOP生物信息”上面幾篇講解CellPhoneDB的原創(chuàng)帖子幅聘,將其中涉及到的代碼稍加整理得到此R包凡纳。
- 基于CellPhoneDB的細(xì)胞通訊分析及可視化 (上篇)——2021-07-24發(fā)布
- 基于CellPhoneDB的細(xì)胞通訊分析及可視化 (下篇)——2021-07-24發(fā)布
- 【單細(xì)胞高級(jí)繪圖】08.細(xì)胞通訊兩組比較氣泡圖——2022-08-30發(fā)布
- 【單細(xì)胞高級(jí)繪圖】09.細(xì)胞通訊兩組比較連線圖——2022-08-31發(fā)布
簡(jiǎn)而言之,這個(gè)包對(duì)接的是CellPhoneDB的流程喊暖,跑完CellPhoneDB之后惫企,可能需要畫幾張圖,比如:
- 各種細(xì)胞之間互作的數(shù)量關(guān)系
- 具體的互作細(xì)節(jié)(什么細(xì)胞之間有什么L-R pair)
- 如果有兩個(gè)組都進(jìn)行了CellPhoneDB的分析,如何比較兩組的結(jié)果
下面代碼演示一下
0. 下載并加載R包
最好提前安裝幾個(gè)依賴包:
RColorBrewer, igraph, reshape2, scales, tidyverse, xlsx
devtools::install_github("SiyuanHuang1/cpplot")
library(cpplot)
library(tidyverse)
1. 各種細(xì)胞之間互作的數(shù)量關(guān)系
這一部分狞尔,有三個(gè)函數(shù)可以實(shí)現(xiàn)丛版,分別是:
ccc_number_heatmap1(pfile = "test/pvalues.txt") #ggplot對(duì)象
ccc_number_heatmap2(pfile = "test/pvalues.txt") #ggplot對(duì)象
ccc_number_line(pfile = "test/pvalues.txt",vertex.size = 20) #不是ggplot對(duì)象,不能用ggsave保存
出圖如下:
(圖片的解讀可以參考我最上面提到的幾篇帖子)
2. 具體的互作細(xì)節(jié)
ccc_bubble(
pfile="./test/pvalues.txt",
mfile="./test/means.txt",
# 下面這些是默認(rèn)參數(shù)偏序,可以不變
# neg_log10_th = -log10(0.05),
# means_exp_log2_th = 1,
# notused.cell = NULL,
# used.cell = NULL,
# neg_log10_th2 = 3,
# means_exp_log2_th2 = c(-4, 6),
# cell.pair = NULL,
# gene.pair = NULL,
# color_palette = c("#313695", "#4575B4", "#ABD9E9", "#FFFFB3", "#FDAE61", "#F46D43","#D73027", "#A50026"),
# text_size = 12
)
# 改寫參數(shù)
ccc_bubble(
pfile="./test/pvalues.txt",
mfile="./test/means.txt",
cell.pair=c("Mcell|Scell","Mcell|NKcell","Mcell|Tcell","Scell|Mcell","NKcell|Mcell","Tcell|Mcell"),
#這里是自定義的順序页畦,若是可選細(xì)胞對(duì)的子集,則只展示子集研儒,若有交集則只展示交集豫缨;空值情況下,會(huì)根據(jù)可選細(xì)胞對(duì)自動(dòng)排序
gene.pair=c("MIF_TNFRSF14","FN1_aVb1 complex","EGFR_MIF")
#作用同上
)
3. 兩組之間的比較
第1種圖
### 必要參數(shù)
ccc_compare(group1.name = "Old",group2.name = "Young",
group1.pfile = "cellphonedb/Old/pvalues.txt",group1.mfile="cellphonedb/Old/means.txt",
group2.pfile="cellphonedb/Young/pvalues.txt",group2.mfile="cellphonedb/Young/means.txt",
p.threshold = 0.01,thre=1,
plot.width=105,plot.height=110,filename = "test0121_"
)
### 額外參數(shù)
# 比如端朵,這里我想展示EC細(xì)胞分別充當(dāng)cellA和cellB的圖
# 也可以指定gene pair
ccc_compare(group1.name = "Old",group2.name = "Young",
group1.pfile = "cellphonedb/Old/pvalues.txt",group1.mfile="cellphonedb/Old/means.txt",
group2.pfile="cellphonedb/Young/pvalues.txt",group2.mfile="cellphonedb/Young/means.txt",
p.threshold = 0.05,thre=1,
#gene.pair = NULL,
cell.pair=c(
paste0("EC|",c("APC","SMC","Mac","DC","Neutrophil")),
paste0(c("APC","SMC","Mac","DC","Neutrophil"),"|EC")
),
plot.width=18,plot.height=30,filename = "test0121b_"
)
(圖片的解讀可以參考我最上面提到的幾篇帖子)
第2種圖
ccc_compare2(group1.name = "Old",group2.name = "Young",
group1.pfile = "cellphonedb/Old/pvalues.txt",group1.mfile="cellphonedb/Old/means.txt",
group2.pfile="cellphonedb/Young/pvalues.txt",group2.mfile="cellphonedb/Young/means.txt",
p.threshold = 0.05,thre=0.5,
cell.pair="EC|APC", #指定ligand產(chǎn)生的細(xì)胞|receptor產(chǎn)生的細(xì)胞
plot.width=15,plot.height=30,filename = "test0121_"
)
之后會(huì)得到一個(gè)xlsx表格好芭,畫圖會(huì)用到
ccc_line(table.path="test0121_Old2Young.xlsx",ligand.cell="EC",receptor.cell="APC",
group1.name = "Old",group2.name = "Young",#這五個(gè)參數(shù)和上一步對(duì)應(yīng)
ligand.color="#4dbbd6",receptor.color="#90d1c1",
pt.size=6,
line.thre1=0.5,line.thre2=6,#line.thre1和上一步的"thre"參數(shù)一致,line.thre2可以用來調(diào)整線的粗細(xì)冲呢,值越大舍败,線越細(xì)
file.name="test0121b_",plot.width=25,plot.height=20)
然后就能得到這張圖:
(圖片的解讀可以參考我最上面提到的幾篇帖子)。
第3種圖
ccc_compare2(group1.name = "Old",group2.name = "Young",
group1.pfile = "cellphonedb/Old/pvalues.txt",group1.mfile="cellphonedb/Old/means.txt",
group2.pfile="cellphonedb/Young/pvalues.txt",group2.mfile="cellphonedb/Young/means.txt",
p.threshold = 0.05,thre=0.5,
cell.pair="EC|APC", #指定ligand產(chǎn)生的細(xì)胞|receptor產(chǎn)生的細(xì)胞
plot.width=15,plot.height=30,filename = "test0121_"
)
這一步跟第2種圖一樣敬拓。后續(xù)還要找兩組的差異基因
library(Seurat)
testseu=readRDS("testseu.rds")
# 此次演示為了加快運(yùn)行速度邻薯,人為減少了數(shù)據(jù)量,實(shí)際分析中找差異基因不建議這么做
selectedCB=sample(testseu@meta.data$CB,1000)
testseu=testseu%>%subset(CB %in% selectedCB)
# 基于分組找差異基因
marker_group=data.frame()
Idents(testseu)="celltype_age"
for ( ci in c("EC","APC") ) {
tmp.marker <- FindMarkers(
testseu, logfc.threshold = 0, min.pct = 0.01,
only.pos = F, test.use = "wilcox",
ident.1=paste0(ci,"_Old"),ident.2=paste0(ci,"_Young")
)
tmp.marker$gene=rownames(tmp.marker)
tmp.marker$cluster_group=ifelse(tmp.marker$avg_log2FC > 0,paste0(ci,"_Old"),paste0(ci,"_Young"))
tmp.marker$cluster=ci
tmp.marker=tmp.marker%>%arrange(desc(avg_log2FC))
marker_group=marker_group%>%rbind(tmp.marker)
}
#本次演示的數(shù)據(jù)集為小鼠數(shù)據(jù)集乘凸,在運(yùn)行cellphonedb時(shí)厕诡,進(jìn)行了基因symbol的轉(zhuǎn)換。
#此處找差異基因得到的symbol為真實(shí)基因名营勤,為了讓兩個(gè)分析匹配灵嫌,DEG表格也應(yīng)該做基因名轉(zhuǎn)換。
#但是為了簡(jiǎn)化冀偶,此處只是簡(jiǎn)單地將小鼠基因名轉(zhuǎn)為大寫醒第,不是很精確。大家在分析的時(shí)候建議嚴(yán)格一點(diǎn)进鸠。
marker_group$gene=marker_group$gene %>% toupper()
然后借助差異基因稠曼,再畫圖
ccc_line2(cpdb.table.path = "test0121_Old2Young.xlsx",marker_group = marker_group,
ligand.cell = "EC",receptor.cell = "APC",
group1.name = "Old",group2.name = "Young",
line.size = 2,file.name = "test0121b_",plot.width = 25,plot.height = 20
)
(圖片的解讀可以參考我最上面提到的幾篇帖子)