Select Annotations by Name

Hi all!

I’m new to QuPath and am struggling with a couple of specific things. The first of these is selecting specific annotations by name. I can use selectAnnotations() to select all annotations on an image, however haven’t worked out what I need to input in the brackets to select, for example, annotations named “Tile 3” and “Tile 47”.

I hope that makes sense so far, but in case it doesn’t some context which will hopefully clarify. I have an IHC stained breast tissue slide, have checked the image type is H-DAB and changed the stain vectors. I then use simple tissue detection, which produces one annotation outlining the whole area of tissue. I then create tiles within this annotation, making each of these tiles an annotation in itself. Then, I’m using this:

n=nObjects()-1
Random rnd = new Random()
a=("Tile “+rnd.nextInt(n)+”; Tile “+rnd.nextInt(n)+”; Tile “+rnd.nextInt(n)+”; Tile “+rnd.nextInt(n)+”; Tile “+rnd.nextInt(n)+”; Tile “+rnd.nextInt(n)+”; Tile “+rnd.nextInt(n)+”; Tile “+rnd.nextInt(n)+”; Tile “+rnd.nextInt(n)+”; Tile "+rnd.nextInt(n))
print(a)

to count the number of annotations and subtract 1 (giving me the number of tiles, by subtracting the annotation of the whole tissue section) and generate 10 random integers between 1 and this maximum value (the number of tiles). a therefore is a list, which ends up looking something like:

Tile 772; Tile 565; Tile 473; Tile 558; Tile 860; Tile 1356; Tile 480; Tile 806; Tile 452; Tile 810

What I need to do from here, is create a script which selects only these annotations. I think the issue I’m having is I don’t know how to specify that when I type “Tile 772” this is the name of the annotation.

From here, I am going to run positive cell detection in only these selected tiles (saving me from running it on the whole slide - and I have ~500 slides in total…my laptop wouldn’t survive!) to give % positive cells for each image.

I hope this all makes sense - please ask me to clarify anything if needed! As I say, I’m new to QuPath, and I’m not the most technologically literate, but I’m trying my best!

Morven :smiley:

It’s not exactly what you asked for, but does this help?

// Randomly select 10 annotations

def annotations = getAnnotationObjects()
annotations.shuffle()
selectObjects(annotations[0..9])

I’m getting back a dreaded error and cannot for the life of me work out why!:

ERROR: Error at line 2: No signature of method: java.util.ArrayList.shuffle() is applicable for argument types: () values:
Possible solutions: size(), size(), sum(), size()

ERROR: Script error
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:49)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at Script128.run(Script128.groovy:3)
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)

What version of QuPath are you using? The script works for me in the latest version (v0.2.3). It gives the error you describe in v0.1.2.

Ahh my apologies - yes, I am using v0.1.2 as it is the one others in my lab use.