web123456

④-1 Single Cell Learning-cellchat Single Data Code Supplement

catalogs

1, Data input and processing

①Load packets and data

②CellChat Input Data Preparation

③ Construct CellChat object

④Data preprocessing

2, Cellular communication prediction

① Calculate the cellular communication probability

②Table of extracted ligand receptor-to-cell communication results

③ Extraction of cellular communication tables at the level of signaling pathways

④ Visualization of cellular interactions

1) Network diagram of the number of ligand receptors between cell subpopulations

2) Ligand-receptor probability/intensity network diagram between cellular subpopulations

3) The probability of ligand-receptor communication for each cell subpopulation is shown separately

(Edit 4) Quantity and intensity chord plots merged

3, Analysis of cellular communication at the level of signaling pathways

4, Analysis of cellular communication at the level of signaling pathway-associated ligand-receptor pairs

5, Visualization of cellular communication mediated at the level of multiple ligand-receptor pairs/signaling pathways

① Designated signaling pathways

② Demonstration of the distribution of expression of genes involved in the target signaling pathway in various cell subpopulations

③Bubble chart

1, Data input and processing
①Load packets and data

Official Learning:focuslyj/CellChat - Code Cloud - Open Source China ()

The data provided here should be counts data

  1. rm(list=ls())
  2. library(CellChat)
  3. library(patchwork)
  4. library(ggplot2)
  5. library(Seurat)
  6. library(ggalluvial)# Plotting Sankey diagrams
  7. library(expm)
  8. library(sna)
  9. library(NMF)
  10. options(stringsAsFactors = FALSE)## input data is not automatically converted to factors (to prevent data formatting errors)
  11. load("data_humanSkin.Rdata") #data loaded: here is the count data data
CellChat Input Data Preparation
  1. #Normalized gene expression matrix and cell grouping information files required
  2. # Different input formats are handled differently
  3. data.input = data_humanSkin$data#Normalized gene expression matrix and cell grouping information files required
  4. meta = data_humanSkin$meta
  5. data.input[1:6,1:3] #Expressioncount
  6. head(meta);table(meta$condition) #with normal(NL) and disequations(LS)
  7. cell.use = rownames(meta)[meta$condition == 'LS'] #Name of the cell from which the LS was extracted
  8. data.input = data.input[, cell.use]# Extract the LS expression matrix
  9. meta = meta[cell.use, ]#Extract LS cell information
  10. identical(rownames(meta),colnames(data.input)) #Check that matrix column names and grouped file line names are identical
  11. unique(meta$labels) #check cell subpopulation label type
Building CellChat Objects
  1. # Next build the CellChat object
  2. cellchat <- createCellChat(object = data.input, # Support for normalized expression matrices, Seurat objects, and SingleCellExperiment objects
  3. meta = meta, #meta file
  4. group.by = 'labels') #cell classification columns in meta
  5. #cellchat <- addMeta(cellchat, meta = meta)#Create CellChat object without cellmeta information when adding the information
  6. cellchat <- setIdent(cellchat, ident.use = 'labels') #Set the labels to the default order in which they are displayed
  7. levels(cellchat@idents) #look at celltype and factor order
  8. table(cellchat@idents) # of cells in each celltype
  9. # Setting up the ligand receptor database (CellChatDB).
  10. CellChatDB <- #() ()
  11. showDatabaseCategory(CellChatDB) #View a pie chart describing the composition of this database
  12. dplyr::glimpse(CellChatDB$interaction) #view database structure
  13. #Directly use the full CellChatDB library for cell communication analysis:
  14. ##CellChatDB.use <- CellChatDB # simply use the default CellChatDB
  15. #Select a specific subset of the database for cellular communication analysis.
  16. CellChatDB.use <- subsetDB(CellChatDB,
  17. search = 'Secreted Signaling') #selectableSecreted Signaling、ECM-ReceptormaybeCell-Cell Contact
  18. cellchat@DB <- CellChatDB.use# Add database to CellChat object (DB)
