QuPath Scripting (Classifiers across projects)

Hey QuPath Community,

I am beginning the automation process and it is my goal to have an (almost) fully automated process for a larger set of images at a time (30 or so).

My plan is to write two separate scripts:
One to create a set ROI that I can move around to select the area of interest on each specific slide. The goal is to have a consistent area that can be analyzed and every image to have the same area that undergoes this analysis.

The second script would be to:
Save the images ROI as a .tif
Apply an image J macro to delete white space (this may not be needed anymore)
Run a pixel classification to visualize different objects in the tissue and count how many occurrences (I am still having trouble training this classifier to fully select these objects and may post this problem later in more depth)
Export this ROI data
Save that ROI Image
Run a different pixel classifier to separate other objects the first classifier has trouble differentiating
Export this ROI data
Save that ROI Image

It seems simple enough I think but what I am seeing as a potential problem is the pixel classification tools. I created these classifiers in a project that already has 20 images as I was learning the software and what I could do with it. Now I want to be able to start a new project but use the same final drafts of the classifiers from the first project. From what I have read this doesn’t seem to be possible, but I was wondering if there is a work around so I wouldn’t have to apply my script to 50+ images each time since the first 20 will be running each time I run this script. I believe that I could deselect these images but would rather not so this process could run faster.

Any and all suggestions are greatly appreciated! Thanks!

Quick response:
The classifiers are saved in the project folder under Classifiers. If you want to move them to a new project, all you need to do is move them into the same sub-folder as they were in the original classifiers folder. As long as the file tree is maintained, they will show up under Load classifiers as in the original project and can be called with scripts, etc.

And, in fact, I do strongly recommend creating the classifier in a separate project, so that you do not accidentally overwrite your training data. And you can always go back and add new training data, improve the classifier, and move it over to the “real” project yet again.

2 Likes

I was wondering about this from a previous post, but without images it is hard to advise anything specific. I suspect most things related to white space could be handled within QuPath, though.

Hello!
I have created a classifier, saved it in a file of my project (which has other files also), when I open my project in QuPath
(I can see my saved classifier image) and other files to run that classifier.
Then I click on workflow to create script and go to run script for project, I select files, it runs but nothing happens after this.
Can anyone please suggest how to proceed, I will be much grateful.

best regards,
Awais

Hi @Awais ,

What does your workflow do? Are you saving the images after?
Could you copy paste the QuPath script that you’re running here on the forum?

1 Like

Hello,
Thanks for your kind reply.
Please view attached images and script,

many thanks in advance

(Attachment Doc123.docx is missing)

My email is
aligners79@gmail.com
Please send me message here to send the files.
best regards.

setImageType('BRIGHTFIELD_H_DAB');
setColorDeconvolutionStains('{"Name" : "H-DAB default", "Stain 1" : "Hematoxylin", "Values 1" : "0.65111 0.70119 0.29049 ", "Stain 2" : "DAB", "Values 2" : "0.26917 0.56824 0.77759 ", "Background" : " 255 255 255 "}');
runPlugin('qupath.imagej.detect.nuclei.WatershedCellDetection', '{"detectionImageBrightfield": "Hematoxylin OD",  "requestedPixelSizeMicrons": 0.5,  "backgroundRadiusMicrons": 8.0,  "medianRadiusMicrons": 0.0,  "sigmaMicrons": 1.5,  "minAreaMicrons": 10.0,  "maxAreaMicrons": 400.0,  "threshold": 0.1,  "maxBackground": 2.0,  "watershedPostProcess": true,  "excludeDAB": false,  "cellExpansionMicrons": 5.0,  "includeNuclei": true,  "smoothBoundaries": true,  "makeMeasurements": true}');
runPlugin('qupath.imagej.detect.nuclei.PositiveCellDetection', '{"detectionImageBrightfield": "Hematoxylin OD",  "requestedPixelSizeMicrons": 0.5,  "backgroundRadiusMicrons": 8.0,  "medianRadiusMicrons": 0.0,  "sigmaMicrons": 1.5,  "minAreaMicrons": 10.0,  "maxAreaMicrons": 400.0,  "threshold": 0.1,  "maxBackground": 2.0,  "watershedPostProcess": true,  "excludeDAB": false,  "cellExpansionMicrons": 5.0,  "includeNuclei": true,  "smoothBoundaries": true,  "makeMeasurements": true,  "thresholdCompartment": "Nucleus: DAB OD mean",  "thresholdPositive1": 0.2,  "thresholdPositive2": 0.4,  "thresholdPositive3": 0.6,  "singleThreshold": false}');
runClassifier('\\\\ad.helsinki.fi\\home\\a\\awahab\\Desktop\\This is my project\\classifiers\\classifier.qpclassifier');
setColorDeconvolutionStains('{"Name" : "H-DAB default", "Stain 1" : "Hematoxylin", "Values 1" : "0.65111 0.70119 0.29049 ", "Stain 2" : "DAB", "Values 2" : "0.26917 0.56824 0.77759 ", "Background" : " 255 255 255 "}');
runPlugin('qupath.imagej.detect.nuclei.WatershedCellDetection', '{"detectionImageBrightfield": "Hematoxylin OD",  "requestedPixelSizeMicrons": 0.5,  "backgroundRadiusMicrons": 8.0,  "medianRadiusMicrons": 0.0,  "sigmaMicrons": 1.5,  "minAreaMicrons": 10.0,  "maxAreaMicrons": 400.0,  "threshold": 0.1,  "maxBackground": 2.0,  "watershedPostProcess": true,  "excludeDAB": false,  "cellExpansionMicrons": 5.0,  "includeNuclei": true,  "smoothBoundaries": true,  "makeMeasurements": true}');
runPlugin('qupath.imagej.detect.nuclei.PositiveCellDetection', '{"detectionImageBrightfield": "Hematoxylin OD",  "requestedPixelSizeMicrons": 0.5,  "backgroundRadiusMicrons": 8.0,  "medianRadiusMicrons": 0.0,  "sigmaMicrons": 1.5,  "minAreaMicrons": 10.0,  "maxAreaMicrons": 400.0,  "threshold": 0.1,  "maxBackground": 2.0,  "watershedPostProcess": true,  "excludeDAB": false,  "cellExpansionMicrons": 5.0,  "includeNuclei": true,  "smoothBoundaries": true,  "makeMeasurements": true,  "thresholdCompartment": "Nucleus: DAB OD mean",  "thresholdPositive1": 0.2,  "thresholdPositive2": 0.4,  "thresholdPositive3": 0.6,  "singleThreshold": false}');
runClassifier('\\\\ad.helsinki.fi\\home\\a\\awahab\\Desktop\\This is my project\\classifiers\\classifier.qpclassifier');
setColorDeconvolutionStains('{"Name" : "H-DAB default", "Stain 1" : "Hematoxylin", "Values 1" : "0.65111 0.70119 0.29049 ", "Stain 2" : "DAB", "Values 2" : "0.26917 0.56824 0.77759 ", "Background" : " 255 255 255 "}');
runClassifier('\\\\ad.helsinki.fi\\home\\a\\awahab\\Desktop\\This is my project\\classifiers\\classifier.qpclassifier');
setColorDeconvolutionStains('{"Name" : "H-DAB default", "Stain 1" : "Hematoxylin", "Values 1" : "0.65111 0.70119 0.29049 ", "Stain 2" : "DAB", "Values 2" : "0.26917 0.56824 0.77759 ", "Background" : " 255 255 255 "}');
runClassifier('\\\\ad.helsinki.fi\\home\\a\\awahab\\Desktop\\This is my project\\classifiers\\classifier.qpclassifier');
setColorDeconvolutionStains('{"Name" : "H-DAB default", "Stain 1" : "Hematoxylin", "Values 1" : "0.65111 0.70119 0.29049 ", "Stain 2" : "DAB", "Values 2" : "0.26917 0.56824 0.77759 ", "Background" : " 255 255 255 "}');

