cellchat需要两个输入:基因表达矩阵 + cell label。表达矩阵行为基因列为细胞,标准化+log。cell label为dataframe,行名为细胞,第一列为cell label.
从seurat v3 object中提取cell chat 所需要的两个输入文件:
-
<- GetAssayData(seurat_object, assay = "RNA", slot = "data") # normalized data matrix
-
labels <- Idents(seurat_object)
-
meta <- (group = labels, = names(labels)) # create a dataframe of the cell labels
-
library(CellChat)
-
library(patchwork)
-
options(stringsAsFactors = FALSE)
- part I: data input and preprocessing, initialization of the cellchat object
(1)load data
-
# Here we load a scRNA-seq data matrix and its associated cell meta data
-
#load(url("/files/25950872"))
-
# This is a combined data from two biological conditions: normal and diseases
-
-
load("/Users/suoqinjin/Documents/CellChat/tutorial/data_humanSkin_CellChat.rda")
-
-
= data_humanSkin$data # normalized data matrix
-
-
meta = data_humanSkin$meta # a dataframe with rownames containing cell mata data
-
-
= rownames(meta)[meta$condition == "LS"] # extract the cell names from disease data
-
-
# Prepare input data for CelChat analysis
-
= [, ]
-
meta = meta[, ]
-
# meta = (labels = meta$labels[], = colnames()) # manually create a dataframe consisting of the cell labels
-
-
unique(meta$labels) # check the cell labels
-
#> [1] Inflam. FIB FBN1+ FIB APOE+ FIB COL11A1+ FIB cDC2
-
#> [6] LC Inflam. DC cDC1 CD40LG+ TC Inflam. TC
-
#> [11] TC NKT
-
#> 12 Levels: APOE+ FIB FBN1+ FIB COL11A1+ FIB Inflam. FIB cDC1 cDC2 ... NKT
(2)create a cellchat object
cellchat <- createCellChat(object = , meta = meta, = "labels")
(3)set the ligand-receptor interaction database
-
CellChatDB <- # use if running on mouse data
-
showDatabaseCategory(CellChatDB)
-
-
# Show the structure of the database
-
dplyr::glimpse(CellChatDB$interaction)
-
-
# use a subset of CellChatDB for cell-cell communication analysis
-
<- subsetDB(CellChatDB, search = "Secreted Signaling") # use Secreted Signaling
-
-
# use all CellChatDB for cell-cell communication analysis
-
# <- CellChatDB # simply use the default CellChatDB
-
-
# set the used database in the object
-
cellchat@DB <-
(4)preprocessing the gene expression data
-
# subset the expression data of signaling genes for saving computation cost
-
cellchat <- subsetData(cellchat) # This step is necessary even if using the whole database
-
future::plan("multiprocess", workers = 4) # do parallel
-
-
cellchat <- identifyOverExpressedGenes(cellchat)
-
cellchat <- identifyOverExpressedInteractions(cellchat)
-
# project gene expression data onto PPI network (optional)
-
cellchat <- projectData(cellchat, )
- Part II: Inference of cell-cell communication network
在核心功能computeCommuProb中,可以设置不同的阈值。默认为trimean(25%),也可以设置成10%、5%等。这个阈值什么意思?当某个cell group中表达某个pair的细胞比例低于此值时,他们的平均表达量就都是零(不会出现在结果里),调低阈值能发现更多通讯,但相应的噪音也更大。调整方法:type = "truncatedMean", trim = 0.1
(1)compute the communication probability and infer the celluar communication network
-
cellchat <- computeCommunProb(cellchat)
-
-
# Filter out the cell-cell communication if there are only few number of cells in certain cell groups
-
cellchat <- filterCommunication(cellchat, = 10)
(2) extract the infered celluar communication network as a dataframe
We provide a function subsetCommunication
to easily access the inferred cell-cell communications of interest. For example,
-
<- subsetCommunication(cellchat)
returns a data frame consisting of all the inferred cell-cell communications at the level of ligands/receptors. Set= "netP"
to access the the inferred communications at the level of signaling pathways -
<- subsetCommunication(cellchat, = c(1,2), = c(4,5))
gives the inferred cell-cell communications sending from cell groups 1 and 2 to cell groups 4 and 5. -
<- subsetCommunication(cellchat, signaling = c("WNT", "TGFb"))
gives the inferred cell-cell communications mediated by signaling WNT and TGFb.
(3)infer the communication network at a signaling pathway level
注:前面以pair为单位的结果存储在“net” slot, 而pathway推断结果在“netP”slot.
cellchat <- computeCommunProbPathway(cellchat)
(4)calculate the aggregated communication network
USER can also calculate the aggregated network among a subset of cell groups by setting and
.
cellchat <- aggregateNet(cellchat)
两种可视化思路:一种线条粗细反应数量,一种反映weights.
-
groupSize <- (table(cellchat@idents))
-
par(mfrow = c(1,2), xpd=TRUE)
-
-
netVisual_circle(cellchat@net$count, = groupSize, = T, = F, = "Number of interactions")
-
-
netVisual_circle(cellchat@net$weight, = groupSize, = T, = F, = "Interaction weights/strength")
可视化从每种细胞类型发出的
-
mat <- cellchat@net$weight
-
par(mfrow = c(3,4), 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, = groupSize, = T, = max(mat), = rownames(mat)[i])
-
}
- part III : visualization of the communication network
(1)visualize each signaling pathway
所有显著的通讯通路都可以通过cellchat@netP$pathways查看
-
<- c("CXCL")
-
-
# Hierarchy plot
-
# Here we define `` so that the left portion of the hierarchy plot shows signaling to fibroblast and the right portion shows signaling to immune cells
-
-
= seq(1,4) # a numeric vector.
-
netVisual_aggregate(cellchat, signaling = , = )
-
# Circle plot
-
par(mfrow=c(1,1))
-
netVisual_aggregate(cellchat, signaling = , layout = "circle")
-
# Chord diagram
-
par(mfrow=c(1,1))
-
netVisual_aggregate(cellchat, signaling = , layout = "chord")
-
#> Note: The first link end is drawn out of sector 'Inflam. FIB'.
-
# Heatmap
-
par(mfrow=c(1,1))
-
netVisual_heatmap(cellchat, signaling = , = "Reds")
(2)Compute the contribution of each ligand-receptor pair to the overall signaling pathway and visualize cell-cell communication mediated by a single ligand-receptor pair
netAnalysis_contribution(cellchat, signaling = )
We provide a function extractEnrichedLR
to extract all the significant interactions (L-R pairs) and related signaling genes for a given signaling pathway.
-
<- extractEnrichedLR(cellchat, signaling = , = FALSE)
-
<- [1,] # show one ligand-receptor pair
-
-
# Hierarchy plot
-
= seq(1,4) # a numeric vector
-
netVisual_individual(cellchat, signaling = , = , = )
-
# Circle plot
-
netVisual_individual(cellchat, signaling = , = , layout = "circle")
-
# Chord diagram
-
netVisual_individual(cellchat, signaling = , = , layout = "chord")
(3)visualize cell communications by multiple L-R pairs or pathways
气泡图
-
# show all the significant interactions (L-R pairs) from some cell groups (defined by '') to other cell groups (defined by '')
-
-
netVisual_bubble(cellchat, = 4, = c(5:11), = FALSE)
-
# show all the significant interactions (L-R pairs) associated with certain signaling pathways
-
-
netVisual_bubble(cellchat, = 4, = c(5:11), signaling = c("CCL","CXCL"), = FALSE)
-
# show all the significant interactions (L-R pairs) based on user's input (defined by ``)
-
-
<- extractEnrichedLR(cellchat, signaling = c("CCL","CXCL","FGF"))
-
netVisual_bubble(cellchat, = c(3,4), = c(5:8), = , = TRUE)
和弦图(和bubble图一样,既可以展示用户指定的target与sender之间的通讯关系,也可以展示用户指定的pair和pathway)
-
# show all the significant interactions (L-R pairs) from some cell groups (defined by '') to other cell groups (defined by '')
-
-
# show all the interactions sending from
-
netVisual_chord_gene(cellchat, = 4, = c(5:11), = 0.5, = 30)
-
# show all the interactions received by
-
-
netVisual_chord_gene(cellchat, = c(1,2,3,4), = 8, = 15)
-
# show all the significant interactions (L-R pairs) associated with certain signaling pathways
-
-
netVisual_chord_gene(cellchat, = c(1,2,3,4), = c(5:11), signaling = c("CCL","CXCL"), = 8)
-
# show all the significant signaling pathways from some cell groups (defined by '') to other cell groups (defined by '')
-
-
netVisual_chord_gene(cellchat, = c(1,2,3,4), = c(5:11), = "netP", = 10)
(4)plot the signaling gene expression distrobution by dot or violin plots
-
#来自seurat的wrapper功能
-
-
plotGeneExpression(cellchat, signaling = "CXCL")
- part IV : systems analysis of cell-cell communication network
这是什么意思呢?
a. 根据已经构建好的通讯网络,发现其中的major sources, targets, influencers, mediators.
b. 对某些细胞类型,预测其关键的incoming and outgoing signals,包括coordinated responses among different cell types
c. group signaling pathways
d. delineate conserved and context-specific signaling pathways
(1)identify signaling roles of cell groups as well as the major contributing signaling (dominant senders and receivers)
-
# Compute the network centrality scores
-
-
cellchat <- netAnalysis_computeCentrality(cellchat, = "netP")
-
# the slot 'netP' means the inferred intercellular communication network of signaling pathways
-
-
-
# Visualize the computed centrality scores using heatmap, allowing ready identification of major signaling roles of cell groups
-
-
netAnalysis_signalingRole_network(cellchat, signaling = , width = 8, height = 2.5, = 10)
Visualize the dominant senders (sources) and receivers (targets) in a 2D space
-
# Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
-
-
gg1 <- netAnalysis_signalingRole_scatter(cellchat)
-
-
# Signaling role analysis on the cell-cell communication networks of interest
-
-
gg2 <- netAnalysis_signalingRole_scatter(cellchat, signaling = c("CXCL", "CCL"))
-
-
gg1 + gg2
identify signals contributing most to the incoming and outgoing signalings of certain cell types
-
# Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
-
-
ht1 <- netAnalysis_signalingRole_heatmap(cellchat, pattern = "outgoing")
-
ht2 <- netAnalysis_signalingRole_heatmap(cellchat, pattern = "incoming")
-
ht1 + ht2
-
# Signaling role analysis on the cell-cell communication networks of interest
-
ht <- netAnalysis_signalingRole_heatmap(cellchat, signaling = c("CXCL", "CCL"))
(2)identify global communication patterns to explore how multiple cell types and signaling pathways coordinate together
default patterns number: 5;可以用select K功能寻找最佳K值,选当曲线开始突然下降时的K。
identify outgoing communication patterns of secreting cells
-
library(NMF)
-
library(ggalluvial)
-
-
selectK(cellchat, pattern = "outgoing")
k选择3
-
nPatterns = 3
-
-
cellchat <- identifyCommunicationPatterns(cellchat, pattern = "outgoing", k = nPatterns)
-
# river plot
-
netAnalysis_river(cellchat, pattern = "outgoing")
-
# dot plot
-
netAnalysis_dot(cellchat, pattern = "outgoing")
identify incoming communication patterns of target cells功能都一样,把outgoing改成incoming就行
(3)manifold and classication learning analysis of signaling networks
可以对所有显著的signaling pathway进行grouping分析,依据通路之间的相似性,这种相似性既可以是功能上的“functional”,也可以是结构上的“structural”.
functional similarity: 主要的sender和receiver相同
structural similarity: 网络的结构相似,不考虑sender和receiver的相似性
identify signaling groups based on their functional similarity
-
cellchat <- computeNetSimilarity(cellchat, type = "functional")
-
cellchat <- netEmbedding(cellchat, type = "functional")
-
-
-
cellchat <- netClustering(cellchat, type = "functional")
-
-
# Visualization in 2D-space
-
netVisual_embedding(cellchat, type = "functional", = 3.5)
-
-
# netVisual_embeddingZoomIn(cellchat, type = "functional", nCol = 2)
identify signaling groups based on structure similarity
-
cellchat <- computeNetSimilarity(cellchat, type = "structural")
-
cellchat <- netEmbedding(cellchat, type = "structural")
-
-
cellchat <- netClustering(cellchat, type = "structural")
-
-
# Visualization in 2D-space
-
netVisual_embedding(cellchat, type = "structural", = 3.5)
netVisual_embeddingZoomIn(cellchat, type = "structural", nCol = 2)
- part V : save the cellchat object
saveRDS(cellchat, file = "cellchat_humanSkin_LS.rds")
这篇文章是关于单个dataset单个条件的,如果涉及到代表不同conditions的datasets 之间的差异分析,可以看另一个教程。
GitHub & BitBucket HTML Preview