Data preprocessing
  1. #Data preprocessing; expression matrix subsetting of signaling genes saves computational costs
  2. cellchat <- subsetData(cellchat) # mandatory step, take a subset of the expression matrix of the signaling genes in the previous step, assign to cellchat@data.Signaling
  3. #future::plan('multiprocess', workers = 4) # do parallel (parallel computation can be unchecked)
  4. #Identification of overexpressed signaling genes associated with each cell subpopulation: determined based on the proportion of cells expressing the gene, differential ploidy and p-value.
  5. cellchat <- identifyOverExpressedGenes(cellchat,
  6. = TRUE, # Only positive markers are returned
  7. = 0, #Cell Proportion Threshold
  8. = 0, # Multiples of variance
  9. = 0.05) #P-Value
  10. #Calculated results assigned to cellchat@var.features:
  11. head(cellchat@var.features$features) # Overexpressed signaling gene name
  12. head(cellchat@var.features$features.info) # Table of results of variance calculations
  13. # Recognize overexpressed gene ligand-receptor interactions:
  14. cellchat <- identifyOverExpressedInteractions(cellchat)
  15. head(cellchat@LR$LRsig) # Calculated result assignment position
  16. # Map gene expression data to PPI networks (skippable):
  17. cellchat <- projectData(cellchat, PPI.human) #Return results:cellchat@data.project
2, Cellular communication prediction
① Calculate the cellular communication probability
  1. #CellComm predictions ##############################################
  2. cellchat <- computeCommunProb(cellchat, raw.use = TRUE) #Return result:cellchat@options$parameter
  3. ## Use raw expression data by default (cellchat@data.Signaling), if you want to use the PPI correction data from the previous step, set raw.use = TALSE
  4. cellchat <- filterCommunication(cellchat, = 10) #Cell Communication Filtering (set the minimum number of cells in each subpopulation required for intercellular communication)
Extracted Ligand Receptor to Cell Communication Results Table
  1. # Extracted ligand receptor to cellular communication results table:
  2. <- subsetCommunication(cellchat, = 'net')
  3. head() #Get a table of ligand-receptor-to-cell communication results
  4. # or visit other interested/Specific cellular communication results:
  5. 1 <- subsetCommunication(cellchat,
  6. sources.use = c('LC'),
  7. targets.use = c('FBN1+ FIB')) # Access to a subset of specific cell pairs
  8. head(1)
  9. 2 <- subsetCommunication(cellchat, signaling = c('CD40')) # Access to specific subsets of signaling pathways
  10. head(2)
Extracting cellular communication tables at the level of signaling pathways

Extraction of ligand receptor-to-cell communication results Table:subsetCommunication function

Extraction of cellular communication tables at the level of signaling pathways:computeCommunProbPathway function

  1. # Extract cellular communication tables at the level of signaling pathways:
  2. cellchat <- computeCommunProbPathway(cellchat) #Calculate the probability of communication at the level of the signaling pathway
  3. df.netp <- subsetCommunication(cellchat, = 'netP') #Get signaling pathway level cellchat table
  4. head()
Visualization of cellular interactions
1) Network diagram of the number of ligand receptors between cell subpopulations
  1. cellchat <- aggregateNet(cellchat)# Calculate the number and probability strength of communication between cell pairs
  2. # Number and probability of interactions between different cell subpopulations/Intensity visualization:
  3. groupSize <- as.numeric(table(cellchat@idents))## Network map of ligand receptor numbers between cell subpopulations:
  4. par(mfrow = c(1,1), xpd = TRUE)
  5. netVisual_circle(cellchat@net$count,
  6. = groupSize,
  7. = T,
  8. = F,
  9. = 'Number of interactions')

Cell Communication| Basic Analysis Tutorial_Beep_bilibili

2) Ligand-receptor probability/intensity network diagram between cellular subpopulations
  1. ## Probability/intensity network plot of ligand receptors between cell subpopulations:
  2. par(mfrow = c(1,1), xpd = TRUE)
  3. netVisual_circle(cellchat@net$weight,
  4. = groupSize,
  5. = T,
  6. = F,
  7. = 'Interaction weights/strength')

3) The probability of ligand-receptor communication for each cell subpopulation is shown separately

Here you need to pay attention to the scope of the R drawing board, you can save the previous drawing and devoff before making a drawing

  1. ## Examine the strength of interactions signals in individual cell subpopulations; each cell is shown individually ###
  2. mat <- cellchat@net$weight
  3. par(mfrow = c(3,4), xpd = TRUE)
  4. for (i in 1:nrow(mat)) {
  5. mat2 <- matrix(0, nrow = nrow(mat), ncol = ncol(mat), dimnames = dimnames(mat))
  6. mat2[i, ] <- mat[i, ]
  7. netVisual_circle(mat2, = groupSize, = T, = max(mat), = rownames(mat)[i])
  8. }
