摘要:这篇笔记概述了使用 CellChat 对单个数据集进行细胞间通信网络推断、分析和可视化的步骤。通过将其应用于来自患者病变皮肤的细胞的单细胞 RNA 测序数据,展示了 CellChat 的多样化功能。


CellChat
需要细胞的基因表达数据作为用户输入,并通过将基因表达与信号配体、受体及其辅因子之间的相互作用的先验知识相结合,来模拟细胞间通信的概率。

在推断出细胞间通信网络后, CellChat
提供了进一步的数据探索、分析和可视化功能。

# 加载必要的包

r
library(CellChat)
载入需要的程辑包:dplyr


载入程辑包:'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

载入需要的程辑包:igraph


载入程辑包:'igraph'

The following objects are masked from 'package:dplyr':

    as_data_frame, groups, union

The following objects are masked from 'package:stats':

    decompose, spectrum

The following object is masked from 'package:base':

    union

载入需要的程辑包:ggplot2
r
library(patchwork)
options(stringsAsFactors = FALSE)

# 数据输入与处理和 CellChat 对象的初始化

CellChat
需要两种用户输入:一种是细胞的基因表达数据,另一种是用户指定的细胞标签(即基于标签的模式)或单细胞数据的低维表示(即无标签模式)。对于后者, CellChat
会根据细胞间在低维空间或伪时间轨迹空间的距离,通过构建共享邻居图自动对细胞进行分组。

# 加载数据

对于基因表达数据矩阵,基因应该在行中并带有行名,细胞应该在列中并带有列名。标准化数据(例如,库大小标准化然后用伪计数为 1 进行对数转换)是
CellChat 分析所需的输入。如果用户提供计数数据,我们提供了一个
normalizeData
函数来解决库大小问题然后进行对数转换。对于细胞群组信息,需要一个带有行名的数据框作为
CellChat 的输入。

r
ptm = Sys.time()
# Here we load a scRNA-seq data matrix and its associated cell meta data
# This is a combined data from two biological conditions: normal and diseases
load("data_humanSkin_CellChat.rda")
data.input = data_humanSkin$data # normalized data matrix
meta = data_humanSkin$meta # a dataframe with rownames containing cell mata data
cell.use = rownames(meta)[meta$condition == "LS"] # extract the cell names from disease data
# Prepare input data for CelChat analysis
data.input = data.input[, cell.use]
meta = meta[cell.use, ]
# meta = data.frame(labels = meta$labels[cell.use], row.names = colnames(data.input)) # 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

# 创建一个 CellChat 对象

用户可以从数据矩阵、 Seurat SingleCellExperiment
对象创建一个新的 CellChat 对象。如果输入是一个 Seurat
SingleCellExperiment
对象,则默认使用对象中的元数据,并且用户必须提供 group.by
来定义细胞群组。例如,对于 Seurat
对象中默认的细胞标识, group.by = "ident"

注意:如果用户加载之前计算的 CellChat 对象(版本 <
0.5.0),请通过 updateCellChat 更新对象。

r
cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels")
[1] "Create a CellChat object from a data matrix"
Set cell identities for the new CellChat object 
The cell groups used for CellChat analysis are  APOE+ FIB, FBN1+ FIB, COL11A1+ FIB, Inflam. FIB, cDC1, cDC2, LC, Inflam. DC, TC, Inflam. TC, CD40LG+ TC, NKT 

# 将细胞信息添加到对象的元数据(可选)

如果在创建 CellChat 对象时没有添加细胞元信息,用户也可以稍后使用
addMeta 添加它,并使用 setIdent 设置默认的细胞标识。

r
cellchat <- addMeta(cellchat, meta = meta)
cellchat <- setIdent(cellchat, ident.use = "labels") # set "labels" as default cell identity
levels(cellchat@idents) # show factor levels of the cell labels
 [1] "APOE+ FIB"    "FBN1+ FIB"    "COL11A1+ FIB" "Inflam. FIB"  "cDC1"        
 [6] "cDC2"         "LC"           "Inflam. DC"   "TC"           "Inflam. TC"  
[11] "CD40LG+ TC"   "NKT"         
r
groupSize <- as.numeric(table(cellchat@idents)) # number of cells in each cell group

# 设置配体 - 受体相互作用数据库

在用户使用 CellChat
推断细胞间通信之前,他们需要设置配体 - 受体相互作用数据库并识别过表达的配体或受体。

