CellChat icon indicating copy to clipboard operation
CellChat copied to clipboard

netVisual_diffInteraction for specific cell target, Error in i_set_edge_attr(x, attr(value, "name"), index = value, value = attr(value, : Length of new attribute value must be 1 or 25, the number of target edges, not 7

Open rfreeman7 opened this issue 2 years ago • 4 comments

Hello! I have been trying to generate a circle plot showing differential interaction strength for a specific target between two groups. I am able to generate this plot for all cell types, but as it is quite noisy I am trying to show this plot for a specific target of interest. My code:

** par(mfrow = c(1,2), xpd=TRUE) netVisual_diffInteraction(cellchat.S, weight.scale = T, measure = "weight", targets.use = 7)**

However, I receive the following error message: "Error in i_set_edge_attr(x, attr(value, "name"), index = value, value = attr(value, : Length of new attribute value must be 1 or 25, the number of target edges, not 7"

If I set the target to 1 or 25 I am able to get the differential interaction strength circle plot for those targets. How can I get this to work for my cell type of interest? I thought perhaps something was wrong with the objects I merged into this cellchat object, but rerunning the program did not help.

Thank you!

rfreeman7 avatar Oct 03 '23 14:10 rfreeman7

Hi,Have you solved this problem ?

JiahaoWongg avatar Oct 12 '23 01:10 JiahaoWongg

Hello,Thank you for following up! Unfortunately, I have not. I tried rerunning it from the beginning (generating the cell chat objects to compare), but I get the same problem.

rfreeman7 avatar Oct 12 '23 12:10 rfreeman7

As discussed in #658, you can resolve by modifying the code:

if(sum(edge.start[,2]==edge.start[,1])!=0){
    igraph::E(g)$loop.angle <- NA # add this
    igraph::E(g)$loop.angle[which(edge.start[,2]==edge.start[,1])]<-loop.angle[edge.start[which(edge.start[,2]==edge.start[,1]),1]]
  }

I think it has something to do with including certain cell types that have very few interactions, but setting remove.isolate=TRUE does not help. In fact, setting remove.isolate=TRUE creates a different error that is not solved by the above source code modification.:

> CellChat::netVisual_diffInteraction(cellchat,
                                     weight.scale = T,
                                     targets.use=c(1:13),
                                     sources.use=c(1:13), remove.isolate=TRUE)
> Error in abs(igraph::E(g)$weight) : 
  non-numeric argument to mathematical function

jmodlis avatar Oct 18 '23 14:10 jmodlis

Thank you for your response! Does that require running the entire visualization vignette (to define loop.angle and edge.start)?

On Oct 18, 2023, at 10:43 AM, J Modliszewski @.***> wrote:

As discussed in #658 https://github.com/sqjin/CellChat/issues/658, you can resolve by modifying the code:

if(sum(edge.start[,2]==edge.start[,1])!=0){ igraph::E(g)$loop.angle <- NA # add this igraph::E(g)$loop.angle[which(edge.start[,2]==edge.start[,1])]<-loop.angle[edge.start[which(edge.start[,2]==edge.start[,1]),1]] } I think it has something to do with including certain cell types that have very few interactions, but setting remove.isolate=TRUE does not help. In fact, setting remove.isolate=TRUE creates a different error that is not solved by the above source code modification.:

CellChat::netVisual_diffInteraction(cellchat, weight.scale = T, targets.use=c(1:13), sources.use=c(1:13), remove.isolate=TRUE) Error in abs(igraph::E(g)$weight) : non-numeric argument to mathematical function — Reply to this email directly, view it on GitHub https://github.com/sqjin/CellChat/issues/705#issuecomment-1768619215, or unsubscribe https://github.com/notifications/unsubscribe-auth/A77Q2PSSSVNSFSZ3RG2XD23X77TIRAVCNFSM6AAAAAA5RDELMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRYGYYTSMRRGU. You are receiving this because you authored the thread.

rfreeman7 avatar Oct 18 '23 16:10 rfreeman7