4) Quantity and intensity chord plots merged
  1. # Quantity and intensity chord plots merged
  2. par(mfrow = c(1,2), xpd = TRUE)
  3. netVisual_circle(cellchat@net$count,
  4. = groupSize,
  5. = T,
  6. = F,
  7. = 'Number of interactions')
  8. netVisual_circle(cellchat@net$weight,
  9. = groupSize,
  10. = T,
  11. = F,
  12. = 'Interaction weights/strength')

  1. # Save the cellchat object:
  2. save(cellchat, groupSize, file = c('humanSkin_CellChat.Rdata'))

3, Analysis of cellular communication at the level of signaling pathways
  1. cellchat@netP$pathways##Signaling pathways to view
  2. <- c('GALECTIN')## to'GALECTIN'Signaling pathway demonstration as an example
  3. # Hierarchy plotting
  4. levels(cellchat@idents)# View cell subpopulations and factor order:
  5. #Select the subpopulation of cells of interest therein:
  6. = c(3,8,9,10)# for the first column of the drawingsourcecolumns
  7. par(mfrow = c(1,1))
  8. netVisual_aggregate(cellchat,
  9. layout = c('hierarchy'), #"circle", "hierarchy", "chord"
  10. signaling = ,
  11. = ) # Select the pathway to display

Other charts

  1. par(mfrow = c(1,1))# Show network diagrams
  2. netVisual_aggregate(cellchat,
  3. layout = c('circle'),
  4. signaling = )
  5. par(mfrow=c(1,1))#Display string diagrams
  6. netVisual_aggregate(cellchat,
  7. layout = c('chord'),
  8. signaling = )
  9. par(mfrow=c(1,1))#Display Heatmap
  10. netVisual_heatmap(cellchat,
  11. signaling = ,
  12. = c("white", "#b2182b"))

4,Analysis of cellular communication at the level of signaling pathway-associated ligand-receptor pairs
  1. netAnalysis_contribution(cellchat,
  2. signaling = ) # Bar graph of ligand receptor pair contributions
  3. <- extractEnrichedLR(cellchat, # extract cell pair
  4. signaling = ,
  5. geneLR.return = FALSE)
  6. <- [1,] # with the contributiontop1As an example, the ligand-receptor pairs of
  7. ;

Other charts

  1. netVisual_individual(cellchat,#Hierarchy plot:
  2. layout = c('hierarchy'),
  3. signaling = , #Target signaling pathways
  4. pairLR.use = , # target ligand receptor pairs
  5. = ) #Subpopulation of cells of interest
  6. #Circle plot:
  7. netVisual_individual(cellchat,
  8. layout = c('circle'),
  9. signaling = ,
  10. pairLR.use = )
  11. #Chord diagram:
  12. netVisual_individual(cellchat,
  13. layout = c('chord'),
  14. signaling = ,
  15. pairLR.use = )

5,Visualization of cellular communication mediated at the level of multiple ligand-receptor pairs/signaling pathways
Specify signaling pathway
  1. Multiple ligand-receptor pairs/Visualization of cellular communication mediated at the level of signaling pathways ######
  2. levels(cellchat@idents)#specify signaling pathways
  3. netVisual_bubble(cellchat,
  4. sources.use = 4,
  5. targets.use = c(5:11),
  6. signaling = c("CCL","CXCL"), # Specify both CCL and CXCL signaling pathways
  7. = FALSE)
  8. # Specify matching receptor pairs:
  9. pairLR.use <- extractEnrichedLR(cellchat,
  10. signaling = c("CCL","CXCL","FGF")) #Identify ligand-receptor pairs that are important in target signaling pathways
  11. pairLR.use
  12. netVisual_bubble(cellchat,
  13. sources.use = 4,
  14. targets.use = c(5:11),
  15. pairLR.use = pairLR.use,# Specified receptor pairs
  16. = TRUE)

② Demonstration of the distribution of expression of genes involved in the target signaling pathway in various cell subpopulations
  1. #Demonstration of the expression distribution of genes involved in target signaling pathways across cellular subpopulations:
  2. plotGeneExpression(cellchat, signaling = 'GALECTIN',
  3. type = 'violin') # Violin charts

③Bubble chart
  1. plotGeneExpression(cellchat,
  2. signaling = 'GALECTIN', type = 'dot', color.use = c("white", "#b2182b")) #bubble chart