我们的数据库 CellChatDB
是一个手工整理的的包含人类和小鼠的文献支持配体 - 受体相互作用的数据库。 CellChatDB
v2
包含约 3,300 个经过验证的分子相互作用,包括约 40% 的分泌自分泌 / 旁分泌信号相互作用、约 17% 的细胞外基质(ECM)- 受体相互作用、约 13% 的细胞 - 细胞接触相互作用以及约 30% 的非蛋白质信号。与
CellChatDB v1 相比, CellChatDB v2
增加了 1000 多个蛋白质和非蛋白质相互作用,如代谢和突触信号。应该注意的是,对于在单细胞 RNA 测序中没有直接测量的与基因相关的分子, CellChat
v2
估计配体和受体的表达量,使用这些分子的关键中介物或酶,以便潜在的通过非蛋白质介导的通信。关键的,突触信号相互作用只能在推断神经元 - 神经元通信时使用。

用户可以通过添加自己策划的配体 - 受体对来更新 CellChatDB

r
CellChatDB <- CellChatDB.human # use CellChatDB.mouse if running on mouse data
showDatabaseCategory(CellChatDB)

r
# Show the structure of the database
dplyr::glimpse(CellChatDB$interaction)
Rows: 3,249
Columns: 28
$ interaction_name         <chr> "TGFB1_TGFBR1_TGFBR2", "TGFB2_TGFBR1_TGFBR2",…
$ pathway_name             <chr> "TGFb", "TGFb", "TGFb", "TGFb", "TGFb", "TGFb…
$ ligand                   <chr> "TGFB1", "TGFB2", "TGFB3", "TGFB1", "TGFB1", …
$ receptor                 <chr> "TGFbR1_R2", "TGFbR1_R2", "TGFbR1_R2", "ACVR1…
$ agonist                  <chr> "TGFb agonist", "TGFb agonist", "TGFb agonist…
$ antagonist               <chr> "TGFb antagonist", "TGFb antagonist", "TGFb a…
$ co_A_receptor            <chr> "", "", "", "", "", "", "", "", "", "", "", "…
$ co_I_receptor            <chr> "TGFb inhibition receptor", "TGFb inhibition …
$ evidence                 <chr> "KEGG: hsa04350", "KEGG: hsa04350", "KEGG: hs…
$ annotation               <chr> "Secreted Signaling", "Secreted Signaling", "…
$ interaction_name_2       <chr> "TGFB1 - (TGFBR1+TGFBR2)", "TGFB2 - (TGFBR1+T…
$ is_neurotransmitter      <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FAL…
$ ligand.symbol            <chr> "TGFB1", "TGFB2", "TGFB3", "TGFB1", "TGFB1", …
$ ligand.family            <chr> "TGF-beta", "TGF-beta", "TGF-beta", "TGF-beta…
$ ligand.location          <chr> "Extracellular matrix, Secreted, Extracellula…
$ ligand.keyword           <chr> "Disease variant, Signal, Reference proteome,…
$ ligand.secreted_type     <chr> "growth factor", "growth factor", "cytokine;g…
$ ligand.transmembrane     <lgl> FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALS…
$ receptor.symbol          <chr> "TGFBR2, TGFBR1", "TGFBR2, TGFBR1", "TGFBR2, …
$ receptor.family          <chr> "Protein kinase superfamily, TKL Ser/Thr prot…
$ receptor.location        <chr> "Cell membrane, Secreted, Membrane raft, Cell…
$ receptor.keyword         <chr> "Membrane, Secreted, Disulfide bond, Kinase, …
$ receptor.surfaceome_main <chr> "Receptors", "Receptors", "Receptors", "Recep…
$ receptor.surfaceome_sub  <chr> "Act.TGFB;Kinase", "Act.TGFB;Kinase", "Act.TG…
$ receptor.adhesome        <chr> "", "", "", "", "", "", "", "", "", "", "", "…
$ receptor.secreted_type   <chr> "", "", "", "", "", "", "", "", "", "", "", "…
$ receptor.transmembrane   <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRU…
$ version                  <chr> "CellChatDB v1", "CellChatDB v1", "CellChatDB…
r
# use a subset of CellChatDB for cell-cell communication analysis
# CellChatDB.use <- subsetDB(CellChatDB, search = "Secreted Signaling", key = "annotation") # use Secreted Signaling
# use all CellChatDB for cell-cell communication analysis
CellChatDB.use <- CellChatDB # simply use the default CellChatDB
# set the used database in the object
cellchat@DB <- CellChatDB.use

# 为细胞间通信分析预处理表达数据

为了推断特定细胞状态的通信, CellChat
识别一个细胞群组中过表达的配体或受体,然后识别过表达的配体 - 受体相互作用,如果配体或受体有过表达。

我们还提供了一个功能,将基因表达数据投影到蛋白质 - 蛋白质相互作用(PPI)网络上。具体来说,使用扩散过程根据在高信度实验验证的蛋白质 - 蛋白质网络中定义的邻居,来平滑基因的表达值。当分析浅层测序深度的单细胞数据时,这个功能很有用,因为投影减少了信号基因的 dropout 效应,特别是对于可能零表达的配体 / 受体亚单位。可能会担心这个扩散过程引入的可能的人为误差,然而,它只会引入非常弱的通信。默认情况下, CellChat
使用原始数据(即
[email protected] )而不是投影数据。要使用投影数据,用户应在运行
computeCommunProb 之前运行 projectData 函数,然后在运行
computeCommunProb 时设置 raw.use = FALSE

