Anyone using this would want to edit almost all of the image data and cell detection to tailor it to their own project, but those parts can be fairly easily swapped out.
import static qupath.lib.scripting.QP.*;
import static qupath.lib.scripting.QPEx.*;
//Set the base image information, since you are not building off of a .qpdata files, you must include these
//Therefor, this script will currently only work well on one type of known image.
//Future work: consider checking the entire annotation area for estimating stain vectors and accept default result.
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 "}');
//Stuff you want to do here. In this case, I detect tissue at a fairly dark threshold, and then select the annotation
//to run a basic cell detection
runPlugin('qupath.imagej.detect.tissue.SimpleTissueDetection2', '{"threshold": 220, "requestedPixelSizeMicrons": 5.0, "minAreaMicrons": 1000000.0, "maxHoleAreaMicrons": 1000000.0, "darkBackground": false, "smoothImage": true, "medianCleanup": true, "dilateBoundaries": false, "smoothCoordinates": true, "excludeOnBoundary": false, "singleAnnotation": true}');
selectAnnotations();
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}');
//Save the results to a predetermined folder
saveAnnotationMeasurements('D:\\Results\\Data',)
saveDetectionMeasurements('D:\\Results\\Data',)
import subprocess
import os
#Work from QuPath installation directory
os.chdir(r"C:\\Program Files\\QuPath\\app")
script = r"D:\\Script\\NoGUITest.groovy"
imageDirectory = r"D:\\Images to process\\"
fileList = os.listdir(imageDirectory)
for file in fileList:
imageFile = imageDirectory + file
subprocess.call(["java", "-jar", "QuPathApp.jar", '-image', imageFile, "-script", script])
import subprocess
import os
#Work from QuPath installation directory
os.chdir(r"C:\\Program Files\\QuPath\\app")
imageDirectory = r'D:\\Images to process\\'
script = r"D:\\Script\\NoGUITest.groovy"
fileList = os.listdir(imageDirectory)
for file in fileList:
imageFile = imageDirectory+
file
movedImage = 'D:\\Results\\Processed Images\\'+file
subprocess.call(["java", "-jar", "QuPathApp.jar", '-image', imageFile, "-script", script])
os.rename(imageFile, movedImage)
import subprocess
import os
import time
#Work from QuPath installation directory
os.chdir(r"C:\\Program Files\\QuPath\\app")
imageDirectory = r'D:\\Images to process\\'
script = r"D:\\Script\\NoGUITest.groovy"
minutesBetweenChecks = 30
//a slight delay at start
time.sleep(30)
while 1:
fileList = os.listdir(imageDirectory)
for file in fileList:
imageFile = imageDirectory+file
movedImage = 'D:\\Results\\Processed Images\\'+file
subprocess.call(["java", "-jar", "QuPathApp.jar", '-image', imageFile, "-script", script])
os.rename(imageFile, movedImage)
time.sleep(minutesBetweenChecks*60)
import qupath.lib.scripting.QP;import groovy.util.*;
import groovy.json.JsonSlurper;def textFile = "test.txt"
def inputFile= new File(textFile)def InputJSON = new JsonSlurper().parseText(inputFile.text)InputJSON.each{ println it }
Error:Script1.groovy: 3: unable to resolve class groovy.json.JsonSlurper
INFO: class groovy.json.internal.LazyMap
It's also worth noting that when you use the java -jar command line option to run your Java program as an executable JAR, then the CLASSPATH environment variable will be ignored, and also the -cp and -classpath switches will be ignored. In this case, you can set your Java classpath in the META-INF/MANIFEST.MF file by using the Class-Path attribute. In short Class-path attribute in manifest file overrides classpath specified by -cp, -classpath or CLASSPATH environment variable.
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getQuPath() is applicable for argument types: () values: []
Possible solutions: getAt(java.lang.String), getClass()
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:155)
at qupath.QuPath.main(Unknown Source)
javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method getAvailablePathClasses() on null object
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:155)
at qupath.QuPath.main(Unknown Source)
Caused by: javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method getAvailablePathClasses() on null object