If you are just running that script, nothing should happen as there is no annotation created or selected to create the cells inside of.
https://qupath.readthedocs.io/en/latest/docs/concepts/object_hierarchy.html#how-the-object-was-created

1 Like

Hi!
Thanks for reply.
I have created annotations as tumor, other, stroma and white space. I opened my project and opened the parent image (used for classifier) and selected the main triangle frame of annotation (turns yellow) and then go to workflow to run script command? I tried this but did´nt work. My all project is saved.
best regards.

Not sure what this part means.

Selecting an annotation and running that script for the current image should run cell detection 4 times in a row (which seems wasteful as the results will be overwritten).

If you “Run for project” nothing should happen because you have not selected anything within the script. Run for project does not show results in the current image either, as the warning in red text states (in the Run for project dialog).

You can use the Annotations tab to select annotations by their class, and that will show up in the workflow to aid in scripting.

Hello!
many thanks for your valuable suggestions.
Now, my script can be read by other files also. However, in order to run all the new files in the script, it is required to annotate areas of all the files to make the script readable for all files.
best regards.

Not sure what this part means.

Selecting an annotation and running that script for the current image should run cell detection 4 times in a row (which seems wasteful as the results will be overwritten).

If you “Run for project” nothing should happen because you have not selected anything within the script. Run for project does not show results in the current image either, as the warning in red text states (in the Run for project dialog).

You can use the Annotations tab to select annotations by their class, and that will show up in the workflow to aid in scripting.

Hello!
I have one question.
Is there any study which has performed the scoring with intensity or precentage of cells through QuPath classifying analysis ?
And please let me know how to run my prepared classifier script for all images in one go for my project ? OR I would need to run each image separately ?

best regards

Here’s a giant list of papers that used QuPath for many things: How to cite QuPath — QuPath 0.2.3 documentation

Here’s a particularly nice paper that compared QuPath to other software: Ki67 reproducibility using digital image analysis: an inter-platform and inter-operator study - PubMed

And please let me know how to run my prepared classifier script for all images in one go for my project ? OR I would need to run each image separately ?

Batch processing with scripting is a really convenient way to speed up analysis. But, it seems like you are not very familiar with coding? In that case, it might end up being faster for you to do the analysis on each slide in your project one at a time. Go through each image, create the annotations and cells, and then run the classifier, all using the commands in the QuPath interface that you are familiar with. If you want to learn more about creating scripts, please read this explanation of transforming workflows into scripts. I think you are getting tripped up by some of the common problems that are described there.

2 Likes

Hello!
Thanks a lot for your detailed reply.

There are few studies which have performed scoring with QuPath, but not exactly as I wish to do. I have set the three intensities level in my classifier which best corresponds to low, moderate and high for tumor area in any slide. Do You think it is correct way to do that OR any other suggestion ?
And yes, when I can do the analysis individually for each image.

best regards.

If you are classifying cells with 3 different thresholds, then likely what you are trying to calculate is an “h-score”. A google scholar search shows lots of papers that do this with QuPath. In fact, one of the summary statistics automatically calculated in every annotation is the h-score of the cells in that region (if you have labeled the cells using the 3 intensity threshold classifier).

2 Likes

Hello!
Thanks a lot for your reply.
Yes, this is correct, it is the h-score method.
best regards.