r
# 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("multisession", workers = 4) # do parallel
cellchat <- identifyOverExpressedGenes(cellchat)
cellchat <- identifyOverExpressedInteractions(cellchat)
execution.time = Sys.time() - ptm
print(as.numeric(execution.time, units = "secs"))
[1] 21.51956
r
#> [1] 12.42671
# 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
通过为每个相互作用分配一个概率值并进行排列测试,推断生物学上重要的细胞间通信。 CellChat
通过整合基因表达与信号配体、受体及其辅因子之间已知的相互作用,使用质量作用定律来模拟细胞间通信的概率。

推断的配体 - 受体对的数量显然取决于计算每个细胞组平均基因表达的方法。默认情况下, CellChat
使用一种称为”trimean” 的统计上稳健的平均方法,它产生的相互作用少于其他方法。然而,我们发现
CellChat
在预测更强的相互作用方面表现良好,这对于进一步缩小实验验证的相互作用非常有帮助。在
computeCommunProb
中,我们提供了一个选项,可以使用其他方法来计算平均基因表达,比如 5% 和 10% 的截断平均。值得注意的是,“trimean” 近似于 25% 的截断平均,这意味着如果一个组中表达细胞的百分比少于 25%,平均基因表达就是零。要使用 10% 截断平均,用户可以设置
type = “truncatedMean” 和 trim = 0.1。为了确定适当的 trim
值, CellChat 提供了一个函数
computeAveExpr ,它可以帮助检查感兴趣的信号基因的平均表达,例如, computeAveExpr(cellchat, features = c("CXCL12","CXCR4"), type = "truncatedMean", trim = 0.1) 。因此,如果在研究的生物过程中未预测到众所周知的信号通路,用户可以尝试用较低的
trim 值的截断平均来改变计算每个细胞组平均基因表达的方法。

当分析未分类的单细胞转录组时,在假设丰富的细胞群体倾向于发送比稀有细胞群体更强的信号的情况下, CellChat
还可以在概率计算中考虑每个细胞组中细胞比例的影响。用户可以设置
population.size = TRUE。

# 计算通信概率并推断细胞通信网络

r
ptm = Sys.time()
cellchat <- computeCommunProb(cellchat, type = "triMean")
triMean is used for calculating the average gene expression per cell group. 
[1] ">>> Run CellChat on sc/snRNA-seq data <<< [2024-01-05 19:16:03]"
[1] ">>> CellChat inference is done. Parameter values are stored in `object@options$parameter` <<< [2024-01-05 19:20:32]"

这项分析的关键参数是
type,即计算每个细胞组平均基因表达的方法。默认情况下 type =
“triMean”,产生较少但更强的相互作用。当设置 type = “truncatedMean”
时,应分配一个值给
trim,产生更多的相互作用。请查看上面详细介绍的计算每个细胞组平均基因表达的方法。

如果某些细胞组中只有很少的细胞,用户可以过滤掉细胞间通信。默认情况下,每个细胞组中细胞间通信所需的最少细胞数是 10。

r
cellchat <- filterCommunication(cellchat, min.cells = 10)

# 提取推断的细胞通信网络为数据框

我们提供了一个 subsetCommunication
函数,可以轻松访问感兴趣的推断细胞间通信。例如,

  • df.net <- subsetCommunication(cellchat)
    返回一个由所有推断的细胞间通信组成的数据框,这些通信在配体 / 受体层面上。设置
    slot.name = "netP" 来访问在信号通路层面上的推断通信。

  • df.net <- subsetCommunication(cellchat, sources.use = c(1,2), targets.use = c(4,5))
    返回从细胞组 1 和 2 发送到细胞组 4 和 5 的推断细胞间通信。

  • df.net <- subsetCommunication(cellchat, signaling = c("WNT", "TGFb"))
    返回由信号 WNT 和 TGFb 介导的推断细胞间通信。

# 在信号通路层面推断细胞间通信

CellChat
通过汇总与每个信号通路相关联的所有配体 - 受体相互作用的通信概率,来计算信号通路层面的通信概率。

注意:每个配体 - 受体对和每个信号通路的推断细胞间通信网络分别存储在 ‘net’
和 ‘netP’ 中。

r
cellchat <- computeCommunProbPathway(cellchat)

# 计算聚合的细胞间通信网络

CellChat
可以通过计算链接数量或汇总通信概率来计算聚合的细胞间通信网络。用户还可以通过设置
sources.usetargets.use 来计算一部分细胞群组之间的聚合网络。

r
cellchat <- aggregateNet(cellchat)
execution.time = Sys.time() - ptm
print(as.numeric(execution.time, units = "secs"))
[1] 274.7239

