Convert Script from Qupath 0.2.0 to Qupath 1.20

I have this Script to create the heatmaps which are calculated by deep learning network. This script is in Qupath 0.2.0 but I need to run this for the Qupath 1.2.0. I am not familiar with Qupath scripting, Can you please help me to convert this script to the older version of Qupath?

import qupath.lib.roi.ROIs
import qupath.lib.objects.PathObjects
import qupath.lib.regions.ImagePlane



// Define data file, delimiter & tile size (in pixels)


def path = 'example.csv'

def delim = ';'
def tileWidth = 1024 // Should this be 512? Depends on export resolution
def tileHeight = 1024

// Get the current image data
def imageData = getCurrentImageData()

// Get the image name
def server = imageData.getServer()
def name = server.getMetadata().getName()
if (name.endsWith('.svs'))
    name = name.substring(0, name.length()-4)

// Find the relevant lines containing the image name
def lines = new File(path).readLines()
def header = lines.remove(0).split(delim)
// Parse the tile location
def tiles = []
for (line in lines.findAll{it.contains(name)}) {
    // Parse coordinates
    def split = line.split(delim)
    def coordsString = split[0].substring(split[0].lastIndexOf('_(')+2, split[0].lastIndexOf(').'))
    def coords = coordsString.split(',')
    def x = coords[0] as int
    def y = coords[1] as int
    // Create objects
    def roi = ROIs.createRectangleROI(x, y, tileWidth, tileHeight, ImagePlane.getDefaultPlane())
    def tile = PathObjects.createTileObject(roi)
    def ml = tile.getMeasurementList()
    for (int i = 1; i < header.size(); i++) {
        ml.putMeasurement(header[i], split[i] as double)
    }
    ml.close()
    tiles.add(tile)
}


// Remove any existing objects & add the tiles
clearAllObjects()
addObjects(tiles)
print 'Tiles added for ' + name + ':\t' + tiles.size()

// set extreme colors
def min = PathObjects.createDetectionObject(ROIs.createEmptyROI())
min.getMeasurementList().putMeasurement('cancer', 0)
min.getMeasurementList().putMeasurement('nonCancer', 0)

def max = PathObjects.createDetectionObject(ROIs.createEmptyROI())
max.getMeasurementList().putMeasurement('c'ancer, 1)
max.getMeasurementList().putMeasurement('nonCancer', 1)

addObjects([min, max])
fireHierarchyUpdate()

def toRemove = getDetectionObjects().findAll {it.getROI().isEmpty()}
removeObjects(toRemove, true)

I don’t keep 0.1.2 around anymore (nor is there a csv to test this on), but the main differences I usually see are in the object creation, which would be something more like:

roi = new RectangleROI(x, y, tileWidth, tileHeight)
def tile = new PathDetectionObject(roi)

I am not sure about your min and max objects as I haven’t ever used createEmptyROI(), but otherwise the object creation should follow a similar pattern.

The name probably needs to be obtained differently as well:

name = server.getShortServerName()

along with the import statement
import qupath.lib.objects.PathDetectionObject

Unrelated, but this line looks like it has the quotes wrong:

Thank you a lot. I applied the changes which you mentioned, However, now I got this Error.

ERROR: Error at line 69: Could not find matching constructor for: qupath.lib.objects.PathDetectionObject(java.awt.Rectangle)

ERROR: Script error
    at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1731)
    at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1534)
    at org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite.callConstructor(MetaClassConstructorSite.java:49)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
    at Script39.run(Script39.groovy:70)
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:343)
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:152)
    at qupath.lib.scripting.DefaultScriptEditor.executeScript(DefaultScriptEditor.java:765)
    at qupath.lib.scripting.DefaultScriptEditor.executeScript(DefaultScriptEditor.java:695)
    at qupath.lib.scripting.DefaultScriptEditor.executeScript(DefaultScriptEditor.java:677)
    at qupath.lib.scripting.DefaultScriptEditor.access$400(DefaultScriptEditor.java:136)
    at qupath.lib.scripting.DefaultScriptEditor$2.run(DefaultScriptEditor.java:1029)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

I am importing the PathDetectionObject as you mentioned.

Ah, you are correct, I was missing:
import qupath.lib.roi.RectangleROI
I really do not remember too much about the specifics of 0.1.2, but in case it helps, the script I was basing my recommendations off of is here:
https://gist.github.com/Svidro/ffb6951e70187de5eb007290f61aea4a#file-create-annotation-of-fixed-size-groovy
It was creating an annotation object instead of a detection, but otherwise is very similar to what you are trying to do.