美文网首页
单细胞数据分析笔记2-2: 细胞通讯分析(CellChat)

单细胞数据分析笔记2-2: 细胞通讯分析(CellChat)

作者: 小程的学习笔记 | 来源:发表于2024-03-20 15:45 被阅读0次

    3. CellChat

    CellChat,用于根据单细胞数据对细胞间通信进行推理、分析和可视化。包含文献支持的多个物种中的配体-受体相互作用,从而全面概括已知的分子相互作用机制,包括配体-受体复合物和辅助因子的多亚基结构。

    目前CellChat提供了多种图形来对结果进行可视化,包括但不限于:
    1)Hierarchical plot (层次聚类图)
    2)Chord diagram (和弦图)
    3)Circle plot (环状图)
    4)Heatmap(热图)
    5)Bubble plot (气泡图)

    CellChat-1

    3.1 数据读入

    # 安装并加载所需的R包
    # devtools::install_github('satijalab/seurat-data')
    # devtools::install_github("sqjin/CellChat")
    library(Seurat)
    library(SeuratData)
    library(tidyverse)
    library(CellChat)
    library(NMF)
    library(ggalluvial)
    library(patchwork)
    library(ggplot2)
    library(svglite)
    
    head(scRNA_harmony) # 需包含后续所需分组(这里是细胞类型)
    ##                           orig.ident nCount_RNA nFeature_RNA percent.mt percent.HB RNA_snn_res.0.8 seurat_clusters RNA_snn_res.0.6 celltype  Group
    ## ACAAGCTTACGGAGGTG        N11        500          244   0.600000          0               4               5               5   plasma Normal
    ## ATAGGCTGCTGCACGCT        N11        500          258   1.200000          0               4              11              11   plasma Normal
    ## ATTCAGGGCTATTCACG        N11        500          242   1.200000          0               0               0               0   plasma Normal
    ## CTTTCAAATGCATGAAT        N11        500          272   1.600000          0               0               0               0   plasma Normal
    ## GGATGTTTACACGATAC        N11        500          261   3.600000          0               4              11              11   plasma Normal
    ## TCCTCCCGCTTTGCAGT        N11        500          256   1.400000          0               0               0               0   plasma Normal
    ## TCCTCTTATGGATATAC        N11        500          260   1.400000          0               4               5               5   plasma Normal
    ## AAACGAAGCTGAATTGA        N11        501          259   1.397206          0               0               0               0   plasma Normal
    ## ATTCCATATGGTAGCCG        N11        501          260   1.996008          0               4               5               5   plasma Normal
    ## CACTGAACGACTTGAAC        N11        501          281   1.397206          0               0               5               5   plasma Normal
    

    3.2 创建CellChat对象

    可以使用矩阵数据、Seurat或SingleCellExperiment 对象中创建CellChat对象

    cellchat <- createCellChat(scRNA_harmony@assays$RNA@data, meta = scRNA_harmony
    @meta.data, group.by = "celltype")
    summary(cellchat)
    ## [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  plasma Macrophage Monocytes memory B CD8 TEM Naive B 
    
    levels(cellchat@idents)
    ## [1] "plasma"     "Macrophage" "Monocytes"  "memory B"   "CD8 TEM"    "Naive B" 
    
    groupSize <- as.numeric(table(cellchat@idents))  #查看每种细胞类型有多少个细胞
    groupSize
    ## [1] 70560  9686  1929   809 12584  3230
    

    3.3 设置参考数据库

    根据分析数据的物种,可选CellChatDB.human, 或者 CellChatDB.mouse

    CellChatDB <- CellChatDB.human # 小鼠是CellChatDB.mouse
    str(CellChatDB) # 查看数据库信息,包含interaction、complex、cofactor和geneInfo
    
    showDatabaseCategory(CellChatDB)
    
    # 使用所有的进行分析
    cellchat@DB <- CellChatDB
    
    # 使用 CellChatDB 的子集进行细胞间通信分析
    # CellChatDB.use <- subsetDB(CellChatDB, search = "Secreted Signaling") 
    # 在对象中设置使用的数据库
    # cellchat@DB <- CellChatDB.use 
    
    CellChat-2

    ꔷ 人的数据包括61.8%的旁分泌/自分泌信号互作、21.7%的细胞外基质(ECM)-受体互作和16.5%的细胞-细胞通讯互作。48%的相互作用涉及杂聚分子复合物,52%的相互作用从最近的文献中搜集的。

    3.4 表达数据的预处理

    可以使用subsetData选择进行cellchat的子集,注意使用全集的话也要subsetData一下

    cellchat <- subsetData(cellchat) 
    # do parallel ,根据配置设置
    future::plan("multiprocess", workers = 15) 
    
    # 识别过表达基因(相当于Seurat的FindMarkers,找每个细胞群中高表达的配受体基因)
    cellchat <- identifyOverExpressedGenes(cellchat)
    # 基于CellChatDB数据库,识别过表达的配体-受体相互作对
    cellchat <- identifyOverExpressedInteractions(cellchat)
    
    # 找到配体受体关系后,projectData将配体受体对的表达值投射到PPI上,来对@data.signaling中的表达值进行校正。结果保存在@data.project
    cellchat <- projectData(cellchat, PPI.human)
    cellchat@data.project[1:4,1:4]
    ##                  ACAAGCTTACGGAGGTG         ATAGGCTGCTGCACGCT         ATTCAGGGCTATTCACG         CTTTCAAATGCATGAAT
    ## AGRN                  0.000000e+00              0.0000000000               0.000000000              0.000000e+00
    ## TNFRSF18              0.000000e+00              0.0000000000               0.000000000              0.000000e+00
    ## TNFRSF4               0.000000e+00              0.0000000000               0.000000000              0.000000e+00
    ## TNFRSF14              1.087736e-05              0.0001582008               0.005097043              6.333395e-05
    ## TNFRSF25              0.000000e+00              0.0000000000               0.000000000              0.000000e+00
    ## UTS2                  0.000000e+00              0.0000000000               0.000000000              0.000000e+00
    

    3.5 推断细胞通讯网路

    # 1.基于配体-受体水平推断细胞通讯网络
    # raw.use = TRUE 表示使用raw数据,而不使用上一步projectData后的结果
    # 在假设细胞数较多的群 往往比 细胞数较少的群发送更强的信号的前提下,当population.size = TRUE时候,CellChat可以在概率计算中考虑每个细胞群中细胞比例的影响
    cellchat <- computeCommunProb(cellchat, raw.use = FALSE, population.size = TRUE) 
    # 过滤
    cellchat <- filterCommunication(cellchat, min.cells = 10) 
    # 配体/受体水平上所有推断的细胞间通讯
    df.net <- subsetCommunication(cellchat)
    write.csv(df.net, "net_lr.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("plasma"), targets.use = c("CD8 TEM" ,"Naive B")) 
    # gives the inferred cell-cell communications mediated by signaling WNT and TGFb.
    df.net3 <- subsetCommunication(cellchat, signaling = c("CCL", "TGFb"))
    
    # 2.基于信号通路水平推断细胞通讯网络
    cellchat <- computeCommunProbPathway(cellchat)
    # 计算整合的细胞类型之间通信结果
    cellchat <- aggregateNet(cellchat)
    df.netp <- subsetCommunication(cellchat, slot.name = "netP")
    write.csv(df.netp, "net_pathway.csv")
    

    3.6 可视化

    3.6.1 celltype之间通讯结果可视化

    1)使用netVisual_circle显示celltype之间的通讯次数(左)或总通讯强度(右)

    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")
    
    CellChat-3

    2)分别展示

    mat <- cellchat@net$weight # 若绘制count维度的,只需要修改下 mat <- cellchat@net$count 即可
    par(mfrow = c(2,3), xpd=TRUE) # 根据celltype的个数,灵活调整mfrow = c(2,3) 参数 
    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, 
                       arrow.width = 2,
                       arrow.size = 0.6,
                       edge.weight.max = max(mat), 
                       title.name = rownames(mat)[I])
    }
    
    CellChat-4
    3.6.2 单个信号通路可视化

    首先根据cellchat@netP$pathways展示当前有哪些通路结果,选择感兴趣的进行展示
    1)层级图(绘制层级图的话 ,需要指定layout为hierarchy ,当前版本默认下出来的是circle图)

    cellchat@netP$pathways
    pathways.show <- c("MHC-II")  
    
    levels(cellchat@idents)   
    ## [1] "plasma"     "Macrophage" "Monocytes"  "memory B"   "CD8 TEM"    "Naive B" 
    vertex.receiver = c(1, 2, 4, 5) 
    
    netVisual_aggregate(cellchat, signaling = pathways.show,  
                        vertex.receiver = vertex.receiver, layout = "hierarchy")
    
    CellChat-5

    ꔷ 左侧部分展示的是以plasma,Macrophage,CD8 TEM和Naive B作为信号接收细胞群的MHC-II信号通路,其中左半部分自分泌相关信号,这里的所谓自分泌信号就是指这几类细胞类群自己释放的信号作用于自己这几类细胞,相应的右半部分就是展示的旁分泌信号,也就是其它类的细胞所释放的信号作用于这几类细胞。

    ꔷ 右侧部分展示是以除了plasma,Macrophage,CD8 TEM和Naive B以外的其它细胞群作为信号接收细胞群的MHC-II信号通路,只不过此时左右半部分的信息反过来了:左半部分旁分泌信号,右半部分自分泌信号。

    2)和弦图 和 热图

    # 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")
    
    CellChat-6
    3.6.3 配体-受体层级的可视化(计算各个ligand-receptor pair对信号通路的贡献)

    1)层次图

    # 计算配体受体对选定信号通路的贡献值(在这里就是查看哪条信号通路对MHC-II贡献最大)
    netAnalysis_contribution(cellchat, signaling = "MHC-II")
    
    # 提取对MHC-II有贡献的所有配体受体
    pairLR.MHC_II <- extractEnrichedLR(cellchat, signaling = "MHC-II", geneLR.return = F)
    
    CellChat-7
    # 提取对这个通路贡献最大的配体受体对来展示(也可以选择其他的配体受体对)
    LR.show <- pairLR.MHC_II[1,]
    vertex.receiver = c(1, 2, 4, 5) 
    netVisual_individual(cellchat, signaling = "MHC-II", pairLR.use = LR.show, vertex.receiver = vertex.receiver, layout = "hierarchy")
    
    CellChat-8

    2)网络图

    netVisual_individual(cellchat, signaling = pathways.show, pairLR.use = LR.show, layout = 'circle)
    

    3)和弦图

    netVisual_individual(cellchat, signaling = pathways.show, pairLR.use = LR.show, layout = 'chord)
    

    4)自动保存所有推断网络的图,以便快速探索

    # 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)
    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)
    }
    
    3.6.4 多个配体-受体介导的细胞互作关系可视化
    1. 配体受体气泡图可视化
    levels(cellchat@idents)
    ## [1] "plasma"     "Macrophage" "Monocytes"  "memory B"   "CD8 TEM"    "Naive B" 
    
    # 查看指定细胞间的相互作用
    netVisual_bubble(
      cellchat,
      sources.use = c(1, 5, 6),
      targets.use = c(2, 3, 4),
      remove.isolate = FALSE
    )
    
    # 查看指定细胞间的指定信号通路
    netVisual_bubble(
      cellchat,
      sources.use = c(1, 5, 6),
      targets.use = c(2, 3, 4),
      signaling = "MHC-II",
      remove.isolate = FALSE
    )
    
    # 查看指定受体配体对在所有细胞间的作用
    netVisual_bubble(
      cellchat,
      # sources.use = c(1, 5, 6),
      # targets.use = c(2, 3, 4),
      pairLR.use = extractEnrichedLR(cellchat, signaling = "MHC-II"),
      remove.isolate = FALSE
    )
    
    CellChat-9
    3.6.5 某条信号通路的配-受体基因在细胞群中的表达情况
    plotGeneExpression(cellchat, 
                       signaling = "MHC-II", 
                       type = "dot", # 点图 type = c("violin", "dot", "bar")
                       color= "Reds") 
    
    CellChat-10

    相关文章

      网友评论

          本文标题:单细胞数据分析笔记2-2: 细胞通讯分析(CellChat)

          本文链接:https://www.haomeiwen.com/subject/duqttjtx.html