CellChat
也可以可视化聚合的细胞间通信网络。例如,使用圆形图展示任意两个细胞组之间的交互数量或总交互强度(权重)。

r
ptm = Sys.time()
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")

由于细胞间通信网络的复杂性,我们可以检查每个细胞组发送的信号。在这里,我们还控制参数
edge.weight.max ,以便我们可以比较不同网络之间的边缘权重。

r
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, vertex.weight = groupSize, weight.scale = T, edge.weight.max = max(mat), title.name = rownames(mat)[i])
}

# 细胞间通信网络的可视化

在推断出细胞间通信网络后, CellChat
提供了各种功能,用于进一步的数据探索、分析和可视化。

  • 它提供了多种方式来可视化细胞间通信网络,包括层次图、圆形图、和弦图和气泡图。

  • 它提供了一个易于使用的工具,用于提取和可视化推断网络的高阶信息。例如,它允许轻松预测细胞群体的主要信号输入和输出,以及这些群体和信号如何协同工作以实现功能。

  • 它可以使用集成的方法定量描述和比较推断的细胞间通信网络,这种方法结合了社会网络分析、模式识别和流形学习方法

# 使用层次图、圆形图或和弦图可视化每个信号通路

层次图:用户应定义
vertex.receiver ,这是一个数值向量,给出层次图左部作为目标的细胞组的索引。这个层次图由两部分组成:左侧部分显示自分泌和旁分泌信号到感兴趣的某些细胞组(即定义的
vertex.receiver ),右侧部分显示自分泌和旁分泌信号到数据集中剩余的细胞组。因此,层次图提供了一种信息丰富且直观的方式来可视化感兴趣的细胞组之间的自分泌和旁分泌通信。例如,在研究成纤维细胞和免疫细胞之间的细胞通信时,用户可以将所有成纤维细胞组定义为
vertex.receiver

和弦图 CellChat 提供了两个函数 netVisual_chord_cell
netVisual_chord_gene
来可视化不同目的和不同层次的细胞间通信。 netVisual_chord_cell
用于可视化不同细胞组之间的细胞间通信(和弦图中的每个扇区是一个细胞组), netVisual_chord_gene
用于可视化由多个配体 - 受体或信号通路介导的细胞间通信(和弦图中的每个扇区是一个配体、受体或信号通路)。

边颜色 / 权重、节点颜色 / 大小 / 形状的解释:在所有可视化图中,边的颜色与作为发送者的源保持一致,边的权重与交互强度成比例。边线越粗表示信号越强。在层次图和圆形图中,圆圈大小与每个细胞组中的细胞数量成比例。在层次图中,实心和空心圆圈分别代表源和目标。在和弦图中,内部较薄的条形颜色代表从相应的外部条形接收信号的目标。内部条形的大小与目标接收的信号强度成比例。这种内部条形有助于解释复杂的和弦图。请注意,对于一些细胞组,存在一些没有任何和弦的内部条形,请忽略它,因为这是
circlize 包尚未解决的问题。

在不同层次上可视化细胞间通信:可以使用 netVisual_aggregate
可视化推断出的信号通路通信网络,使用 netVisual_individual
可视化与该信号通路相关的个别配体 - 受体对的推断通信网络。

这里我们以一个信号通路的输入为例。所有显示显著通信的信号通路可以通过
cellchat@netP$pathways 访问。

r
pathways.show <- c("CXCL") 
# Hierarchy plot
# Here we define `vertex.receive` so that the left portion of the hierarchy plot shows signaling to fibroblast and the right portion shows signaling to immune cells 
vertex.receiver = seq(1,4) # a numeric vector. 
netVisual_aggregate(cellchat, signaling = pathways.show,  vertex.receiver = vertex.receiver)
# Circle plot
par(mfrow=c(1,1))
netVisual_aggregate(cellchat, signaling = pathways.show, layout = "circle")

r
# Chord diagram
par(mfrow=c(1,1))
netVisual_aggregate(cellchat, signaling = pathways.show, layout = "chord")

r
# Heatmap
par(mfrow=c(1,1))
netVisual_heatmap(cellchat, signaling = pathways.show, color.heatmap = "Reds")
Do heatmap based on a single object 

r
#> Do heatmap based on a single object

对于和弦图, CellChat 有一个独立的函数 netVisual_chord_cell
来灵活地通过调整 circlize
包中的不同参数来可视化信号网络。例如,我们可以定义一个命名的字符向量
group 来创建多组和弦图,例如,将细胞簇分组到不同的细胞类型。

r
# Chord diagram
group.cellType <- c(rep("FIB", 4), rep("DC", 4), rep("TC", 4)) # grouping cell clusters into fibroblast, DC and TC cells
names(group.cellType) <- levels(cellchat@idents)
netVisual_chord_cell(cellchat, signaling = pathways.show, group = group.cellType, title.name = paste0(pathways.show, " signaling network"))
Plot the aggregated cell-cell communication network at the signaling pathway level

r
#> Plot the aggregated cell-cell communication network at the signaling pathway level

# 计算每个配体 - 受体对对整个信号通路的贡献并可视化

r
netAnalysis_contribution(cellchat, signaling = pathways.show)

我们也可以可视化由单个配体 - 受体对介导的细胞间通信。我们提供了一个函数
extractEnrichedLR
来提取给定信号通路的所有显著相互作用(L-R 对)和相关的信号基因。

r
pairLR.CXCL <- extractEnrichedLR(cellchat, signaling = pathways.show, geneLR.return = FALSE)
LR.show <- pairLR.CXCL[1,] # show one ligand-receptor pair
# Hierarchy plot
vertex.receiver = seq(1,4) # a numeric vector
netVisual_individual(cellchat, signaling = pathways.show,  pairLR.use = LR.show, vertex.receiver = vertex.receiver)
[[1]]
r
#> [[1]]
# Circle plot
netVisual_individual(cellchat, signaling = pathways.show, pairLR.use = LR.show, layout = "circle")

# 自动保存所有推断网络的图表以便快速探索

在实际使用中,用户可以使用 ‘for ... loop’ 自动保存所有推断网络,以便使用
netVisual 进行快速探索。 netVisual 支持 svg、png 和 pdf
格式的输出。

r
# Access all the signaling pathways showing significant communications
pathways.show.all <- cellchat@netP$pathways
# check the order of cell identity to set suitable vertex.receiver
levels(cellchat@idents)
 [1] "APOE+ FIB"    "FBN1+ FIB"    "COL11A1+ FIB" "Inflam. FIB"  "cDC1"        
 [6] "cDC2"         "LC"           "Inflam. DC"   "TC"           "Inflam. TC"  
[11] "CD40LG+ TC"   "NKT"         
r
vertex.receiver = seq(1,4)
#for (i in 1:length(pathways.show.all)) {
  # Visualize communication network associated with both signaling pathway and individual L-R pairs
  #netVisual(cellchat, signaling = pathways.show.all[i], vertex.receiver = vertex.receiver, layout = "hierarchy")
  # Compute and visualize the contribution of each ligand-receptor pair to the overall signaling pathway
  #gg <- netAnalysis_contribution(cellchat, signaling = pathways.show.all[i])
  #ggsave(filename=paste0(pathways.show.all[i], "_L-R_contribution.pdf"), plot=gg, width = 3, height = 2, units = 'in', dpi = 300)
#}

# 可视化由多个配体 - 受体或信号通路介导的细胞间通信

# 气泡图

我们还可以使用 netVisual_bubble
展示一些细胞组到其他细胞组的所有显著相互作用(L-R 对)。

r
# show all the significant interactions (L-R pairs) from some cell groups (defined by 'sources.use') to other cell groups (defined by 'targets.use')
netVisual_bubble(cellchat, sources.use = 4, targets.use = c(5:11), remove.isolate = FALSE)
Comparing communications on a single object 

r
# show all the significant interactions (L-R pairs) associated with certain signaling pathways
netVisual_bubble(cellchat, sources.use = 4, targets.use = c(5:11), signaling = c("CCL","CXCL"), remove.isolate = FALSE)
Comparing communications on a single object 

r
# show all the significant interactions (L-R pairs) based on user's input (defined by `pairLR.use`)
pairLR.use <- extractEnrichedLR(cellchat, signaling = c("CCL","CXCL","FGF"))
netVisual_bubble(cellchat, sources.use = c(3,4), targets.use = c(5:8), pairLR.use = pairLR.use, remove.isolate = TRUE)
Comparing communications on a single object 

# 和弦图

类似于气泡图, CellChat 提供了一个函数 netVisual_chord_gene
用于绘制和弦图来

  • 展示一些细胞组到其他细胞组的所有相互作用(L-R 对或信号通路)。两个特殊情况:一个是展示从一个细胞组发送的所有相互作用,另一个是展示由一个细胞组接收的所有相互作用。

  • 展示由用户输入的相互作用或由用户定义的某些信号通路。

r
# show all the significant interactions (L-R pairs) from some cell groups (defined by 'sources.use') to other cell groups (defined by 'targets.use')
# show all the interactions sending from Inflam.FIB
netVisual_chord_gene(cellchat, sources.use = 4, targets.use = c(5:11), lab.cex = 0.5,legend.pos.y = 30)

r
# show all the interactions received by Inflam.DC
netVisual_chord_gene(cellchat, sources.use = c(1,2,3,4), targets.use = 8, legend.pos.x = 15)

r
# show all the significant interactions (L-R pairs) associated with certain signaling pathways
netVisual_chord_gene(cellchat, sources.use = c(1,2,3,4), targets.use = c(5:11), signaling = c("CCL","CXCL"),legend.pos.x = 8)

