sqjin / CellChat

R toolkit for inference, visualization and analysis of cell-cell communication from single-cell data
GNU General Public License v3.0
613 stars 140 forks source link

"Inference and analysis of cell-cell communication using CellChat" tutorial – Error messages #296

Open science070308 opened 2 years ago

science070308 commented 2 years ago

I am currently working my way through the “Inference and analysis of cell-cell communication using CellChat” tutorial (https://htmlpreview.github.io/?https://github.com/sqjin/CellChat/blob/master/tutorial/CellChat-vignette.html) to analyze/visualize the cell-cell communication networks from scRNA-seq data. The CellChat input file is from a Seurat object.

I am encountering some errors in my R code, and I am unsure how to resolve the errors:

-When running computeCommunProb(cellchat) I get the following error message:

Error in aggregate.data.frame(as.data.frame(x), ...) :

arguments must have same length

--

-When I run df.net <- subsetCommunication(cellchat) I get the following error message:

Error in names(x) <- value :

'names' attribute [3] must be the same length as the vector [1]

--

-When I run cellchat <- computeCommunProbPathway(cellchat) I get the following error message:

Error in apply(prob, c(1, 2), by, group, sum) :

dim(X) must have a positive length

--

-When I run cellchat <- aggregateNet(cellchat) I get the following error message:

Error in apply(prob > 0, c(1, 2), sum) :

dim(X) must have a positive length

--

I do not understand what the above error messages mean, and thus I do not know how to resolve these issues and cannot proceed with the rest of the tutorial. Any insight would be appreciated! Thank you!

My full R code is the following:

CellChat

Install CellChat

install.packages("devtools")

CellChat <- devtools::install_github("sqjin/CellChat")

Install dependencies for CellChat

install.packages('NMF')

devtools::install_github("jokergoo/circlize")

devtools::install_github("jokergoo/ComplexHeatmap")

library(CellChat)

library(patchwork)

options(stringsAsFactors = FALSE)

Prepare input data for CellChat analysis – extract the CellChat input file from a Seurat object

data.input <- GetAssayData(immune_hp.combined, assay = "RNA", slot = "data") #normalized data matrix

labels <- Idents(immune_hp.combined)

meta <- data.frame(group = labels, row.names = names(labels)) #create a dataframe of the cell labels

create a CellChat object from a data matrix

cellchat <- createCellChat(object = data.input, group.by = "ident")

Add cell information into meta slot of the object (Optional)

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

groupSize <- as.numeric(table(cellchat@idents)) # number of cells in each cell group

Set the ligand-receptor interaction database

CellChatDB <- CellChatDB.mouse

showDatabaseCategory(CellChatDB)

Show the structure of the database

dplyr::glimpse(CellChatDB$interaction)

To use all CellChatDB for cell-cell communication analysis, run the following code

CellChatDB.use <- CellChatDB

Set the used database in the object

cellchat@DB <- CellChatDB.use

Preprocessing the expression data for cell-cell communication analysis

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("multiprocess", workers = 4) # do parallel

cellchat <- identifyOverExpressedGenes(cellchat)

cellchat <- identifyOverExpressedInteractions(cellchat)

project gene expression data onto PPI network (optional)

cellchat <- projectData(cellchat, PPI.mouse)

Compute the communication probability and infer cellular communication network – ERROR

cellchat <- computeCommunProb(cellchat)

Filter out the cell-cell communication if there are only few number of cells in certain cell groups

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

Extract the inferred cellular communication network as a data frame – ERROR

df.net <- subsetCommunication(cellchat)

Infer the cell-cell communication at a signaling pathway level - ERROR

cellchat <- computeCommunPathway(cellchat)

Calculate the aggregated cell-cell communication network – ERROR

cellchat <- aggregateNet(cellchat)

HiRuser2021 commented 2 years ago

I have the same problem and cannot move forwared. Has the command been updated since April 26, when the following website was uploaded: https://htmlpreview.github.io/?https://github.com/sqjin/CellChat/blob/master/tutorial/CellChat-vignette.html ?

sqjin commented 2 years ago

@science070308 @HiRuser2021 Have you guys figured it out? I feel it is due to the improper input of your data. It is better to show me your input data.

jiaan-yu commented 2 years ago

Hi @sqjin I don't speak for the people above who had the issue with the code, but I think I might have run into similar issue. Nevertheless, there is a confounding mistake in the instructions when you use the tutorial From my experience, cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels") should be cellchat <- createCellChat(object = data.input, meta = meta, group.by = "group") if I to follow the Seurat object commands. Alternatively, use the correct name for the df meta <- data.frame(labels = var, row.names = names(var))

marialgk commented 1 year ago

Thank you, @jiaan-yu , this solved my issue!