CellChat
CellChat copied to clipboard
Issue in cellchat <- identifyOverExpressedGenes(cellchat)
Hi, I am facing troubles in identifyOverExpressedGenes(cellchat) and identifyOverExpressedInteractions(cellchat) functions.
I get the same error for both functions:
Error in rep(no, length.out = len) : attempt to replicate an object of type 'closure' 2. ifelse(test = future::nbrOfWorkers() == 1, yes = pbapply::pbsapply, no = future.apply::future_sapply) 1. identifyOverExpressedGenes(cellchat)
Can you please suggest what to do? I am really struggling to finish my analysis.
I am using the following code to complete previous functions:
`lung_carcinoma_seurat <- readRDS("../Output/Lung_adenocarcinoma_seurat_CellChat_NormalizedOnly.rds")
data.input = GetAssayData(lung_carcinoma_seurat, assay = "RNA", slot = "data") # normalized data matrix labels = [email protected]$Cell_subtype meta = data.frame(group = labels, row.names = names(labels)) # create a dataframe of the cell labels
cellchat <- createCellChat(object = data.input, meta = meta, group.by = 'group')
#Create a CellChat object from a data matrix
The cell barcodes in 'meta' is 1 2 3 4 5 6 The cell barcodes in 'meta' is different from those in the used data matrix. We now simply assign the colnames in the data matrix to the rownames of 'mata'!Set cell identities for the new CellChat object The cell groups used for CellChat analysis are Activated DCs Alveolar Mac AT1 AT2 CD141+ DCs CD163+CD14+ DCs CD1c+ DCs CD207+CD1a+ LCs CD4+ Th CD8 low T CD8+/CD4+ Mixed Th Ciliated Club COL13A1+ matrix FBs COL14A1+ matrix FBs Cytotoxic CD8+ T EPCs Exhausted CD8+ T Exhausted Tfh FB-like cells Follicular B cells GC B cells in the DZ GC B cells in the LZ GrB-secreting B cells Lymphatic ECs Malignant cells MALT B cells MAST Mesothelial cells Microglia/Mac mo-Mac Monocytes Myofibroblasts Naive CD4+ T Naive CD8+ T NK pDCs Pericytes Plasma cells Pleural Mac Smooth muscle cells Stalk-like ECs Tip-like ECs Treg tS1 tS2 tS3 Tumor ECs Undetermined
CellChatDB <- CellChatDB.human # use CellChatDB.mouse if running on mouse data showDatabaseCategory(CellChatDB)
Show the structure of the database
dplyr::glimpse(CellChatDB$interaction)
use a subset of CellChatDB for cell-cell communication analysis
CellChatDB.use <- subsetDB(CellChatDB, search = "Secreted Signaling")
use Secreted Signaling
use all CellChatDB for cell-cell communication analysis
CellChatDB.use <- CellChatDB # simply use the default CellChatDB
set the used database in the object
cellchat@DB <- CellChatDB.use
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") # do parallel
cellchat <- identifyOverExpressedGenes(cellchat)
cellchat <- identifyOverExpressedInteractions(cellchat)
project gene expression data onto PPI network (optional) cellchat <- projectData(cellchat, PPI.human)
#HERE IS THE ERROR
Error in rep(no, length.out = len) : attempt to replicate an object of type 'closure'
2.
ifelse(test = future::nbrOfWorkers() == 1, yes = pbapply::pbsapply, no = future.apply::future_sapply)
1.
identifyOverExpressedGenes(cellchat)
`
Am I even uploading the Seurat object correctly? Please help, thank you so much.
@superman2412 It looks ok. Can you show me the [email protected] and unique(cellchat@idents)?
@sqjin Thank you for your prompt response. Yes, here you go. One thing to bear in mind would be that my Seurat object (inside R environment) is 7.8GB. That shouldn't make any difference right? As long as as I have enough RAM?




@sqjin Would be fantastic if you could see what the issue is here and why it isn't running.
@sqjin Some more information on this error.

@superman2412 The data matrix looks good. The error information you posted is not much informative. Can you run the source code of this function line by line to give more error information?
@sqjin . Managed to fix this error by changing the syntax of a code chunk found in the source code.
FROM:
my.sapply <- ifelse(
test = future::nbrOfWorkers() == 1,
yes = pbapply::pbsapply,
no = future.apply::future_sapply
)
TO:
my.sapply <- if(
test <- future::nbrOfWorkers() == 1)elsif(
yes = pbapply::pbsapply)else(
no = future.apply::future_sapply
)
The code chunk belongs to the identifyOverexpressedGenes and identifyOverExpressedInteractions functions. Also, I ran the edited source code itself in my script and the function ran successfully.
Why do you think changed syntax is fixing the error? Also, do you mind uploading updated version of the CellChat package so the error is fixed globally (i.e. in case such a code chuck appears any other function)?
@superman2412 Can you please check the edited codes you shared? There is an error when running on my computer. Error in elsif(yes = pbapply::pbsapply) : could not find function "elsif" Error in elseif(yes = pbapply::pbsapply) : could not find function "elseif"
@sqjin Not sure what's going on here. So for the functions identifyOverExpressedInteractions
, identifyOverExpressedGenes
changing this code chunk:
my.sapply <- ifelse(
test = future::nbrOfWorkers() == 1,
yes = pbapply::pbsapply,
no = future.apply::future_sapply
)
TO, the following code chunk
my.sapply <- if(
test <- future::nbrOfWorkers() == 1)elsif(
yes = pbapply::pbsapply)else(
no = future.apply::future_sapply
Makes the code run properly, without any error.
-
Is there any thing we can do to troubleshoot this error?
-
There's another problem though, now I have the same error in the following function:
cellchat <- computeCommunProb(cellchat)
What changes do I need to make here to the following code chunk of the computeCommunProb function to make the code run?
my.sapply <- ifelse(
test = future::nbrOfWorkers() == 1,
yes = sapply,
no = future.apply::future_sapply
)
CHANGING THIS:
my.sapply <- if(
test = future::nbrOfWorkers() == 1,
yes = pbapply::pbsapply,
no = future.apply::future_sapply
)
TO:
my.sapply <- future.apply::future_sapply
in all the files of the source code fixes the errors.
Huge thank you to @sqjin for helping me through this. If anyone wants the modified package (i.e. with the changed source code) you can find it here: https://github.com/superman2412
@sqjin you can close the issue now.
Thanks for this discussion. I just wanted to point out that I'm also encountering the same issue (even when running the tutorial vignette) and replacing the ifelse loop by what @superman2412 suggested solves the issue. It might have to do with an update of the future package. The command future::plan("multiprocess", workers = 4)
as used in the vignette is now deprecated. Instead one should use future::plan("multisession")
(or any of the other types of future currently implemented). However, this generates the error mentioned in this issue when running identifyOverExpressedGenes()
.
@sqjin: in 1.1.3 this does not seem to be resolved yet, but hopefully this will be addressed in a future release of CellChat.
EDIT: the same issue also arises in netClustering()
, where exactly the same ifelse loop needs to be replaced. Also, future::plan("multiprocess", workers = nCores)
on the line above needs to be changed into future::plan("multisession", workers = nCores)
.
@YitengDang and @superman2412 thanks for the info! I am still running into this issue due to a future update (I think) for the netClustering()
function.
Error in rep(no, length.out = len) :
attempt to replicate an object of type 'closure'
For those that don't know, you can easily edit netClustering()
, or any other function similarly, with trace(netClustering, edit = T)
which will bring up a window to look at the source code for that function.
Edit: Just to specify, I used the same recommendations as @YitengDang and the code works now.