fish-quant / fq-imjoy

ImJoy plugins to run different smFISH analysis in a user-friendly setting.
https://fq-imjoy.readthedocs.io/en/latest/
MIT License
2 stars 2 forks source link

Assigning RNAs to cells/nuclei not working - only finds 1 cell despite 3 appearing in the mask png file #40

Closed 4symmetry19 closed 2 years ago

4symmetry19 commented 2 years ago

First of all, great tool, although I've been trying for 2 weeks now to get the ImJoy version to work because we currently don't have a Matlab license. Not as intuitive as I thought :D Either way, thanks for all the effort! I'd appreciate your help on my little problem...

I am working on a Mac, Mac OS 12.1

Describe the bug I have a DAPI image (identifier: C4) for which the "Assign RNAs to cells/nuclei" doesn't work. The mask spit out by your fq-segmentation tool (cells and nuclei) is visible for me in FIJI and looks great to me. 3 fat cells and 2 half ones. When I use that together with spot_detection results to assign the RNA to cells and nuclei, however, it works as expected for other images but not for this one. For this one, it only says "1 cell found" and that is reflected by the csv results. I will attach the image.

In the log below, you will see it analyzing/assigning from four different channels of the same image - I will just upload C1 here.

PS: I know that doing spot detection for C4 (DAPI) doesn't make sense, and much less assigning those spots to the cell/nuclei masks, but honestly, I found that your script gives errors or just stops if I don't provide those files, so I just do.

