drieslab / Giotto

Spatial omics analysis toolbox
https://drieslab.github.io/Giotto_website/
Other
258 stars 98 forks source link

spatInSituPlotPoints segmentation white streaking #628

Closed bhhlee closed 1 year ago

bhhlee commented 1 year ago

Hi Giotto team.

First of all thank you so much for building such a great tool. I have been using Giotto for analysis of our CosMX dataset and have come across an issue in the spatInSituPlotPoints function where the segmentation mask is overlaid correctly, but is accompanied by these white streaks that as far as I know are not in the original segmentation mask.

image

showGiottoImageNames(fovsubset)

# Set up vector of image names
id_set = c('5')
new_names = paste0("fov5", id_set)
image_names = paste0(new_names, '-image')

spatInSituPlotPoints(fovsubset,
                     show_image = TRUE,
                     feats = list('rna' = c('MMP2', 'VEGFA', 'IGF1R',
                                            'MKI67', 'EPCAM', 'KRT8')),
                     feats_color_code = viv10,
                     spat_unit = 'cell',
                     point_size = 0.01,
                     show_polygon = TRUE,
                     use_overlap = FALSE,
                     polygon_feat_type = 'cell',
                     polygon_color = 'white',
                     polygon_line_size = 0.03,
                     save_param = list(base_height = 5,
                                       save_name = '1_inSituFeats'))

I have been using the Nanostring CosMx Subcellular Lung Cancer Tutorial as a first pass analysis and haven't changed any of the code, except use just 1 FOV.

Thank you in advance!

RubD commented 1 year ago

Hi @bhhlee, this seems to be a mask to polygon issue. Do you also see this with our CosMx example dataset? And are your segmentation results any different? If you can share the segmentation mask and composite image files we can likely figure out which settings you should use.

bhhlee commented 1 year ago

Hi @RubD I tried it with the CosMX lung example dataset and did not have this issue.

I'm attaching a google drive link for the segmentation mask and composite image files.

https://drive.google.com/file/d/1I5jsk7zkwalGYQQ5vxfLg4Aoj5csLxH4/view?usp=sharing https://drive.google.com/file/d/11FwG4LIDitmEu9szrwt1xVis7ZV2rdV7/view?usp=sharing

Much appreciated!

RubD commented 1 year ago

Hi @bhhlee,

I've added another parameter remove_unvalid_polygons to our convenience function and set it to TRUE. This should fix your issue, but you'll need to use your development branch for now devtools::install_github("drieslab/Giotto@suite_dev").

Without:

Screenshot 2023-04-05 at 06 28 43

With:

Screenshot 2023-04-05 at 06 28 25

bhhlee commented 1 year ago

Hi @RubD really appreciate the quick response. I'm using the development branch now, but am having issues with the createGiottoCosMxObject.

fov_16 = createGiottoCosMxObject(cosmx_dir = data_path,
                                 data_to_use = 'subcellular', # only subcellular
                                 remove_background_polygon = TRUE,
                                 FOVs = c(16),
                                 instructions = instrs)

I'm getting an error with building the subcellular giotto object:

Loading image information... Image load done [ FOV 016 ] Assigning FOV feature detections... Building subcellular giotto object... Error in list(mask_method = "guess", flip_vertical = TRUE, flip_horizontal = FALSE, : argument 8 is empty

I've been looking through the source code, but couldn't find an eight argument for polygon_mask_list_params. Am I missing something else in my createGiottoInstructions?

Thank you!

RubD commented 1 year ago

I left a , somewhere in the code ... I already pushed a fix. Should work again.

You will need to re-install though and restart your R session.

bhhlee commented 1 year ago

Ah of course. Perfect! It works great now! Thank you so much, I really appreciate the quick responses!