jinworks / CellChat

R toolkit for inference, visualization and analysis of cell-cell communication from single-cell and spatially resolved transcriptomics
GNU General Public License v3.0
299 stars 52 forks source link

Error in using identifyOverExpressedGenes #112

Open ssruser opened 8 months ago

ssruser commented 8 months ago

I have been trying to use the new cellchat v2 to run some analysis but I keep getting the same error when performing the ' identifyOverExpressedGenes' function.

I wanted to use the 'Comparison analysis of multiple datasets using CellChat' tutorial but read you need to first run CellChat on each dataset separately and then merge different CellChat objects together. So I started running the 'Inference and analysis of cell-cell communication using CellChat' tutorial first.

I have a seurat object with a control and a ko conditon so I first split this based on conditon then ran the pipeline on both datasets seperatly. This is the script I used...

Split harmony.20 dataset into two based on condition (WT/KO)

WT.dataset <- subset(x = harmony.20.filt.2.res0.5, subset = Condition == "WT.dataset") KO.dataset <- subset(x = harmony.20.filt.2.res0.5, subset = Condition == "KO.dataset")

Check the condition label again to check it has been split correctly

table(WT.dataset[["Condition"]]) table(KO.dataset[["Condition"]])

STEP 4 - Preparing to start from a Seurat object - with the split object

for the WT dataset

data.input.wt <- WT.dataset[["RNA"]]@data # normalized data matrix

For Seurat version >= “5.0.0”, get the normalized data via seurat_object[["RNA"]]$data

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

cellchat.WT <- createCellChat(object = data.input.wt, group.by = "orig.ident", assay = "RNA")

for the KO dataset

data.input.ko <- KO.dataset[["RNA"]]@data # normalized data matrix

For Seurat version >= “5.0.0”, get the normalized data via seurat_object[["RNA"]]$data

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

cellchat.KO <- createCellChat(object = data.input.ko, group.by = "orig.ident", assay = "RNA")

STEP 5 - Assigning the reference database to the object

CellChatDB <- CellChatDB.mouse showDatabaseCategory(CellChatDB) dplyr::glimpse(CellChatDB$interaction)

assigning ref database minus non-protein interactions...

CellChatDB.use <- subsetDB(CellChatDB) cellchat.WT@DB <- CellChatDB.use cellchat.KO@DB <- CellChatDB.use

STEP 6 - Preprocessing the cellchat objects

subset and pre-processing the expression data

subset the expresion data to use less RAM

cellchat.WT <- subsetData(cellchat.WT) cellchat.KO <- subsetData(cellchat.KO)

pre-processing the expression data

cellchat.WT <- identifyOverExpressedGenes(cellchat.WT) cellchat.WT <- identifyOverExpressedInteractions(cellchat.WT)

cellchat.KO <- identifyOverExpressedGenes(cellchat.KO) cellchat.KO <- identifyOverExpressedInteractions(cellchat.KO)

When I run these lines... 'cellchat.WT <- identifyOverExpressedGenes(cellchat.WT) or cellchat.KO <- identifyOverExpressedGenes(cellchat.KO)' I get the following error...

cellchat.WT <- identifyOverExpressedGenes(cellchat.WT) Error in wilcoxauc.default(data.use, labels, groups_use = level.use) : number of columns of X does not match length of y

Can someone help me figure this out? I have used the previous version of cellchat with the same data and used the same rough lines of code but never encountered an error in this line so unsure the cause of this.

Thank you in advance!

martina-morchio commented 7 months ago

Did you find a solution? I'm currently running into the same issue

ZhangMH2000 commented 7 months ago

Please confirm whether you choose the right database. See #15

ssruser commented 7 months ago

Hi Thank you for your response, I believe I did, the tissue I am using is mouse and I have selected for this.

STEP 5 - Assigning the reference database to the object

CellChatDB <- CellChatDB.mouse showDatabaseCategory(CellChatDB) dplyr::glimpse(CellChatDB$interaction)

assigning ref database minus non-protein interactions...

CellChatDB.use <- subsetDB(CellChatDB) cellchat.WT@DB <- CellChatDB.use cellchat.KO@DB <- CellChatDB.use

ifanirene commented 6 months ago

Hi Thank you for your response, I believe I did, the tissue I am using is mouse and I have selected for this.

STEP 5 - Assigning the reference database to the object CellChatDB <- CellChatDB.mouse showDatabaseCategory(CellChatDB) dplyr::glimpse(CellChatDB$interaction)

assigning ref database minus non-protein interactions... CellChatDB.use <- subsetDB(CellChatDB) cellchat.WT@DB <- CellChatDB.use cellchat.KO@DB <- CellChatDB.use

I hope you have figured this out. For me the problem was with the following step: CellChatDB.use <- subsetDB(CellChatDB) If you want to filter out non-protein interactions, replacing it with the following line would remove the error: CellChatDB.use <- subsetDB(CellChatDB, search =c("Secreted Signaling","ECM-Receptor","Cell-Cell Contact"), key = c("annotation")) Best