Semi-automated cell creation in high resolution IF analyses

327 views
Skip to first unread message

micros...@gmail.com

unread,
Apr 15, 2018, 5:06:24 PM4/15/18
to QuPath users
Hi all,

It has come up for me a few times recently, so I wanted to share my experiences with generating cells for analysis when cell shape and borders are very important and at high resolution.  Any feedback would be appreciated, as I have not yet actually done any of these analyses, only advised and attempted to streamline the process as much as possible.

So to begin!

1.  Most of these images have been zoomed in, so do not have normal tissue borders.  In these cases, the area of interest is usually everything, and QuPath provides a tool in the Objects menu "Create full image annotation" which is perfect for this situation.  Once you have your full image annotation, as long as you have a nuclear stain, generating the nuclei to use as the base building blocks for your cells should be fairly straightforward.  I have seen images at a variety of bit depths, exposure times/gains/etc, and one thing that helps me during this first step is using Right click in image-> Display->Brightness/Contrast and selecting only the channel that contains my nuclear stain.  Once I have that set up, I can first mouse around while looking at the values in the lower right corner to get a rough idea of where I want my threshold to be, then double click on the "Min display."  Entering a value into the Min Display allows me to define what is "black," and once I am happy that only my nuclei are visible, I can use that value for my "Threshold" in the Cell detection method.   Since i am interested in generating more accurate cell borders than the default expansion, I will use a "Cell expansion" of 0; otherwise the parameters should be whatever you think are appropriate for detecting your cell nuclei.

Note: You will probably want to lock your annotation, especially before heading to step 2.  It will make it easier to move around inside as well.

https://gist.github.com/Svidro/6171d6d24a85539d3af5d417bc928d50#file-step-1-groovy



At this point you should have an annotation area, and cell nuclei detected, and the nuclei should have measurements for all channels.  If they do not, you may need to add them manually to the nuclei using "Add Intensity Measurements"
This script is roughly

2.  Create your cytoplasms.
For this I prefer the Wand Tool, and you may have to play around with the options in Settings (and your zoom level) to get the wand tool to work the best for your particular stain.  In this case I ended up using a Smoothing of 8 and a Sensitivity of 1.5.  This works best when you have a channel that represents the boundaries of the cells you want to create.
One problem I frequently run into is when the cell is too close to a border of the image.  In this case, one of the normal options would be to delete the nuclei altogether, as you aren't necessarily getting the full picture or data for that cell!  However, if you feel that the cell is essentially fully represented within the image, but the wand tool has extended beyond the image, Pete pointed out that you can select both the cell annotation and the whole area annotation (CRTL+click in the viewer, or use the Annotations tab) and then Right click in image->Annotations->Intersect selected annotations.  This action will remove the whole image annotation, but you can reapply that quickly with CTRL+SHIFT+A. I did this three times in the test case shown below.



V1.3 of QuPath ONLY
Finally, when I have two cells that are touching/interacting, and I want to still have a separate "cell" for each, I make use of the Intersect tool once again, by drawing a polygon to represent my estimated border between the two cells.  Then I select the cell created using the Brush tool, and the polygon, and create my hard border.  Next I remove my whole image annotation (this trick does not work within another annotation)



Once you have all of your annotations created around your nuclei, delete your whole image annotation, and proceed to step 3.


Step 3.  Run the following script to merge your annotations into cells
https://gist.github.com/Svidro/6171d6d24a85539d3af5d417bc928d50#file-step-3-groovy
You should get a few area based measurements out of this, and it will restore your whole image annotation



Step 4.  Add mean cytoplasmic values for each channel: again run the following script.  It can be edited to allow for more channels, if needed, in the addColors function.


In this case, Channel 3 was DAPI, so Channel 3 mean is much higher in the nucleus, which provides a sanity check for the values.  For an actual analysis, I probably would have opted for Subcellular detections for this particular image, but this is a start, and now that you have cells, you can do whatever you want from here!  The red channel mean is actually lower in my cytoplasm due to a solid average around the nucleus, while it drops to near zero near some of the outer edges of the cell.  Performing a quick subcellular detection and localization check on this cell shows that the majority of the bright red structures are actually outside the nucleus.



Anyway, at the end of this, you have your cells and can play to your hearts desire.  I recommend saving the initial result though, and backing up the .qpdata file so that you do not have to repeat the hand-drawn part.



Yay!

Auto Generated Inline Image 1
Auto Generated Inline Image 2
Auto Generated Inline Image 3
Auto Generated Inline Image 4
Auto Generated Inline Image 5
Auto Generated Inline Image 6
Auto Generated Inline Image 7

micros...@gmail.com

unread,
Apr 15, 2018, 5:14:33 PM4/15/18
to QuPath users
Whoops, I did forget the Step 4 script!  It can be found with the others, but just in case, here it is:
https://gist.github.com/Svidro/6171d6d24a85539d3af5d417bc928d50#file-step-4-groovy

micros...@gmail.com

unread,
Apr 15, 2018, 5:18:44 PM4/15/18
to QuPath users
Sigh, and a further correction!  The part that only works in 1.3 that shows up during step two should read:
*****************

V1.3 of QuPath ONLY
Finally, when I have two cells that are touching/interacting, and I want to still have a separate "cell" for each, I make use of the Intersect tool once again, by drawing a polygon to represent my estimated border between the two cells.  Then I select the cell created using the Brush tool, and the polygon, and create my hard border.  Next I remove my whole image annotation (this trick does not work within another annotation)
[Image here]
You can then use the "Shift" key while drawing the second cell annotation area in order to draw it without overlapping with the first cell's annotation area. 
*******************
Again, I believe this only works in version 1.3.
Reply all
Reply to author
Forward
0 new messages