sqjin / CellChat

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

Error in using netVisual_bubble when comparing two datasets #358

Open jv-20 opened 2 years ago

jv-20 commented 2 years ago

Hi @sqjin

A quick question. I get the following error when running the following code

netVisual_bubble(cellchat.HC_CDI,sources.use = 6, targets.use = 9,comparison = c(1,2)) Comparing communications on a merged object

Error in seq.default(0.5 + length(dataset.name[comparison]), length(group.names0) *  : 
  wrong sign in 'by' argument

One thing I forgot to include column named "evidence" in the LR database when running cellchat initially. I noticed some functions wouldn't work without having this column, So after I obtained the cellchat results, I added column name "evidence" as follows

#single datasets
cellchat.DS@LR$LRsig$evidence="evidence"
cellchat.HC@LR$LRsig$evidence="evidence"

#merged object
cellchat.HC_DS@LR$HC$LRsig$evidence="evidence"
cellchat.HC_DS@LR$DS$LRsig$evidence="evidence"

Just wanted to check if this would be the cause of error I am receiving when using netVisual_bubble or I have to re-run the analysis with "evidence" column included at the start of the analysis. Any thoughts?

Thank you, Janaki

sqjin commented 2 years ago

@jv-20 I think the reason might be that there is only one cluster as source and one cluster as target. There may be a bug in such special case. I will check it and you can also run the source code to fix the issue.

jv-20 commented 2 years ago

Hi @sqjin , you are correct. It works when the source or target cell types are more than 1. But if there is only one celltype given in source and target, it gives me the above error. Thanks for looking into this. Much appreciated.

zhanglab2008 commented 2 years ago

I came across the same issue when I limited the source and target to 1 cell type. Do you have a quick fix, Jin? I will look at your source codes and see if I can fix it but just to see if you already have a solution. Thanks!

zhanglab2008 commented 2 years ago

May not be an ideal solution but I returned the data frame and reploted it with ggplot. I just have one more question: Why the p value column is greater than 1? In my case they are all 3

malosreet commented 2 years ago

I am also facing a similar issue with netVisual_bubble where the p-values are all 3. After looking at the source code, I think what is being returned in the size of the circle to be plotted, which is larger for smaller p-values. So 3 actually means that p-value is < 0.01.

Perhaps instead of re-writing the pval column a new column called pval_size (or something similar) could be created?

sqjin commented 2 years ago

@malosreet This is a good suggestion. I will add this later today. Thanks!