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)

// Remove any existing objects & add the 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])

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(
    at groovy.lang.MetaClassImpl.invokeConstructor(
    at org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite.callConstructor(
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(
    at qupath.lib.scripting.DefaultScriptEditor.executeScript(
    at qupath.lib.scripting.DefaultScriptEditor.executeScript(
    at qupath.lib.scripting.DefaultScriptEditor.executeScript(
    at qupath.lib.scripting.DefaultScriptEditor.access$400(
    at qupath.lib.scripting.DefaultScriptEditor$
    at java.util.concurrent.Executors$
    at java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.util.concurrent.ThreadPoolExecutor$

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:
It was creating an annotation object instead of a detection, but otherwise is very similar to what you are trying to do.