Error in apply(prob.pathways.sig, 3, sum) : 'MARGIN' does not match dim(X)
Hi, I have met a error which I saw many users met but none gave a solution. The problem is, when I created and run cellchat using the Seurat::FindCluster column 'seurat_clusters' in meta.data, cellchat run well and I could get a result. But, when I used the 'celltype' column which I assigned myself, cellchat would call error like below:
cellchat <- computeCommunProbPathway(cellchat)
Error in apply(prob.pathways.sig, 3, sum) :
'MARGIN' does not match dim(X)
I‘m very confused why I just change the group.by parameter but the pipeline was down. And hope there could be any solution or just tell me what's wrong of my operation.
Bests.
I am also having the same problem. I have used Seurat object to create cell chat. Everything runs fine before computeCommunProbPathway(cellchat). Is there a way to fix this error?
@cherrie-g @estherwon This is interesting. As you can see in the tutorial, cellchat can take input of any meta data. Could you try cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels")? That is, creating the object via data matrix. Could you show me unique(cellchat@idents)?
Hello this is my unique(cellchat@idents)
unique(cellchat@idents) [1] Memory CD4 T B CD8 T Naive CD4 T Levels: Naive CD4 T Memory CD4 T B CD8 T
I have already tried to use cellchat <- createCellChat(object = data.input, meta = meta, group.by = "labels") and I was able to successfully create CellChat object, but cellchat <- computeCommunProbPathway(cellchat) does not work and my netP slot does not get updated.
@estherwon I have no idea on this error. You need to run the sources codes line by line. If you like, you can also share me your object and I can take a look.
Hi, same problem when running my own scRNA data:
cellchat <- computeCommunProbPathway(cellchat) Error in apply(prob.pathways.sig, 3, sum) : 'MARGIN' does not match dim(X)
Solved the problem by setting:
# use all CellChatDB for cell-cell communication analysis
> CellChatDB.use <- CellChatDB # simply use the default CellChatDB
Do not use "Secreted Signaling" sebset, since "Secreted Signaling" results may not be enough to process following code.
CellChatDB.use <- subsetDB(CellChatDB, search = "Secreted Signaling") # use Secreted Signaling
I also encountered this problem and have ran the code line by line and it seems the problem is due to the significant pathways only having a 2D matrix instead of having a 3rd dimension in the array, this can occur when there is only one significant pathway
prob.pathways <- aperm(apply(prob, c(1, 2), by, group, sum), c(2, 3, 1))
pathways.sig <- pathways[apply(prob.pathways, 3, sum) != 0]
After this step @cherrie-g @estherwon you can check if pathways.sig only has one significant pathway in your cellchat object and if that is the case, then the next line of code:
prob.pathways.sig <- prob.pathways[,,pathways.sig] would produce a 2D matrix
Hence the following line of code won't work since there aren't 3 dimensions in the object of prob.pathways.sig
idx <- sort(apply(prob.pathways.sig, 3, sum), decreasing=TRUE, index.return = TRUE)$ix
In order to solve this issue, the argument drop=F can be added in the step when the matrix of significant pathways are subsetted from all of the probability pathways @sqjin if you could kindly add this to the code and push an update:
prob.pathways.sig <- prob.pathways[,,pathways.sig,drop=F]
This would retain the 3 dimensions even if there only ends up having 1 significant pathway in your dataset. Hope this helps!
I am facing the same problem. Could I know whether it is updated or there is a parameter I can use to solve it in my code?
@xzhouaw you can find this line in the code for computeCommunProbPathway() function:
prob.pathways.sig <- prob.pathways[,,pathways.sig]
and just change it to this prob.pathways.sig <- prob.pathways[,,pathways.sig,drop=F] then run the function and your analysis