CellProfiler / CellProfiler-plugins

Community-contributed and experimental CellProfiler modules.
http://plugins.cellprofiler.org/
56 stars 67 forks source link

Functionality for RunCellpose to be used in an image-based analysis pipeline #177

Closed jenna-tomkinson closed 1 year ago

jenna-tomkinson commented 1 year ago

Is your feature request related to a problem? Please describe.

The main issue that I am facing is that I am unable to implement RunCellpose into an image-based analysis pipeline for a Cell Painting data set (e.g. segmentation and feature extraction).

This module is the issue because when using Pycytominer to link the single cells between objects (e.g. nuclei and cells) from a sqlite file, there is no way to link the single cells since there are no Parent columns to work with after feature extraction.

Describe the solution you'd like

The solution that I would like is that there be a way for the RunCellpose module to use the nuclei segmentations from a previous module to use when segmenting cells.

The current function of the RunCellpose module (and seemly Cellpose as a whole) currently is to be able to segment objects from images independent of each other. This is evident due to not being able to use the segmented nuclei from one RunCellpose module as the basis to segment out the whole cells in another; you can only use the whole image with all the nuclei for segmentation of cells which I believe is causing the inability to connect single cells.

In all, the solution would be to create the ability to use the RunCellpose module like the already established IdentifyPrimaryObjects and IdentifySecondaryObjects. The ability to detect the "parents" is apart of the CellProfiler segmentation modules, so I wonder if it could be implemented into the RunCellpose module.

Describe alternatives you've considered

The alternative I considered is to instead of creating a database right from my pipeline, I could:

  1. Export the measurements for the nuclei and cells into spreadsheets
  2. Run a "linking" function that would attempt to match the cells to nuclei based on the location center x and y values which would remove any rows (single cells) from the nuclei data frame that do not have a cytoplasm connected to it so that both the nuclei and cells have the same number of single cells
  3. Merge the features into one single data frame and avoid using Pycytominer to link the features together from the sqlite file

The only issue I see with my alternative is that I wouldn't be the most confident in a "linking" function because I would have to set the parameter for how many pixels (+/-) would be considered close enough to connect the nuclei and cell.

Additional context

I would love to try and help with this enhancement, so advice on how I could try and implement this would be very welcome!

As well, I know this could be put under the CellProfiler-plugins as an issue, but I believe this enhancement could add to CellProfiler as a whole. To be able to use Cellpose in traditional Cell Painting pipelines through CellProfiler would be a big upgrade and would save a lot of time for many users that would have had to go through other alternatives.

bethac07 commented 1 year ago

Hey Jenna,

No one would be happier than us if Cellpose could be included in the main program, but it's not technically feasible at this time without making installation much harder for the average user, which we don't believe we can do at this time. The second that's not the case, trust me, it's moving to the main CellProfiler repo.

Does RelateObjects not do what you need with regards to linking? If not, it would be great to hear what the issue is there.

bethac07 commented 1 year ago

PS Thanks for the SUPER thorough writeup!

jenna-tomkinson commented 1 year ago

Hi Beth!

I really appreciate the quick response and the transparency regarding the fact there are technical challenges with Cellpose. I am excited for the day that Cellpose can become apart of the main CellProfiler repo!

Thank you also for guiding me to the RelateObjects module. When I tested with it to relate the Cells to the Nuclei, it was giving very odd results as seen below:

image

image

What I ended up doing to fix my linking issue was to just create a IdentifyTeritaryObjects module to collect the cytoplasm object and remove the RelateObjects module all together. Since the cytoplasm is used to find parent nuclei and cells, then I didn't need the relate objects. This ending up working perfectly and I was able to run the cells.SingleCells function to link the single cells together.

Thank you again @bethac07!

jenna-tomkinson commented 1 year ago

Here is the PR with the CellProfiler pipelines using Cellpose in a traditional Cell Painting image-based analysis pipeline:

https://github.com/WayScience/NF1_SchwannCell_data/pull/38