DillonHammill / CytoExploreR

Interactive Cytometry Data Analysis
60 stars 13 forks source link

Population percentages different for cyto_plot_gating_scheme vs cyto_plot #111

Open Biomiha opened 3 years ago

Biomiha commented 3 years ago

Hi @DillonHammill,

I'm seeing some unusual behavior with the population percentages when I plot a sample with cyto_plot_gating_scheme (e.g. 1793%) Gating_scheme

Whereas cyto_plot plots accurate percentages for the same sample: Whole_blood_gating Is this because of the back gating or could it be because there are multiple gates on the same plot?

Many thanks in advance.

DillonHammill commented 3 years ago

@Biomiha, looks like cyto_plot() is getting confused as to which layer it is labelling. If you look closely you will see that the statistic is in a separate label to "Monocytes" - so for some reason it has skipped the displaying the Monocytes statistics in favour of a different layer. I have probably fixed this already on the coming version of CytoExploreR but maybe I can push a temporary fix for you.

Do you get the same issue when plotting with cyto_plot() directly?

cyto_plot(gs[[1]], 
          parent = "Live", 
          alias = c("Lymphocytes", "Monocytes", "Granulocytes"), 
          overlay = c("Lymphocytes", "Monocytes", "Granulocytes"), 
          channels = c("FSC-H", "SSC-H"))
Biomiha commented 3 years ago

@DillonHammill Yes, the second plot (at the bottom) was made using cyto_plot and it looks like the population percentages are as expected. If you compare the gate percentages in the plot at the top, there are 2 differences - the lymphocyte gate should be ~41% (instead of ~4%) and the monocyte gate should be roughly 2% instead of 1793%. Thanks for the feedback. Looking forward to the new version.

DillonHammill commented 3 years ago

Are you able to include the image generated by cyto_plot() with all the overlays? It will help to track down where things have gone wrong. Sorry just realised I omitted this from my previous comment, I just updated the code in my above comment.

DillonHammill commented 3 years ago

Similarly, an image generated by cyto_plot_gating_scheme() with back_gate = FALSE would be equally useful.

Biomiha commented 3 years ago

Using cyto_plot_gating_scheme(x = gs[[1]], back_gate = FALSE, gate_track = TRUE, axes_trans = trans_obj, legend = FALSE) gives me: GatingScheme_nobackgate Whereas if I try cyto_plot with overlays, I get the following warning message and the plot below:

Warning message:
In split.default(TNP, rep(seq_len(SMP), each = NP)) :
    data length is not a multiple of split variable

Cyto_plot_version

DillonHammill commented 3 years ago

Thanks @Biomiha, this is very helpful. Unfortunately it looks like I was right and cyto_plot() is getting the layers mixed up when overlays are present. I will take a closer look and get back to you.

DillonHammill commented 3 years ago

@Biomiha, I managed to track down the bug. I have just pushed the fix to the master branch for you:

devtools::install_github("DillonHammill/CytoExploreR")

Note to self: This bug is not present in coming version as this code has already been re-written.

Biomiha commented 3 years ago

Hi @DillonHammill,

I keep getting the following error if I specify: back_gate = TRUE

Error in if (channels[1] == channels[2] | (!.empty(channels[1]) & .empty(channels[2]))) { : 
  missing value where TRUE/FALSE needed

I'm not sure if it is to do with my GatingSet or something else but it seems to work when back_gate = FALSE.

DillonHammill commented 3 years ago

@Biomiha, looks like you have added a boolean gate to your gating scheme, the plotting of which is not currently supported by cyto_plot_gating_scheme().

DillonHammill commented 3 years ago

Closing as I believe the original issue has been resolved.

Biomiha commented 3 years ago

Hi @DillonHammill,

There's no boolean gate but unfortunately I haven't been able to figure out what is causing the issue. I think it's best if you close the issue for now and I'll do some troubleshooting to hopefully find out what the source of the problem is.

Thanks.

DillonHammill commented 3 years ago

@Biomiha, if you send through your gatingTemplate I can take a closer look. There must be an entry in there without defined channels.

Biomiha commented 3 years ago

@DillonHammill - apologies for the delay. I've sent it to your email address.

DillonHammill commented 3 years ago

Thanks @Biomiha, looks like your gates are OK. Are you able to send through the output of:

gt <- openCyto::gh_generate_template(gs[[1]])
write.csv(gt, "gatingTemplate.csv", row.names = FALSE)
Biomiha commented 3 years ago

Thanks @DillonHammill. I've sent it across to your email.

DillonHammill commented 3 years ago

Thanks @Biomiha, not sure what is going on here - back gating shouldn't influence the channels in any way. This is very old code and I will be re-writing cyto_plot_gating_scheme() soon.