Annotation import not working

Hi Forum,
I use Qupath 0.2.2. The script for batch import of annotation suddenly not working anymore. Could anyone suggest a solution. Many thanks in advance.
Sincerely,
Sabrina

import qupath.lib.scripting.QP
import qupath.lib.geom.Point2
import qupath.lib.roi.PolygonROI
import qupath.lib.objects.PathAnnotationObject
import qupath.lib.images.servers.ImageServer

//Aperio Image Scope displays images in a different orientation
def rotated = false

def server = QP.getCurrentImageData().getServer()
def h = server.getHeight()
def w = server.getWidth()

// need to add annotations to hierarchy so qupath sees them
def hierarchy = QP.getCurrentHierarchy()

//Prompt user for exported aperio image scope annotation file
def path = server.getURIs().getAt(0).getPath(); // HERE
path = path.substring(0, path.lastIndexOf(".")) + “.xml” // HERE
def file = new File(path)
def text = file.getText()

def list = new XmlSlurper().parseText(text)

list.Annotation.each {

it.Regions.Region.each { region ->

    def tmp_points_list = []

    region.Vertices.Vertex.each{ vertex ->

        if (rotated) {
            X = vertex.@Y.toDouble()
            Y = h - vertex.@X.toDouble()
        }
        else {
            X = vertex.@X.toDouble()
            Y = vertex.@Y.toDouble()
        }
        tmp_points_list.add(new Point2(X, Y))
    }

    def roi = new PolygonROI(tmp_points_list)

    def annotation = new PathAnnotationObject(roi)

    hierarchy.addPathObject(annotation, false)
}

}

When was the last time it worked?

What is the source of the script? It’s not built-in to QuPath, or an official part of the software. It looks like it was written for v0.1.2.

What error message do you see?

1 Like

Hi Pete,
the script was from this thread:Importing batch annotations (xml) from a folder

the error message it gives:
ERROR: FileNotFoundException at line 23: ~ge46xaw\TUM-PC\all doc\Projects\Project_Tanja\mouse\ki67\image\2020-3_48-1_MCPT1.xml (Das System kann den angegebenen Pfad nicht finden)

ERROR: java.base/java.io.FileInputStream.open0(Native Method)
java.base/java.io.FileInputStream.open(Unknown Source)
java.base/java.io.FileInputStream.(Unknown Source)
groovy.util.CharsetToolkit.(CharsetToolkit.java:77)
org.codehaus.groovy.runtime.ResourceGroovyMethods.newReader(ResourceGroovyMethods.java:1780)
org.codehaus.groovy.runtime.ResourceGroovyMethods.getText(ResourceGroovyMethods.java:591)
org.codehaus.groovy.runtime.dgm$1040.invoke(Unknown Source)
org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:247)
org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130)
Script3.run(Script3.groovy:24)
org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317)
org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:155)
qupath.lib.gui.scripting.DefaultScriptEditor.executeScript(DefaultScriptEditor.java:926)
qupath.lib.gui.scripting.DefaultScriptEditor.executeScript(DefaultScriptEditor.java:859)
qupath.lib.gui.scripting.DefaultScriptEditor.executeScript(DefaultScriptEditor.java:782)
qupath.lib.gui.scripting.DefaultScriptEditor$ProjectTask.call(DefaultScriptEditor.java:1428)
qupath.lib.gui.scripting.DefaultScriptEditor$ProjectTask.call(DefaultScriptEditor.java:1375)
javafx.concurrent.Task$TaskCallable.call(Task.java:1425)
java.base/java.util.concurrent.FutureTask.run(Unknown Source)
java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
java.base/java.util.concurrent.FutureTask.run(Unknown Source)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.base/java.lang.Thread.run(Unknown Source)

It looks like the script can’t find your file.
At line 23, make sure that the path points to your actual file.
If I remember correctly, this is the reason why I added // HERE as a comment next to it.

1 Like

I went back to version 0.2.0 and use the same script without giving file path and it works. but for future, if i use later version (0.2.3), in that case, could you tell how to mention file path?
Sincerely,
Sabrina

This seems to be the path that you give it: ~ge46xaw\TUM-PC\all doc\Projects\Project_Tanja\mouse\ki67\image\2020-3_48-1_MCPT1.xml
Is there a file at this location? Can you open it?

You might want to instead give it a full path manually? Just to be sure…

path = "your/full/path.xml"
1 Like