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:

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))

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()

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(
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(
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$

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.