之前介紹過(guò)使用cellphoneDB 進(jìn)行細(xì)胞通訊分析scRNA分析 | 解決可能的報(bào)錯(cuò),從0開(kāi)始教你完成細(xì)胞通訊分析-cellphoneDB,可能會(huì)遇到一些報(bào)錯(cuò)。這次介紹另一款細(xì)胞通訊分析的常見(jiàn)方法CellChat 。CellChat是一款R包,使用更容易且可視化結(jié)果也非常不錯(cuò)。
一 數(shù)據(jù)輸入,處理
首選安裝CellChat 包,然后繼續(xù)使用之前的sce2數(shù)據(jù)進(jìn)行展示
#devtools::install_github("sqjin/CellChat")
library(CellChat)
library(tidyverse)
library(Seurat)
options(stringsAsFactors = FALSE)
#提取表達(dá)矩陣和細(xì)胞分類信息
#scRNA <- readRDS(url("https://zenodo.org/record/3531889/files/seuratObj.rds"))
load("sce.anno.RData")
head(sce2@meta.data)
可以使用矩陣數(shù)據(jù)、Seurat或SingleCellExperiment 對(duì)象中創(chuàng)建CellChat對(duì)象。如果是Seurat或SingleCellExperiment 對(duì)象,meta信息會(huì)默認(rèn)使用meta.data(當(dāng)然也可以指定),通過(guò) group.by 定義分組。
這里直接使用seurat的對(duì)象sce2進(jìn)行創(chuàng)建CellChat對(duì)象
cellchat <- createCellChat(object = sce2,
meta = sce2@meta.data,
group.by = "celltype")
cellchat
Create a CellChat object from a Seurat object
The `data` slot in the default assay is used. The default assay is RNA
Set cell identities for the new CellChat object
The cell groups used for CellChat analysis are Epi Myeloid Fibroblast T Endo un
根據(jù)分析數(shù)據(jù)的物種,可選CellChatDB.human, 或者 CellChatDB.mouse 。通過(guò)showDatabaseCategory函數(shù)可以查看該數(shù)據(jù)庫(kù)的情況
CellChatDB <- CellChatDB.human
showDatabaseCategory(CellChatDB)
# use a subset of CellChatDB for cell-cell communication analysis
CellChatDB.use <- subsetDB(CellChatDB, search = "Secreted Signaling")
# set the used database in the object
cellchat@DB <- CellChatDB.use
人的數(shù)據(jù)包括61.8%的旁分泌/自分泌信號(hào)互作、21.7%的細(xì)胞外基質(zhì)(ECM)受體互作和16.5%的細(xì)胞-細(xì)胞通訊互作。
注1:如果想用全部的用于cellchat分析,不進(jìn)行subsetDB,直接指定cellchat@DB <- CellChatDB 即可。
注2:如果你有關(guān)心的配受體對(duì) 且 不在該數(shù)據(jù)庫(kù)中,也可以自行添加上。大概步驟就是下載對(duì)應(yīng)的csv(數(shù)據(jù)庫(kù)),在對(duì)應(yīng)的列上添加上你的配受體對(duì)信息,保存后重新讀取新的csv即可,詳細(xì)見(jiàn)https://htmlpreview.github.io/?https://github.com/sqjin/CellChat/blob/master/tutorial/Update-CellChatDB.html。
可以使用subsetData選擇進(jìn)行cellchat的子集,注意使用全集的話也要subsetData一下。
# This step is necessary even if using the whole database
cellchat <- subsetData(cellchat)
# do parallel ,根據(jù)配置設(shè)置
future::plan("multiprocess", workers = 1)
#識(shí)別過(guò)表達(dá)基因
cellchat <- identifyOverExpressedGenes(cellchat)
#識(shí)別過(guò)表達(dá)配體受體對(duì)
cellchat <- identifyOverExpressedInteractions(cellchat)
#project gene expression data onto PPI (Optional: when running it, USER should set `raw.use = FALSE` in the function `computeCommunProb()` in order to use the projected data)
cellchat <- projectData(cellchat, PPI.human)
cellchat@data.project[1:4,1:4]
# K16733_AAACATACTCGTTT-1 K16733_AAAGCAGAACGTTG-1 K16733_AAAGCAGACTGAGT-1 K16733_AAAGGCCTGCTCCT-1
#TNFRSF18 0.0000000 0.000000000 0.000000e+00 0.000000000
#TNFRSF4 0.0000000 0.000000000 0.000000e+00 0.177007949
#TNFRSF14 0.9381181 0.001323893 1.852638e-05 0.002543824
#TNFRSF25 0.0000000 0.000000000 0.000000e+00 0.000000000
projectData函數(shù)將配體受體對(duì)的表達(dá)值投射到PPI上為可選項(xiàng),做了該步驟的話可以在data.project中查看結(jié)果。
二 推斷 cell-cell communication network
前面數(shù)據(jù)和配體受體庫(kù)準(zhǔn)備好之后,就可以根據(jù)表達(dá)值推斷細(xì)胞類型之間的互作了。
使用表達(dá)值推測(cè)細(xì)胞互作的概率,該步驟相對(duì)較耗時(shí)一些。
cellchat <- computeCommunProb(cellchat, raw.use = TRUE, population.size = TRUE)
# Filter out the cell-cell communication if there are only few number of cells in certain cell groups
cellchat <- filterCommunication(cellchat, min.cells = 10)
注1:raw.use = TRUE 表示使用raw數(shù)據(jù),而不使用上一步projectData后的結(jié)果。
注2:在假設(shè)細(xì)胞數(shù)較多的群 往往比 細(xì)胞數(shù)較少的群發(fā)送更強(qiáng)的信號(hào)的前提下,當(dāng)population.size = TRUE時(shí)候,CellChat可以在概率計(jì)算中考慮每個(gè)細(xì)胞群中細(xì)胞比例的影響。
根據(jù)需求保存結(jié)果,默認(rèn)保存全部結(jié)果(推薦),設(shè)置slot.name = "netP" 保存顯著的結(jié)果,指定sources.use和targets.use則能獲取指定配體受體方向的結(jié)果,signaling獲取指定signaling的結(jié)果。
#all the inferred cell-cell communications at the level of ligands/receptors
df.net <- subsetCommunication(cellchat)
write.csv(df.net, "cell-cell_communications.all.csv")
#access the the inferred communications at the level of signaling pathways
df.net1 <- subsetCommunication(cellchat,slot.name = "netP")
#gives the inferred cell-cell communications sending from cell groups 1 and 2 to cell groups 4 and 5.
levels(cellchat@idents)
df.net2 <- subsetCommunication(cellchat, sources.use = c("Epi"), targets.use = c("Fibroblast" ,"T"))
#gives the inferred cell-cell communications mediated by signaling WNT and TGFb.
df.net3 <- subsetCommunication(cellchat, signaling = c("CCL", "TGFb"))
使用computeCommunProbPathway計(jì)算每個(gè)信號(hào)通路的所有配體-受體相互作用的通信結(jié)果,結(jié)存存放在net 和 netP中 。
然后使用aggregateNet計(jì)算細(xì)胞類型間整合的細(xì)胞通訊結(jié)果。
#計(jì)算每個(gè)信號(hào)通路相關(guān)的所有配體-受體相互作用的通信結(jié)果
cellchat <- computeCommunProbPathway(cellchat)
#計(jì)算整合的細(xì)胞類型之間通信結(jié)果
cellchat <- aggregateNet(cellchat)
net中會(huì)有count 和 weight 兩個(gè)維度,可以選擇性可視化。
三 CellChat 可視化
groupSize <- as.numeric(table(cellchat@idents))
par(mfrow = c(1,2), xpd=TRUE)
netVisual_circle(cellchat@net$count, vertex.weight = groupSize,
weight.scale = T, label.edge= F, title.name = "Number of interactions")
netVisual_circle(cellchat@net$weight, vertex.weight = groupSize,
weight.scale = T, label.edge= F, title.name = "Interaction weights/strength")
根據(jù)celltype的個(gè)數(shù),靈活調(diào)整mfrow = c(2,3) 參數(shù) 。像繪制count維度的,只需要修改下 mat <- cellchat@net$count 即可 。
mat <- cellchat@net$weight
par(mfrow = c(2,3), xpd=TRUE)
for (i in 1:nrow(mat)) {
mat2 <- matrix(0, nrow = nrow(mat), ncol = ncol(mat), dimnames = dimnames(mat))
mat2[i, ] <- mat[i, ]
netVisual_circle(mat2, vertex.weight = groupSize, weight.scale = T, edge.weight.max = max(mat), title.name = rownames(mat)[i])
}
首先根據(jù)cellchat@netP$pathways展示當(dāng)前有哪些通路結(jié)果,選擇感興趣的進(jìn)行展示,此處示例展示TGFb通路。levels(cellchat@idents) 查看當(dāng)前的celltype順序,然后可以通過(guò)vertex.receiver指定target 的細(xì)胞類型。
繪制層級(jí)圖的話 ,需要指定layout為hierarchy ,當(dāng)前版本默認(rèn)下出來(lái)的是circle圖。
cellchat@netP$pathways
pathways.show <- c("TGFb")
levels(cellchat@idents)
#[1] "Epi" "Myeloid" "Fibroblast" "T" "Endo" "un"
vertex.receiver = c(1,2,4,5)
netVisual_aggregate(cellchat, signaling = pathways.show,
vertex.receiver = vertex.receiver,layout = "hierarchy")
左圖中間的Target是vertex.receiver選定的細(xì)胞類型,右圖是除vertex.receiver選中之外的另外的細(xì)胞類型。
#Chord diagram
par(mfrow=c(1,1))
netVisual_aggregate(cellchat, signaling = pathways.show, layout = "chord")
#Heatmap
par(mfrow=c(1,1))
netVisual_heatmap(cellchat, signaling = pathways.show, color.heatmap = "Reds")
注:繪制熱圖的話,需要使用netVisual_heatmap函數(shù)
繪制指定受體-配體細(xì)胞類型中的全部配體受體結(jié)果的氣泡圖,通過(guò)sources.use 和 targets.use指定。
#指定受體-配體細(xì)胞類型
netVisual_bubble(cellchat, sources.use = c(3,5),
targets.use = c(1,2,4,6), remove.isolate = FALSE)
同時(shí)通過(guò)signaling指定展示通路
#指定TGFb和SPP1兩個(gè)信號(hào)通路
netVisual_bubble(cellchat, sources.use = c(3,5), targets.use = c(1,2,4,6),
signaling = c("TGFb","SPP1"), remove.isolate = FALSE)
## Plot the signaling gene expression distribution
p1 = plotGeneExpression(cellchat, signaling = "SPP1")
p1
p2 = plotGeneExpression(cellchat, signaling = "SPP1", type = "dot")
更多的可視化展示方式詳見(jiàn)官網(wǎng):Inference and analysis of cell-cell communication using CellChat (htmlpreview.github.io) 。
◆ ◆ ◆ ◆ ◆
精心整理(含圖PLUS版)|R語(yǔ)言生信分析,可視化(R統(tǒng)計(jì),ggplot2繪圖,生信圖形可視化匯總)
聯(lián)系客服