r
# show all the significant signaling pathways from some cell groups (defined by 'sources.use') to other cell groups (defined by 'targets.use')
netVisual_chord_gene(cellchat, sources.use = c(1,2,3,4), targets.use = c(5:11), slot.name = "netP", legend.pos.x = 10)

# 使用小提琴 / 点图绘制信号基因表达分布

我们可以使用一个 Seurat 包装函数 plotGeneExpression
绘制与 L-R 对或信号通路相关的信号基因的基因表达分布。

r
plotGeneExpression(cellchat, signaling = "CXCL")
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
which was just loaded, were retired in October 2023.
Please refer to R-spatial evolution reports for details, especially
https://r-spatial.org/r/2023/05/15/evolution4.html.
It may be desirable to make the sf package available;
package maintainers should consider adding sf to Suggests:.

Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.

默认情况下, plotGeneExpression
只显示与推断的显著通信相关的信号基因的表达。用户可以通过以下方式显示与一个信号通路相关的所有信号基因的表达:

r
plotGeneExpression(cellchat, signaling = "CXCL", enriched.only = FALSE)
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.

r
execution.time = Sys.time() - ptm

# 识别细胞组的信号角色(例如,主要发送者、接收者)以及主要贡献信号

CellChat
允许通过计算每个细胞组的几种网络中心性度量,轻松识别细胞间通信网络中的主要发送者、接收者、中介者和影响者。具体来说,我们使用了加权有向网络中的度量,包括出度、入度、流中心性和信息中心性,分别识别细胞间通信的主要发送者、接收者、中介者和影响者。在一个以计算的通信概率为权重的加权有向网络中,出度(计算为一个细胞组发出的通信概率之和)和入度(计算为一个细胞组接收的通信概率之和),可分别用于识别信号网络的主要细胞发送者和接收者。

# 计算和可视化网络中心性分数

