zktuong / ktplots

Some tools for plotting single-cell data
https://zktuong.github.io/ktplots/
MIT License
157 stars 30 forks source link

plot_cpdb2: non significant interactions show up and other problems #78

Closed stanaka6 closed 1 year ago

stanaka6 commented 1 year ago

Hello,

Thank you very much for providing a wonderful tool!

I have a few questions about plot_cpdb2:

  1. I set keep_significant_only = TRUE, but it looks like non-significant interactions are still in my plot. Could you please let me know how I can solve this problem? I have looked at the source code of plot_cpdb2 but couldn't find the codes to exclude non-significant ones even if keep_significant_only = TRUE. I would be grateful if you could provide me with any clarification.

  2. Is -log10(sig) is equal to -log10(p-value)? If so, why is the range from 0 to 1? Is it possible to show the original -log10(p-value) as 0<~infenity?

  3. In my plot, interaction scores are represented by line colors, and -log10(sig) is represented by the thickness of the bars, unlike the plot in the example (opposite: thickness - score, -log10(sig) = colors. Why that happens, and would it be possible to use the same way in the example?

Here is my code:

Interest2 <- list(c('XXX', '36'), c('YYY', '36'),
                 c('ZZZ', '36'),c('AAA','36'),
                 c('BBB','36'))

colors2 <- c("XXX" = "#86bc86",
            "YYY" = "#79706e",
            "ZZZ" = "#ff7f0e",
            "AAA" = "#bcbd22",
            "BBB" = "#17becf",
            "36" = "#EC407A")

p2<- plot_cpdb2(cell_type1 = "XXX|YYY|ZZZ|AAA|BBB",
           cell_type2 = "36",
           idents = 'cell_type',
           scdata = mySCE,
           means = means,
           pvals = pvals,
           deconvoluted = deconvoluted,       
           desiredInteractions = Interest2,
           node_group_colors = colors2,
           keep_significant_only = TRUE,
           standard_scale = TRUE,
           remove_self = TRUE)

Screenshot 2023-05-31 at 8 36 24 PM This is the legend of my plot (hiding cell-type information)

Any comments and suggestions would be very much appreciated.

Thanks!

zktuong commented 1 year ago

Hi @stanaka6, thank you for the interest in ktplots.

  1. keep_significant_only is passed to plot_cpdb where significant interactions are additionally labelled with the highlights. The current trimming occurs on the cellphonedb output but row-wise, i.e. only keeps the interaction if there is at least 1 celltype-celltype pair that shows the significant interaction. Therefore, how it works currently is a feature for plot_cpdb. I can see why one would want to just only keep the significant hits. I will have to look into this further to implement the ability to just show the actual significant only.

  2. yes. it still scales to 0 to 1 because you had standard_scale = TRUE. just toggle that to FALSE, as well as scale = FALSE. For clarity, both scale (z-score) and standard_scale (0 to 1) are default TRUE. Toggling both to FALSE should revert to the original p-value.

  3. you are right. my apologies. it seems i have switched the width and alpha parameters at some point. let me look into this further.

Should also mention that you are also welcomed to put in PRs to toggle the behaviours you want.

stanaka6 commented 1 year ago

Thank you for your answers! Any updates?

zktuong commented 1 year ago

hi @stanaka6, sorry i haven't had time to work on this. progress will be a bit slow.

zktuong commented 1 year ago

@stanaka6, hi, can you give the version in my #79 PR a go?

devtools::install_github('zktuong/ktplots', ref = 'flip-colour-order')

I've added in an argument plot_score_as_thickness that takes TRUE/FALSE to toggle the thickness versus alpha scaling. let me know if that works for you