To Reproduce

  1. Load FQ on ImJoy plugin. Enter "Specify Data" under 1. Data specifications (didn't add the channels, spot detection was already done before with the same tool though).
  2. Go to 3. Post-processing. I left the File identifiers the same, only added Channel identifiers C1 for spots and cells, C4 for nuclei. (BTW, is there a way to do this assignment only with nuclei? I don't have a cytosol stain so I used my spots channel for segmenting the cells as well. Mask looks fine though)
  3. Check "Create plots of individual cells" and click "Assign RNAs to cells".
  4. Check log/output - only one cell was detected on these files.

I tried the same with checking the "clean segmentation results" checkbox, but it didn't change the results. Only 1 cell detected.

Logs `[FISH-QUANT][clean_segmentation] received data::

{ "files": [], "file_loaded": "", "path_root": "/Volumes/Extreme SSD/[Secret folders]/", "path_sub_acquisition": "acquisition", "path_sub_analysis": "analysis", "z_first": true, "img_ext": "tif", "channels": [], "ch_name": [], "ch_ident": [], "reg_exp": "(?P.)_(?P.)-(?P.)_\.(?P.)", "current_index": 0, "channel_selected": null, "sigma": [ 1, 0.75 ], "threshold_range": [ 0, 5000, 50 ], "minimum_distance": [ 2, 2 ], "detection_threshold": null, "th_range_min": 0, "th_range_max": 5000, "th_range_nbins": 50, "analyze_clusters": false, "create_plots": true, "show_filtered": true, "show_detection": true, "voxel_size_yx": 64, "voxel_size_z": 500, "psf_size_xy": 200, "psf_size_z": 400, "cluster_alpha": 0.5, "cluster_beta": 2, "foci_radius": 300, "foci_nb_min_spots": 4, "assign_subfolder": "segmentation-results", "assign_subfolder_new":, "assign_ident_spots": "__spots_foci.csv", "assign_ident_cell": "maskcells.png", "assign_ident_nuc": "masknuclei.png", "assign_ch_cell": "C1", "assign_ch_nuc": "C4", "assign_ch_spots": "C1", "clean_segmentation_enable": false, "plot_individual_cells_enable": true }

Analyzing spots detection file /Volumes/Extreme SSD/[Secret folders]/analysis/spot_detection/SC9_C1-SKBR3_E7___spots_foci.csv

/Volumes/Extreme SSD/[Secret folders]/acquisition/SC9_C1-SKBR3E7.tif

number of cells identified: 1

Analyzing spots detection file /Volumes/Extreme SSD/[Secret folders]/analysis/spot_detection/SC9_C2-SKBR3_E7___spots_foci.csv

/Volumes/Extreme SSD/[Secret folders]/acquisition/SC9_C2-SKBR3E7.tif

number of cells identified: 1

Analyzing spots detection file /Volumes/Extreme SSD/[Secret folders]/analysis/spot_detection/SC9_C3-SKBR3_E7___spots_foci.csv

/Volumes/Extreme SSD/[Secret folders]/acquisition/SC9_C3-SKBR3E7.tif

number of cells identified: 1

Analyzing spots detection file /Volumes/Extreme SSD/[Secret folders]/analysis/spot_detection/SC9_C4-SKBR3_E7___spots_foci.csv

/Volumes/Extreme SSD/[Secret folders]/acquisition/SC9_C4-SKBR3E7.tif

number of cells identified: 1`

Screenshots Masks from segmentation-results in FIJI: image

CSV results for the "1 cell" found: image

Sample file: https://drive.google.com/drive/folders/1xPiZGVIaLXm_krVJgpuWMYtUE82LRCH-?usp=sharing

muellerflorian commented 2 years ago

Hey there,

I will have a look at the bug (thanks for the data).

A small comment on the acquisition. Assuming that the meta-data is correct, your pixel size is 62nm. This seems a bit small considering that you are probably using a wide-field microscope. Your pixels are likely too small and you are over-sampling. You could potentially use an objective with less magnification, which would have the advantage that you have more cells per field of view. Not sure what objective you are using (maybe a 100X?).so a 60X would be ideal.

Concerning ImJoy. Any suggestions on what we could improve to make it easier to get started? Better tutorials (what could we add)? We also thought about providing a Docker image, would that help?

Best Florian

4symmetry19 commented 2 years ago

Hi Florian,

thanks for the reply! Curious to see the fix and how it affects my analysis.

Regarding acquisition, yes it's a widefield microscope and these were the recommended settings. Unfortunately, it doesn't have a 60x, only a 40x air objective and that didn't work too well. In general, it's not really a great microscope... But we work with what we have, right :)

Regarding ImJoy, I would have to think about it for longer and write it down as I wasn't keeping track of what I found hard. But I will go into it now step by step, with whatever I remember off the top of my head. As a preface: Please don't take this the wrong way - you created a great tool and I am more than grateful that it exists. I just think with a couple tweaks in the documentation, it will be more easily accessible to a broader audience. I am a biologist, but with technical inclination - I have worked with R, Python and Java for different applications before. Not as a full-on programmer, of course. But I have never worked with Anaconda, Miniconda or Imjoy before and I found the explanations in the docs to be somewhat unclear/confusing. Let's start: It took me a day to figure out RegEx. Maybe a nice explanation in addition to the reference link would be nice, with some more examples? Also, the way you structured the documentation really confused me. The sequence seems a bit off to me sometimes. I went through step by step. You start with the overview, where it says Once you have the Imjoy pluging engine installed, you can..." and linking to a page later in the structure, under Plugin Engine. That already gets me confused - should I read on now, or follow the link now and install? Of course I installed, since I couldn't even try the next "simple steps" to connect ImJoy to the Jupyter engine that were mentioned in the doc. I tried those simple steps then, but the next question was, step 1: Open anaconda terminal. What the hell is an anaconda terminal and how do I open it? Took me half an hour of googling until I just opened terminal on Mac and entered those commands. It might be obvious for you, but for someone who has never worked with Anaconda/Miniconda before, it's not. At least it wasn't for me, and for a biologist I am quite technically inclined. Next, on the overview page it says Installing Plugins, and you mention that you provide an installation link. Of course, there is no link there which prompted another half hour of searching. Since it's mentioned there, I expected to have missed something. Instead, it only pops up later under RNA Detection - Overview. However, as a first time user, with the way it is referenced here as if I should already know it or have it, I lack the faith to continue on and hope it will show up. Do you see my point? Once you get to RNA detection - overview, you start talking about Kaibu etc, although at that step, not everything is installed yet so I won't see that window... confusing, but ok, I went on... And so on it went.

Also, for the actual analysis, I referred back to your Youtube videos on the Matlab FQ version. For me, nobody in my lab is doing smFISH so I have nobody telling me what plausible settings for analysis are, where to set a threshold, etc. I think it would be very helpful and open up your tool to a broader audience to include such guidance or at least references to papers that discuss this in the documentation.

Hope that helps - I think the gist of it is that more examples and "content" oriented guidance (as in how do I scientifically correctly analyse my data, not just technically with the tool), as well as correct sequencing in the docs would really be helpful.

Thanks again for your efforts and responsiveness!

muellerflorian commented 2 years ago

Thanks for the feedback. Our goal is to provide useful tools, and if they are hard to setup, then this goal is not (yet) achieved. I I really appreciate critical feedback to get there. So I don't take this badly at all :-)

We are working on a newer version to integrate some new things in big-fish & correct your bug. I will try to take this opportunity to modify the documentation along the lines you suggested.

4symmetry19 commented 2 years ago

Thanks for taking it that way and working on an improvement! :)

