sqjin / CellChat

R toolkit for inference, visualization and analysis of cell-cell communication from single-cell data
GNU General Public License v3.0
638 stars 145 forks source link

Error in netAnalysis_signalingRole_scatter : Please run `netAnalysis_computeCentrality` to compute the network centrality scores! #230

Open BatLaB-cell opened 3 years ago

BatLaB-cell commented 3 years ago

Dear cell chat users,

after using mergeCellChat encompassing different cellchat objects (C1,C2,C3,C4), I successfully run the downstream analysis with netVisual_diffInteraction for instance.

My issue arrives when I run the following codes:

num.link <- sapply(object.list, function(x) {rowSums(x@net$count) + colSums(x@net$count)-diag(x@net$count)}) weight.MinMax <- c(min(num.link), max(num.link)) # control the dot size in the different datasets gg <- list() for (i in 1:length(object.list)) { gg[[i]] <- netAnalysis_signalingRole_scatter(object.list[[i]], title = names(object.list)[i], weight.MinMax = weight.MinMax) }

I get the following error:

Error in netAnalysis_signalingRole_scatter(object.list[[i]], title = names(object.list)[i], : Please run netAnalysis_computeCentrality to compute the network centrality scores!

I can't see this line in the tutorial for multiple dataset analysis.

Does it mean I need to run this netAnalysis_computeCentrality code for each cell chat objects I merged before merging?

If yes, I tried to run individually

cellchat.C1 <- netAnalysis_computeCentrality(cellchat.C1, slot.name = "netP")

but it ended with the following error:

Error in if (nrow(adjmatrix) != ncol(adjmatrix)) { : argument is of length zero.

Could you help me please?

Thank you

sqjin commented 3 years ago

@BatLaB-cell This is unexpected. Yes, you need to run netAnalysis_computeCentrality code for each cell chat objects I merged before merging.

Can you run the source codes to examine the reason for such error? Please check the 'Help' section in the README file in this github.

BatLaB-cell commented 3 years ago

@sqjin how can I run the source codes?

zpingfeng commented 3 years ago

I have similar problem for 2 samples. Where can I find the source codes?

snow55 commented 3 years ago

I tried to change the color for each cell type by color.use and the color has been changed but is not consistent with cell type. How can I make it? Thanks.

snow55 commented 3 years ago

I tried to change the color for each cell type by color.use and the color has been changed but is not consistent with cell type. How can I make it? Thanks.

I have settled this question when I scanned your source code of netAnalysis_signalingRole_scatter function. It needs to add a line to revise the type of labels variate (from chr to factor). When I added this line, it works. df$labels = factor(df$labels,levels = levels(object@idents)).

sqjin commented 3 years ago

@snow55 Thank you for providing the solution. I am wondering whether you see the line df$labels <- factor(df$labels, levels = names(incoming.cells)) in your code. I have it in my local computer.