r
ptm = Sys.time()
# Compute the network centrality scores
cellchat <- netAnalysis_computeCentrality(cellchat, slot.name = "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 = pathways.show, width = 8, height = 2.5, font.size = 10)

# 在二维空间中可视化主要发送者(源)和接收者(目标)

我们还提供了另一种直观的方法,使用散点图在二维空间中可视化主要发送者(源)和接收者(目标)。

r
# Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
gg1 <- netAnalysis_signalingRole_scatter(cellchat)
Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
r
#> Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
# Signaling role analysis on the cell-cell communication networks of interest
gg2 <- netAnalysis_signalingRole_scatter(cellchat, signaling = c("CXCL", "CCL"))
Signaling role analysis on the cell-cell communication network from user's input
r
#> Signaling role analysis on the cell-cell communication network from user's input
gg1 + gg2

# 识别对某些细胞组的外发或接收信号贡献最大的信号

我们也可以解答哪些信号对某些细胞组的外发或接收信号贡献最大的问题。

r
# 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

r
# Signaling role analysis on the cell-cell communication networks of interest
ht <- netAnalysis_signalingRole_heatmap(cellchat, signaling = c("CXCL", "CCL"))

# 识别全局通信模式以探索多个细胞类型和信号通路如何协同工作

除了探索单个通路的详细通信外,一个重要的问题是多个细胞群组和信号通路如何协调工作。 CellChat
采用模式识别方法来识别全局通信模式。

随着模式数量的增加,可能会出现冗余模式,使得解释通信模式变得困难。我们默认选择五种模式。通常情况下,模式数量大于 2 时生物学上是有意义的。此外,我们还提供了一个
selectK 函数来推断模式的数量,这基于 NMF R
包中实现的两个指标,包括 Cophenetic 和
Silhouette。这两个指标基于共识矩阵的层次聚类来测量特定数量模式的稳定性。对于一系列的模式数量,适当的模式数量是
Cophenetic 和 Silhouette 值开始突然下降的地方。

# 识别和可视化分泌细胞的外发通信模式

外发模式揭示了发送细胞(即作为信号源的细胞)如何相互协调,以及它们如何与某些信号通路协调来驱动通信。

为了直观显示潜在模式与细胞群组以及配体 - 受体对或信号通路的关联,我们使用了河流(alluvial)图。我们首先将
W 的每行和 H 的每列标准化为 [0,1],然后如果 W 和 H
中的元素小于 0.5 就将它们设置为零。这样的阈值化允许揭示与每个推断模式最富集的细胞群组和信号通路,即每个细胞群组或信号通路只与一个推断模式相关。这些阈值化的矩阵
W 和 H 用作创建河流图的输入。

为了直接关联细胞群组及其富集的信号通路,如果 W 和 H
中的元素小于 1/R(R 是潜在模式的数量),我们将它们设置为零。通过使用不那么严格的阈值,可能获得与每个细胞群组相关的更多富集信号通路。使用每个细胞群组对每个信号通路的贡献得分(通过乘以
W 和 H
计算得到),我们构建了一个点图,其中点的大小与贡献得分成比例,以显示细胞群组与其富集的信号通路之间的关联。用户也可以减小参数
cutoff 来显示与每个细胞群组相关的更多富集信号通路。

加载进行通信模式分析所需的包。

r
library(NMF)
载入需要的程辑包:registry

载入需要的程辑包:rngtools

载入需要的程辑包:cluster

NMF - BioConductor layer [OK] | Shared memory capabilities [NO: bigmemory] | Cores 2/2

  To enable shared memory capabilities, try: install.extras('
NMF
')


载入程辑包:'NMF'

The following objects are masked from 'package:igraph':

    algorithm, compare
r
library(ggalluvial)
r
selectK(cellchat, pattern = "outgoing")

r
# Both Cophenetic and Silhouette values begin to drop suddenly when the number of outgoing patterns is 3.
nPatterns = 3
cellchat <- identifyCommunicationPatterns(cellchat, pattern = "outgoing", k = nPatterns)

r
# river plot
netAnalysis_river(cellchat, pattern = "outgoing")
Please make sure you have load `library(ggalluvial)` when running this function

r
#> Please make sure you have load `library(ggalluvial)` when running this function
r
# dot plot
netAnalysis_dot(cellchat, pattern = "outgoing")

# 识别和可视化目标细胞的接收通信模式

接收模式显示目标细胞(即作为信号接收者的细胞)如何相互协调,以及它们如何与某些信号通路协调来响应接收的信号。

r
selectK(cellchat, pattern = "incoming")

r
nPatterns = 3
cellchat <- identifyCommunicationPatterns(cellchat, pattern = "incoming", k = nPatterns)

r
# river plot
netAnalysis_river(cellchat, pattern = "incoming")
Please make sure you have load `library(ggalluvial)` when running this function

r
#> Please make sure you have load `library(ggalluvial)` when running this function
r
# dot plot
netAnalysis_dot(cellchat, pattern = "incoming")

# 流形和信号网络的分类学习分析

此外, CellChat
能够量化所有显著信号通路之间的相似性,然后根据它们的细胞通信网络相似性对它们进行分组。分组可以基于功能相似性或结构相似性进行。

功能相似性:高度的功能相似性表明主要的发送者和接收者是相似的,这可以解释为两个信号通路或两个配体 - 受体对展示了相似和 / 或冗余的角色。功能相似性分析需要两个数据集之间有相同的细胞群体组成。

结构相似性:结构相似性被用来比较它们的信号网络结构,不考虑发送者和接收者的相似性。

根据功能相似性识别信号群组。

r
cellchat <- computeNetSimilarity(cellchat, type = "functional")
cellchat <- netEmbedding(cellchat, type = "functional")
Manifold learning of the signaling networks for a single dataset 
r
#> Manifold learning of the signaling networks for a single dataset
cellchat <- netClustering(cellchat, type = "functional")
Classification learning of the signaling networks for a single dataset 
r
#> Classification learning of the signaling networks for a single dataset
# Visualization in 2D-space
netVisual_embedding(cellchat, type = "functional", label.size = 3.5)

r
netVisual_embeddingZoomIn(cellchat, type = "functional", nCol = 2)

根据结构相似性识别信号群组。

r
cellchat <- computeNetSimilarity(cellchat, type = "structural")
cellchat <- netEmbedding(cellchat, type = "structural")
Manifold learning of the signaling networks for a single dataset 
r
#> Manifold learning of the signaling networks for a single dataset
cellchat <- netClustering(cellchat, type = "structural")
Classification learning of the signaling networks for a single dataset 
r
#> Classification learning of the signaling networks for a single dataset
# Visualization in 2D-space
netVisual_embedding(cellchat, type = "structural", label.size = 3.5)

r
netVisual_embeddingZoomIn(cellchat, type = "structural", nCol = 2)

# 保存 CellChat 对象

r
saveRDS(cellchat, file = "cellchat_humanSkin_LS.rds")
r
sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 21.2

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

locale:
 [1] LC_CTYPE=zh_CN.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=zh_CN.UTF-8        LC_COLLATE=zh_CN.UTF-8    
 [5] LC_MONETARY=zh_CN.UTF-8    LC_MESSAGES=zh_CN.UTF-8   
 [7] LC_PAPER=zh_CN.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=zh_CN.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] doParallel_1.0.17   iterators_1.0.14    foreach_1.5.2      
 [4] ggalluvial_0.12.5   NMF_0.26            cluster_2.1.2      
 [7] rngtools_1.5.2      registry_0.5-1      patchwork_1.1.3    
[10] CellChat_2.1.1      Biobase_2.54.0      BiocGenerics_0.40.0
[13] ggplot2_3.4.4       igraph_1.5.1        dplyr_1.1.3        

loaded via a namespace (and not attached):
  [1] utf8_1.2.3              spatstat.explore_3.2-3  reticulate_1.34.0      
  [4] tidyselect_1.2.0        htmlwidgets_1.6.2       grid_4.1.2             
  [7] BiocParallel_1.28.3     Rtsne_0.16              munsell_0.5.0          
 [10] ragg_1.2.5              codetools_0.2-18        ica_1.0-3              
 [13] future_1.33.0           miniUI_0.1.1.1          withr_2.5.1            
 [16] spatstat.random_3.1-6   colorspace_2.1-0        progressr_0.14.0       
 [19] knitr_1.45              rstudioapi_0.15.0       Seurat_4.9.9.9067      
 [22] stats4_4.1.2            ROCR_1.0-11             ggsignif_0.6.4         
 [25] tensor_1.5              listenv_0.9.0           labeling_0.4.3         
 [28] polyclip_1.10-6         farver_2.1.1            coda_0.19-4            
 [31] parallelly_1.36.0       vctrs_0.6.3             generics_0.1.3         
 [34] xfun_0.40               R6_2.5.1                ggbeeswarm_0.7.2       
 [37] clue_0.3-65             spatstat.utils_3.0-3    cachem_1.0.8           
 [40] promises_1.2.1          scales_1.2.1            beeswarm_0.4.0         
 [43] gtable_0.3.4            globals_0.16.2          goftest_1.2-3          
 [46] spam_2.9-1              rlang_1.1.1             systemfonts_1.0.4      
 [49] GlobalOptions_0.1.2     splines_4.1.2           rstatix_0.7.2          
 [52] lazyeval_0.2.2          spatstat.geom_3.2-5     broom_1.0.5            
 [55] BiocManager_1.30.22     yaml_2.3.7              reshape2_1.4.4         
 [58] abind_1.4-5             ggnetwork_0.5.12        backports_1.4.1        
 [61] httpuv_1.6.11           tools_4.1.2             BPCells_0.1.0          
 [64] gridBase_0.4-7          statnet.common_4.9.0    ellipsis_0.3.2         
 [67] jquerylib_0.1.4         RColorBrewer_1.1-3      ggridges_0.5.4         
 [70] Rcpp_1.0.11             plyr_1.8.9              purrr_1.0.2            
 [73] ggpubr_0.6.0            deldir_1.0-9            pbapply_1.7-2          
 [76] GetoptLong_1.0.5        cowplot_1.1.1           S4Vectors_0.32.4       
 [79] zoo_1.8-12              SeuratObject_4.9.9.9091 ggrepel_0.9.3          
 [82] magrittr_2.0.3          data.table_1.14.8       RSpectra_0.16-1        
 [85] sna_2.7-2               magick_2.8.0            scattermore_1.2        
 [88] circlize_0.4.15         lmtest_0.9-40           RANN_2.6.1             
 [91] fitdistrplus_1.1-11     matrixStats_1.0.0       mime_0.12              
 [94] evaluate_0.22           xtable_1.8-4            fastDummies_1.7.3      
 [97] IRanges_2.28.0          gridExtra_2.3           shape_1.4.6            
[100] compiler_4.1.2          tibble_3.2.1            KernSmooth_2.23-20     
[103] crayon_1.5.2            htmltools_0.5.6         later_1.3.1            
[106] tidyr_1.3.0             ComplexHeatmap_2.10.0   MASS_7.3-55            
[109] Matrix_1.6-1.1          car_3.1-2               cli_3.6.1              
[112] dotCall64_1.0-2         pkgconfig_2.0.3         sp_2.1-0               
[115] plotly_4.10.2           spatstat.sparse_3.0-2   svglite_2.1.3          
[118] vipor_0.4.5             bslib_0.5.1             stringr_1.5.0          
[121] digest_0.6.33           sctransform_0.4.0       RcppAnnoy_0.0.21       
[124] spatstat.data_3.0-1     rmarkdown_2.25          leiden_0.4.3           
[127] uwot_0.1.16             shiny_1.7.5             rjson_0.2.21           
[130] nlme_3.1-155            lifecycle_1.0.3         jsonlite_1.8.7         
[133] carData_3.0-5           network_1.18.2          BiocNeighbors_1.12.0   
[136] viridisLite_0.4.2       fansi_1.0.4             pillar_1.9.0           
[139] lattice_0.20-45         ggrastr_1.0.2           fastmap_1.1.1          
[142] httr_1.4.7              survival_3.2-13         glue_1.6.2             
[145] FNN_1.1.3.2             png_0.1-8               presto_1.0.0           
[148] stringi_1.7.12          sass_0.4.7              textshaping_0.3.6      
[151] RcppHNSW_0.5.0          tidyverse_2.0.0         irlba_2.3.5.1          
[154] future.apply_1.11.0    
更新于