netVisual_diffInteraction:Error in obj2 - obj1 : non-conformable arrays
package.version("CellChat")
[1] "1.6.1"
I want to compare to cellchat object using netVisual_diffInteraction, but got this error:
Error in obj2 - obj1 : non-conformable arrays
After check source code, I found the reason is the two object have different length of types in group.by meta.
So I use subsetCellChat to subset object with shared types.
However, also get error below:
Error in i_set_edge_attr(x, attr(value, "name"), index = value, value = attr(value, :
Length of new attribute value must be 1 or x, the number of target edges, not x
So, I decide to fix source code, which solve my problom.
Below R/visualization.R line 1644, add:
shared_label = intersect(rownames(obj1_raw), rownames(obj2_raw))
obj1 = obj1_raw[shared_label, shared_label]
obj2 = obj2_raw[shared_label, shared_label]
to only keep shared types, which can solve error mentioned in title
Also, R/visualization.R line 1738, I guess, may be the reason cause error above Length of new attribute value must be ....
Before this line, I give the same length as edge.start in advance to avoid errors caused by length mismatch when adding igraph::E (g)$loop.angle
if(sum(edge.start[,2]==edge.start[,1])!=0){
igraph::E(g)$loop.angle = rep(0, nrow(edge.start)) # add this new line
igraph::E(g)$loop.angle[which(edge.start[,2]==edge.start[,1])]<-loop.angle[edge.start[which(edge.start[,2]==edge.start[,1]),1]]
}
That's works, hurray!
Fixed code: https://github.com/JiahaoWongg/CellChat_fix/blob/main/visualization.R
I have the same issue here!
But since I use Docker image, I may need to wait until the next update. @JiahaoWongg thanks for the fix, but do you have a simple workaround?
Thanks in advance
@eijynagai Not yet. But you just need to source my fixed code above.