sqjin / CellChat

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

Error when running "netAnalysis_signalingRole_heatmap" #573

Open HouyuZhang opened 1 year ago

HouyuZhang commented 1 year ago

Dear developer, Thank you for this powerful software to study cell-cell communication. I recently have an error when running the netAnalysis_signalingRole_heatmap function, it raised "Error: elements in col should be named vectors." I have checked the Anno column and found these cell annotations are factors. Does someone have a similar issue when running this function? Thank you in advance.

ManuelMoradiellos commented 1 year ago

I do have the same error when running that function and netVisual_heatmap too even though I'm using a vector with the same names as my Idents... At the end I changed the color manually with Illustrator when creating the final version of the plot as I don't know if this error is a bug coming from ComplexHeatmap

HouyuZhang commented 1 year ago

Yes, I finally found this arose from ComplexHeatmap, where the col parameter needs a named color vector. The format should look like this: CellType1 CellType2 CellType3 "red" "blue" "black"

ManuelMoradiellos commented 1 year ago

How did you defined that named color vector?? Because i tried to do mine in the usual way:

asa_palette <- c('B cells' = '#426600', 'DC' = '#FF0010', 'Endothelial cells' = '#4C005C', 'Epithelial cells' = '#FFCC99', 'Fibroblasts' = '#8F7C00', 'ILC' = '#808080', 'Macrophages' = '#9DCC00', 'Mixed group' = '#F0A0FF', 'Monocytes' = '#005C31', 'Neutrophils' = '#191919', 'NK cells' = '#C20088', 'NKT' = '#FFA405', 'Stem cells' = '#003380', 'T cells CD4' = '#FFA8BB', 'T cells CD8' = '#993F00', 'T cells immature-early' = '#65c8db', 'Tgd' = '#2BCE48', 'Tregs' = '#0075DC' )

And I believe it's done correctly but I still have the same issue:

image

I don't know what did I do wrong but I would have save me a lot of time of post-editing...

ManuelMoradiellos commented 1 year ago

Literally I've just noticed that this error arises when you select the remove.isolate = T!

With that option set to FALSE the colors are matched accordingly, and I recommend using it because in the past I saw that it was removing some rows that it shouldn't...

HouyuZhang commented 1 year ago

Cell types in the color vector should be exactly the same as the cell types input for cellchat analysis.

ManuelMoradiellos commented 1 year ago

They are the same! In other functions the named vector worked perfectly but in netVisual_heatmap it only worked when remove.isolate = TRUE; maybe it's because of what you say, as removing the isolates is removing cell types that it cannot find in the named color vector

sqjin commented 1 year ago

@ManuelMoradiellos It should be fixed now.