【cellchat】Inference and analysis of cell-cell communication-基础篇,一个condition

时间:2024-10-07 07:29:07

cellchat需要两个输入:基因表达矩阵 + cell label。表达矩阵行为基因列为细胞,标准化+log。cell label为dataframe,行名为细胞,第一列为cell label.

从seurat v3 object中提取cell chat 所需要的两个输入文件:

  1. <- GetAssayData(seurat_object, assay = "RNA", slot = "data") # normalized data matrix
  2. labels <- Idents(seurat_object)
  3. meta <- (group = labels, = names(labels)) # create a dataframe of the cell labels
  1. library(CellChat)
  2. library(patchwork)
  3. options(stringsAsFactors = FALSE)

 

  • part I: data input and preprocessing, initialization of the cellchat object 

(1)load data

  1. # Here we load a scRNA-seq data matrix and its associated cell meta data
  2. #load(url("/files/25950872"))
  3. # This is a combined data from two biological conditions: normal and diseases
  4. load("/Users/suoqinjin/Documents/CellChat/tutorial/data_humanSkin_CellChat.rda")
  5. = data_humanSkin$data # normalized data matrix
  6. meta = data_humanSkin$meta # a dataframe with rownames containing cell mata data
  7. = rownames(meta)[meta$condition == "LS"] # extract the cell names from disease data
  8. # Prepare input data for CelChat analysis
  9. = [, ]
  10. meta = meta[, ]
  11. # meta = (labels = meta$labels[], = colnames()) # manually create a dataframe consisting of the cell labels
  12. unique(meta$labels) # check the cell labels
  13. #> [1] Inflam. FIB FBN1+ FIB APOE+ FIB COL11A1+ FIB cDC2
  14. #> [6] LC Inflam. DC cDC1 CD40LG+ TC Inflam. TC
  15. #> [11] TC NKT
  16. #> 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

  1. CellChatDB <- # use if running on mouse data
  2. showDatabaseCategory(CellChatDB)
  3. # Show the structure of the database
  4. dplyr::glimpse(CellChatDB$interaction)
  5. # use a subset of CellChatDB for cell-cell communication analysis
  6. <- subsetDB(CellChatDB, search = "Secreted Signaling") # use Secreted Signaling
  7. # use all CellChatDB for cell-cell communication analysis
  8. # <- CellChatDB # simply use the default CellChatDB
  9. # set the used database in the object
  10. cellchat@DB <-

 (4)preprocessing the gene expression data

  1. # subset the expression data of signaling genes for saving computation cost
  2. cellchat <- subsetData(cellchat) # This step is necessary even if using the whole database
  3. future::plan("multiprocess", workers = 4) # do parallel
  4. cellchat <- identifyOverExpressedGenes(cellchat)
  5. cellchat <- identifyOverExpressedInteractions(cellchat)
  6. # project gene expression data onto PPI network (optional)
  7. 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 

  1. cellchat <- computeCommunProb(cellchat)
  2. # Filter out the cell-cell communication if there are only few number of cells in certain cell groups
  3. 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.

  1. groupSize <- (table(cellchat@idents))
  2. par(mfrow = c(1,2), xpd=TRUE)
  3. netVisual_circle(cellchat@net$count, = groupSize, = T, = F, = "Number of interactions")
  4. netVisual_circle(cellchat@net$weight, = groupSize, = T, = F, = "Interaction weights/strength")

 可视化从每种细胞类型发出的

  1. mat <- cellchat@net$weight
  2. par(mfrow = c(3,4), xpd=TRUE)
  3. for (i in 1:nrow(mat)) {
  4. mat2 <- matrix(0, nrow = nrow(mat), ncol = ncol(mat), dimnames = dimnames(mat))
  5. mat2[i, ] <- mat[i, ]
  6. netVisual_circle(mat2, = groupSize, = T, = max(mat), = rownames(mat)[i])
  7. }

 

  •  part III : visualization of the communication network

(1)visualize each signaling pathway 

