Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

netVisual_diffInteraction:Error in obj2 - obj1 : non-conformable arrays #708

Open
JiahaoWongg opened this issue Oct 12, 2023 · 2 comments

Comments

@JiahaoWongg
Copy link

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

@eijynagai
Copy link

eijynagai commented Oct 25, 2023

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

@JiahaoWongg
Copy link
Author

@eijynagai Not yet. But you just need to source my fixed code above.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants