CellChat icon indicating copy to clipboard operation
CellChat copied to clipboard

Error in obj2 - obj1 : non-conformable arrays

Open smk5g5 opened this issue 1 year ago • 3 comments

Hi,

I keep getting Error in obj2 - obj1 : non-conformable arrays this error when comparing 2 objects. I was wondering why is that and if you can let me know the cause of this error. Thank you!

smk5g5 avatar Jun 06 '24 12:06 smk5g5

@smk5g5 Sorry, I have no idea on this. The best way is to run the source codes line by line and figure out the reason.

sqjin avatar Jun 09 '24 08:06 sqjin

That means the 2 objects have different cell clusters or there are differences in their idents.

in that case you must first create a common idents and lift the sample that is missing it.

example:

group.new = unique(union(levels(cellchat.E14@idents), levels(cellchat.E13@idents)))
cellchat.E14@idents<- liftCellChat(cellchat.E14@idents, group.new)
object.list = list(cellchat.E14, cellchat.E13)
names(object.list) = c("cellchat.E14","cellchat.E13")
cellchat <- mergeCellChat(object.list, add.names = names(object.list), cell.prefix = TRUE)

in case cellchat.E13@idents has missing cluster then you must run

group.new = unique(union(levels(cellchat.E14@idents), levels(cellchat.E13@idents)))
cellchat.E14@idents<- liftCellChat(cellchat.E14@idents, group.new)
cellchat.E13@idents<- liftCellChat(cellchat.E13@idents, group.new)
object.list = list(cellchat.E14, cellchat.E13)
names(object.list) = c("cellchat.E14","cellchat.E13")
cellchat <- mergeCellChat(object.list, add.names = names(object.list), cell.prefix = TRUE)

micosacak avatar Jun 11 '24 15:06 micosacak

Thank you so much @micosacak . Indeed, this error occurs when we have different cell identities between the two objects. One can also:

shared_label = intersect(obj1@idents, obj2@idents)
[email protected] = matrix(nrow = 0,ncol = 0)
obj1 = subsetCellChat(obj1,idents.use = shared_label)
[email protected] = matrix(nrow = 0,ncol = 0)
obj2 = subsetCellChat(obj2,idents.use = shared_label)
object.list = list(obj1,obj2)
cellchat.merge <- mergeCellChat(object.list, add.names = names(object.list), cell.prefix = TRUE)

I'm doing this because I noticed that when using subsetCellChat, error occurred: no slot of name "data.smooth" for this object of class "CellChat" So I create an empty matrix just to bypass the error.

CC-DrDU avatar Jan 06 '25 05:01 CC-DrDU