所有显著的通讯通路都可以通过cellchat@netP$pathways查看

  1. <- c("CXCL")
  2. # Hierarchy plot
  3. # 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
  4. = seq(1,4) # a numeric vector.
  5. netVisual_aggregate(cellchat, signaling = , = )

 

  1. # Circle plot
  2. par(mfrow=c(1,1))
  3. netVisual_aggregate(cellchat, signaling = , layout = "circle")

  1. # Chord diagram
  2. par(mfrow=c(1,1))
  3. netVisual_aggregate(cellchat, signaling = , layout = "chord")
  4. #> Note: The first link end is drawn out of sector 'Inflam. FIB'.

  1. # Heatmap
  2. par(mfrow=c(1,1))
  3. 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.

  1. <- extractEnrichedLR(cellchat, signaling = , = FALSE)
  2. <- [1,] # show one ligand-receptor pair
  3. # Hierarchy plot
  4. = seq(1,4) # a numeric vector
  5. netVisual_individual(cellchat, signaling = , = , = )

  1. # Circle plot
  2. netVisual_individual(cellchat, signaling = , = , layout = "circle")

  1. # Chord diagram
  2. netVisual_individual(cellchat, signaling = , = , layout = "chord")

 (3)visualize cell communications by multiple L-R pairs or pathways

气泡图

  1. # show all the significant interactions (L-R pairs) from some cell groups (defined by '') to other cell groups (defined by '')
  2. netVisual_bubble(cellchat, = 4, = c(5:11), = FALSE)

 

  1. # show all the significant interactions (L-R pairs) associated with certain signaling pathways
  2. netVisual_bubble(cellchat, = 4, = c(5:11), signaling = c("CCL","CXCL"), = FALSE)

  1. # show all the significant interactions (L-R pairs) based on user's input (defined by ``)
  2. <- extractEnrichedLR(cellchat, signaling = c("CCL","CXCL","FGF"))
  3. netVisual_bubble(cellchat, = c(3,4), = c(5:8), = , = TRUE)

 和弦图(和bubble图一样,既可以展示用户指定的target与sender之间的通讯关系,也可以展示用户指定的pair和pathway)

  1. # show all the significant interactions (L-R pairs) from some cell groups (defined by '') to other cell groups (defined by '')
  2. # show all the interactions sending from
  3. netVisual_chord_gene(cellchat, = 4, = c(5:11), = 0.5, = 30)

  1. # show all the interactions received by
  2. netVisual_chord_gene(cellchat, = c(1,2,3,4), = 8, = 15)

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

  1. # show all the significant signaling pathways from some cell groups (defined by '') to other cell groups (defined by '')
  2. 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

  1. #来自seurat的wrapper功能
  2. 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)

  1. # Compute the network centrality scores
  2. cellchat <- netAnalysis_computeCentrality(cellchat, = "netP")
  3. # the slot 'netP' means the inferred intercellular communication network of signaling pathways
  4. # Visualize the computed centrality scores using heatmap, allowing ready identification of major signaling roles of cell groups
  5. netAnalysis_signalingRole_network(cellchat, signaling = , width = 8, height = 2.5, = 10)

 Visualize the dominant senders (sources) and receivers (targets) in a 2D space

  1. # Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
  2. gg1 <- netAnalysis_signalingRole_scatter(cellchat)
  3. # Signaling role analysis on the cell-cell communication networks of interest
  4. gg2 <- netAnalysis_signalingRole_scatter(cellchat, signaling = c("CXCL", "CCL"))
  5. gg1 + gg2

 identify signals contributing most to the incoming and outgoing signalings of certain cell types

  1. # Signaling role analysis on the aggregated cell-cell communication network from all signaling pathways
  2. ht1 <- netAnalysis_signalingRole_heatmap(cellchat, pattern = "outgoing")
  3. ht2 <- netAnalysis_signalingRole_heatmap(cellchat, pattern = "incoming")
  4. ht1 + ht2

  1. # Signaling role analysis on the cell-cell communication networks of interest
  2. 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

  1. library(NMF)
  2. library(ggalluvial)
  3. selectK(cellchat, pattern = "outgoing")

 k选择3

  1. nPatterns = 3
  2. cellchat <- identifyCommunicationPatterns(cellchat, pattern = "outgoing", k = nPatterns)

 

  1. # river plot
  2. netAnalysis_river(cellchat, pattern = "outgoing")

 

  1. # dot plot
  2. 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

  1. cellchat <- computeNetSimilarity(cellchat, type = "functional")
  2. cellchat <- netEmbedding(cellchat, type = "functional")
  3. cellchat <- netClustering(cellchat, type = "functional")
  4. # Visualization in 2D-space
  5. netVisual_embedding(cellchat, type = "functional", = 3.5)
  6. # netVisual_embeddingZoomIn(cellchat, type = "functional", nCol = 2)

 identify signaling groups based on structure similarity

  1. cellchat <- computeNetSimilarity(cellchat, type = "structural")
  2. cellchat <- netEmbedding(cellchat, type = "structural")
  3. cellchat <- netClustering(cellchat, type = "structural")
  4. # Visualization in 2D-space
  5. 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