BodenmillerGroup / cytomapper

R package for visualization of highly multiplexed imaging data
https://bodenmillergroup.github.io/cytomapper/
31 stars 9 forks source link

CytomapperShiny gating only applies to one ROI of the 6 #61

Closed tessbrodie closed 2 years ago

tessbrodie commented 2 years ago

Thanks for your great IMC analysis tools and we tried copy pasting the script from the IMC data analysis workflow website for cytomapperShiny and everything seems to work fine until we look at the number of cells labeled per patient. Our gated populations only apply to one ROI each, instead of applying to all ROIs.

Number of cells labeled per patient

table(spe$cell_labels, spe$patient_id)

                             220525_segmentationkit_testonNASHmice_001

B cells 27 CD11b positive no F480 or Ly6G 0 CD31 endothelial cells 0 Cholangiocytes 0 Hepatocytes 0 Kupffer cells 0 LSECs 0 neutrophils 0 T cells 19 unlabeled 2547

                             220525_segmentationkit_testonNASHmice_002

B cells 0 CD11b positive no F480 or Ly6G 0 CD31 endothelial cells 0 Cholangiocytes 41 Hepatocytes 0 Kupffer cells 0 LSECs 0 neutrophils 0 T cells 0 unlabeled 2311

Are we supposed to download a given gate for each ROI in the shiny? Or did we need to edit the script to avoid this? Also, it would be really helpful if after you gate a population in the Shiny, the cells would be taken out of the gating scheme so you do not have this issue with doublets that you mention.

Thanks again for your help and support, Best, Tess

nilseling commented 2 years ago

Hi @tessbrodie yes, you will need to download one gate per ROI and per cell type. It's implemented like this since we often detect patient specific staining differences or ROI specific effects such as a differential spatial overlap between markers. If you want to apply a defined gate across all cells you will need to load the shiny app without the masks and images and gate across all cells by setting an img_id which is the same for all cells.

I'll think how to best implement what you suggest but it might not be straight forward. Thanks for the suggestion!

tessbrodie commented 2 years ago

Thanks for the quick reply and I did not realize this could be on purpose, but I see your point. The issue here is how to do this when you have hundreds of ROI? We would like to try your idea of applying an img_id, but if we cannot see the individual masks and images from each ROI and if all cells are merged, it would be hard to do the gating. Is there a way you could add a button in the Shiny for applying the gates to all ROI?
Again, thanks so much for your great tools!

nilseling commented 2 years ago

So you want to visually inspect the gate on all images? You can set the gate and the switch between images by clicking the right and left button or by selecting the image name. If you are happy with your gate either save one object and apply the gate (which is stored in metadata(spe)) computationally to all your cells or open the app again and set the exact same gate. You see the boundaries directly under each plot.

tessbrodie commented 2 years ago

Sorry for the late response and I think we would like to apply our gate (B cells, for example) computationally to all our cells but we don't know how to do this. Would you mind sharing an example of what the code might look like to do this?

nilseling commented 2 years ago

Hi @tessbrodie,

so there are two ways:

  1. via gating:
sce$all <- "all"
cytomapperShiny(object = sce, img_id = "all", cell_id = "ObjectNumber")

then you gate all CD20+ cells

  1. programmatically:
gate <- metadata(gated_sce)$cytomapper_gate_1$gate
Bcells <- assay(sce, "exprs")["CD20",] < gate["CD20","max"] & assay(sce, "exprs")["CD20",] > gate["CD20","min"]

Does that help?

tessbrodie commented 2 years ago

That helps a lot, thanks Nils!