Since we're at it: I would also have liked to see some guidance on how/what to segment with the ImJoy fq-segmentation tool so that I can use it with the FQ tool in ImJoy. I could only get it to work using the segmentation for both cells and nuclei. Only nuclei doesn't work, right? Maybe include that in the doc as well. Also, for me the tool was always looking for _nuclei and _cells files for each spot-channel that I wanted to use to assign RNA to cells. Took me a while to figure out because I had to look into the log file to see that it wasn't finding those nonexistent files. I might be wrong, as a noob here, but the way I saw it it doesn't make sense to do a segmentation with each channel if there is only smFISH signal in that channel - especially for the "nuclei" segmentation result, right? So what I did as a workaround was to copy those files from the cell/nuclei segmentation (I used C1, which actually just has smFISH signal, for the cells, and C4, which has Hoechst staining, for the nuclei). I pasted them and just renamed them from C1 to C2 and C3 for the cells, and from C4 to C1, C2 and C3 for the nuclei. Then the tool found the right files. Did I do that right? Seemed to me like it was doing what I wanted it to do then, at least... But it would be great to a) explain that requirement, b) give an error message, or c) add an option to automatically create renamed files for all your relevant channels when doing the cell/nuclei segmentation.

Maybe none of this makes sense and I'm just being a noob, in that case, I apologize. But I thought I'd leave that here :)

4symmetry19 commented 2 years ago

Not sure if you fixed that but what I mentioned in my last comment about the segmentation asking for files for all channels, seems to work now - so maybe I'd just made a mistake.

muellerflorian commented 2 years ago

Sorry for the long silence. I found the reason for this behavior. It is actually intended. By default, all cells touching the border will be removed in big-fish. This default option was used in the ImJoy plugin. I now added an option for the user to decide if cells touching the border should be removed or not.

This modification will be part of the ongoing pull-request #44 , and should be available early next week.

image

I will also rework the documentation as discussed.

muellerflorian commented 2 years ago

for the ongoing PR, I updated the documentation about regular expressions a bit & added some more information for the example file-structure. for a more detailed introduction, I would like to refer to dedicated ressources explaining & illustrating regular expressions.

#62b7e5c081de9b22792b3de471daa5a94d9ac136

muellerflorian commented 2 years ago

I realize that it is not so obvious for how to get started, since several components are working together. I restructured the documentation a bit more. Hope things are a bit clearer now.

In case this is ok for you now, @4symmetry19, please go ahead and close the issue.