IF Colocalization Calculations for QuPath

Hi all, another script. This one unfortunately does not have a GUI at the moment, but I wanted to get the option for colocalization out there as soon as I had it working. If you find that it is not working for you, please do let me know! It is certainly a bit rough around the edges, and doesn’t check for things like attempting to run the script on brightfield images. It is also fairly slow as it only runs in one thread. The code can be found here, and is intended for 0.2.0m2 (EDIT: Test version for 0.1.2 and 0.1.3 here. Thanks Pete for all of the help!).
How To:
First, have an image with some detections. Currently the script supports general detection objects (all), cells, subcellular objects, tiles (including SLICs), nuclei and cytoplasms. Once you have some objects, go into the script and edit several values so that the script will do what you want it to. You should see something like this:

//Channel numbers are based on cell measurement/channel order in Brightness/contrast menu, starting with 1

int FIRST_CHANNEL = 2

int SECOND_CHANNEL = 4

//CHOOSE ONE: "cell", "nucleus", "cytoplasm", "tile", "detection", "subcell"

//"detection" should be the equivalent of everything

String objectType = "cell"

//These should be figured out for a given sample to eliminate background signal

//Pixels below this value will not be considered for a given channel.

//Used for Manders coefficients only.

ch1Background = 4000

ch2Background = 1500

Pick the two channels you want to perform the colocalization analysis on; these numbers should be the same as the “Channel #” in the measurements list, or can be determined by the order in the Brightness/Display menu.

Next, select the detection type you want to analyze. “detection” would be the most general, and I think will hit everything that isn’t an annotation in the image. Tiles should get both tile objects and any kind of SLIC or other superpixel. Cells, nuclei, and cytoplasm should be fairly self explanatory, though your results might be odd if you are using one of the non-standard cell detections. Check the object types in the measurement list or ask here if you are getting odd results.

To get meaningful Manders coefficients you will need background values for each channel. The simplest way to think about these are that any pixel in a given channel below that value will be ignored when checking for overlap. I highly recommend reading up on colocalization before attempting to interpret the meaning of your results. If anyone has recommendations for short, clear, and to the point references to add here, please let me know and I will include links.
ImageJ Coloc

An example, with pictures!
image
Starting here, I have cells with subcellular detections created from channel 2. I was curious how channels 5 and 6 would colocalize, both within the channel 2 areas, and in general within the cells. All three channels are for cytoplasmic proteins.


The Pearson’s coefficient shows that the 5 and 6 markers are negatively correlated within the channel 2 areas, while the Manders cofficients show that most of the channel 6 stain shows up within the channel 5 stain… within the channel 2 subcellular regions. But is the fact that I looked in the subcellular regions important?

Looking at the cytoplasmic correlation coefficients, we can see that in general, the 5/6 markers are not strongly correlated, though the areas that were “unstained” (background only) do show high correlation. That is something to watch out for! The Manders coefficients for the cytoplasm also show that the channel 6 positive areas are subsets of the channel 5 positive areas, regardless of whether we look in the channel 2 areas alone. It would have been incorrect to draw any strong conclusion that this relationship was unique to the channel 2 subcells! It also could be that my threshold was a bit low on the channel 6 Manders cutoff. I would always recommend testing out different values, or better yet, having a negative control to set your thresholds!

Feedback/criticism/suggestions for improvements encouraged!

Update for 0.2.0m7 here.
https://gist.github.com/Svidro/68dd668af64ad91b2f76022015dd8a45#file-colocalization-of-channels-per-detection-0-2-0m7-groovy

I should note I have been a bit busy and have not had time to fully test/vet this. Please make some noise if there are any problems.

1 Like