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
-
rm(list=ls())
-
library(CellChat)
-
library(patchwork)
-
library(ggplot2)
-
library(Seurat)
-
library(ggalluvial)# Plotting Sankey diagrams
-
library(expm)
-
library(sna)
-
library(NMF)
-
options(stringsAsFactors = FALSE)## input data is not automatically converted to factors (to prevent data formatting errors)
-
load("data_humanSkin.Rdata") #data loaded: here is the count data data
②CellChat Input Data Preparation
-
#Normalized gene expression matrix and cell grouping information files required
-
# Different input formats are handled differently
-
data.input = data_humanSkin$data#Normalized gene expression matrix and cell grouping information files required
-
meta = data_humanSkin$meta
-
data.input[1:6,1:3] #Expressioncount
-
head(meta);table(meta$condition) #with normal(NL) and disequations(LS)
-
cell.use = rownames(meta)[meta$condition == 'LS'] #Name of the cell from which the LS was extracted
-
data.input = data.input[, cell.use]# Extract the LS expression matrix
-
meta = meta[cell.use, ]#Extract LS cell information
-
identical(rownames(meta),colnames(data.input)) #Check that matrix column names and grouped file line names are identical
-
unique(meta$labels) #check cell subpopulation label type
③Building CellChat Objects
-
# Next build the CellChat object
-
cellchat <- createCellChat(object = data.input, # Support for normalized expression matrices, Seurat objects, and SingleCellExperiment objects
-
meta = meta, #meta file
-
group.by = 'labels') #cell classification columns in meta
-
#cellchat <- addMeta(cellchat, meta = meta)#Create CellChat object without cellmeta information when adding the information
-
cellchat <- setIdent(cellchat, ident.use = 'labels') #Set the labels to the default order in which they are displayed
-
levels(cellchat@idents) #look at celltype and factor order
-
table(cellchat@idents) # of cells in each celltype
-
-
# Setting up the ligand receptor database (CellChatDB).
-
CellChatDB <- #() ()
-
showDatabaseCategory(CellChatDB) #View a pie chart describing the composition of this database
-
dplyr::glimpse(CellChatDB$interaction) #view database structure
-
-
#Directly use the full CellChatDB library for cell communication analysis:
-
##CellChatDB.use <- CellChatDB # simply use the default CellChatDB
-
#Select a specific subset of the database for cellular communication analysis.
-
CellChatDB.use <- subsetDB(CellChatDB,
-
search = 'Secreted Signaling') #selectableSecreted Signaling、ECM-ReceptormaybeCell-Cell Contact
-
cellchat@DB <- CellChatDB.use# Add database to CellChat object (DB)
④Data preprocessing
-
#Data preprocessing; expression matrix subsetting of signaling genes saves computational costs
-
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
-
#future::plan('multiprocess', workers = 4) # do parallel (parallel computation can be unchecked)
-
#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.
-
cellchat <- identifyOverExpressedGenes(cellchat,
-
= TRUE, # Only positive markers are returned
-
= 0, #Cell Proportion Threshold
-
= 0, # Multiples of variance
-
= 0.05) #P-Value
-
#Calculated results assigned to cellchat@var.features:
-
head(cellchat@var.features$features) # Overexpressed signaling gene name
-
head(cellchat@var.features$features.info) # Table of results of variance calculations
-
# Recognize overexpressed gene ligand-receptor interactions:
-
cellchat <- identifyOverExpressedInteractions(cellchat)
-
head(cellchat@LR$LRsig) # Calculated result assignment position
-
# Map gene expression data to PPI networks (skippable):
-
cellchat <- projectData(cellchat, PPI.human) #Return results:cellchat@data.project
2, Cellular communication prediction
① Calculate the cellular communication probability
-
#CellComm predictions ##############################################
-
cellchat <- computeCommunProb(cellchat, raw.use = TRUE) #Return result:cellchat@options$parameter
-
## 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
-
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
-
# Extracted ligand receptor to cellular communication results table:
-
<- subsetCommunication(cellchat, = 'net')
-
head() #Get a table of ligand-receptor-to-cell communication results
-
-
# or visit other interested/Specific cellular communication results:
-
1 <- subsetCommunication(cellchat,
-
sources.use = c('LC'),
-
targets.use = c('FBN1+ FIB')) # Access to a subset of specific cell pairs
-
head(1)
-
-
2 <- subsetCommunication(cellchat, signaling = c('CD40')) # Access to specific subsets of signaling pathways
-
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
-
# Extract cellular communication tables at the level of signaling pathways:
-
cellchat <- computeCommunProbPathway(cellchat) #Calculate the probability of communication at the level of the signaling pathway
-
df.netp <- subsetCommunication(cellchat, = 'netP') #Get signaling pathway level cellchat table
-
head()
④Visualization of cellular interactions
1) Network diagram of the number of ligand receptors between cell subpopulations
-
cellchat <- aggregateNet(cellchat)# Calculate the number and probability strength of communication between cell pairs
-
# Number and probability of interactions between different cell subpopulations/Intensity visualization:
-
groupSize <- as.numeric(table(cellchat@idents))## Network map of ligand receptor numbers between cell subpopulations:
-
par(mfrow = c(1,1), xpd = TRUE)
-
netVisual_circle(cellchat@net$count,
-
= groupSize,
-
= T,
-
= F,
-
= 'Number of interactions')
Cell Communication| Basic Analysis Tutorial_Beep_bilibili
2) Ligand-receptor probability/intensity network diagram between cellular subpopulations
-
## Probability/intensity network plot of ligand receptors between cell subpopulations:
-
par(mfrow = c(1,1), xpd = TRUE)
-
netVisual_circle(cellchat@net$weight,
-
= groupSize,
-
= T,
-
= F,
-
= '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
-
## Examine the strength of interactions signals in individual cell subpopulations; each cell is shown individually ###
-
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])
-
}
4) Quantity and intensity chord plots merged
-
# Quantity and intensity chord plots merged
-
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')
-
# Save the cellchat object:
-
save(cellchat, groupSize, file = c('humanSkin_CellChat.Rdata'))
3, Analysis of cellular communication at the level of signaling pathways
-
cellchat@netP$pathways##Signaling pathways to view
-
<- c('GALECTIN')## to'GALECTIN'Signaling pathway demonstration as an example
-
# Hierarchy plotting
-
levels(cellchat@idents)# View cell subpopulations and factor order:
-
#Select the subpopulation of cells of interest therein:
-
= c(3,8,9,10)# for the first column of the drawingsourcecolumns
-
par(mfrow = c(1,1))
-
netVisual_aggregate(cellchat,
-
layout = c('hierarchy'), #"circle", "hierarchy", "chord"
-
signaling = ,
-
= ) # Select the pathway to display
Other charts
-
par(mfrow = c(1,1))# Show network diagrams
-
netVisual_aggregate(cellchat,
-
layout = c('circle'),
-
signaling = )
-
par(mfrow=c(1,1))#Display string diagrams
-
netVisual_aggregate(cellchat,
-
layout = c('chord'),
-
signaling = )
-
par(mfrow=c(1,1))#Display Heatmap
-
netVisual_heatmap(cellchat,
-
signaling = ,
-
= c("white", "#b2182b"))
4,Analysis of cellular communication at the level of signaling pathway-associated ligand-receptor pairs
-
netAnalysis_contribution(cellchat,
-
signaling = ) # Bar graph of ligand receptor pair contributions
-
<- extractEnrichedLR(cellchat, # extract cell pair
-
signaling = ,
-
geneLR.return = FALSE)
-
<- [1,] # with the contributiontop1As an example, the ligand-receptor pairs of
-
;
Other charts
-
netVisual_individual(cellchat,#Hierarchy plot:
-
layout = c('hierarchy'),
-
signaling = , #Target signaling pathways
-
pairLR.use = , # target ligand receptor pairs
-
= ) #Subpopulation of cells of interest
-
#Circle plot:
-
netVisual_individual(cellchat,
-
layout = c('circle'),
-
signaling = ,
-
pairLR.use = )
-
#Chord diagram:
-
netVisual_individual(cellchat,
-
layout = c('chord'),
-
signaling = ,
-
pairLR.use = )
5,Visualization of cellular communication mediated at the level of multiple ligand-receptor pairs/signaling pathways
①Specify signaling pathway
-
Multiple ligand-receptor pairs/Visualization of cellular communication mediated at the level of signaling pathways ######
-
levels(cellchat@idents)#specify signaling pathways
-
netVisual_bubble(cellchat,
-
sources.use = 4,
-
targets.use = c(5:11),
-
signaling = c("CCL","CXCL"), # Specify both CCL and CXCL signaling pathways
-
= FALSE)
-
# Specify matching receptor pairs:
-
pairLR.use <- extractEnrichedLR(cellchat,
-
signaling = c("CCL","CXCL","FGF")) #Identify ligand-receptor pairs that are important in target signaling pathways
-
pairLR.use
-
netVisual_bubble(cellchat,
-
sources.use = 4,
-
targets.use = c(5:11),
-
pairLR.use = pairLR.use,# Specified receptor pairs
-
= TRUE)
② Demonstration of the distribution of expression of genes involved in the target signaling pathway in various cell subpopulations
-
#Demonstration of the expression distribution of genes involved in target signaling pathways across cellular subpopulations:
-
plotGeneExpression(cellchat, signaling = 'GALECTIN',
-
type = 'violin') # Violin charts
③Bubble chart
-
plotGeneExpression(cellchat,
-
signaling = 'GALECTIN', type = 'dot', color.use = c("white", "#b2182b")) #bubble chart
-