QuPath 0.2.1 Scripting Source Files

Hi,

I’m a student intern in a bioinfomatics lab, and I am currently working on writing some QuPath scripts for our lab.

I was following the guide here on setting up scripting in a real IDE. I chose to do it in Eclipse as that is my Java IDE of choice. Instead of the qupath and jars directories within the QuPath directory, I found that the jars I needed came from lib/app. However, I could not find a location with source versions of those jar files (qupath/sources in the guide). Are those jar files still distributed somewhere? Or would I have to build QuPath from source to take advantage of them?

Thanks,
Arjun

I am using the following paths to set up QuPath in an IDE (which I got after building from source):
QuPath\build\qupath
QuPath\build\resources (instead of the sources directory from the link)

I do think you will need to build from source to get the source code etc… but not sure anymore if you can get the compilation to work without. The best is to try out and see! Good luck :slight_smile:

Seconding what Melvin said… the source jars are no longer included in the distribution, but you should be able to point the IDE towards the QuPath source cloned from GitHub. That’s what I now do when using IntelliJ for scripting, but haven’t yet updated the instructions for v0.2.x.

Building from source won’t really help you unless you change the build.gradle file to also generate source jars… but that can be a bit awkward (i.e. I’m not exactly sure what bits you’d need to change).

PS. I personally much prefer eclipse for development and IntelliJ for scripting… I find Groovy support in eclipse isn’t terribly good.

1 Like

Thanks @melvingelbard @petebankhead for the suggestionns! I will try them out today.

1 Like

I have added

QuPath\build\qupath
QuPath\build\resources

to my IntelliJ project

Any call to a function or method like

// Read BufferedImage region
def server = getCurrentServer()

shows “No candidates found for method call getCurrentServer” in the IDE

@Kai_Wiechen you’d need a static import statement at the top of your script, such as

import static qupath.lib.gui.scripting.QPEx.*

If that doesn’t resolve things, can you explain in more detail exactly what steps you’ve taken?

2 Likes

Dear all,

I have an added question in this line
I have started scripting with IntelliJ and it helps a lot!
I was wondering how I could also get suggestions in setPathClass

I have already added import static qupath.lib.gui.scripting.QPEx.* and have tried out adding some other imports. I also checked out the source code and saw that setPathClass is defined in the
qupath.lib.objects.pathROIObject.java page, but when I add
import qupath.lib.objects.PathROIObject
this doesn’t give me autocompletion for annotations.setPathClass()

Do you have a suggestion which library I should add?

Thanks in advance,
Justin

The completion should happen automatically – no need for further imports… if the variable is of the correct kind :slight_smile:

My guess is that annotations refers to a list and not to a PathObject, and so you don’t see the expected method.

You can run this script on any image containing annotations to see the difference:

def annotations = getAnnotationObjects()

// This will print the methods for a list
println describe(annotations)

// This will print the methods for a path object
def singleAnnotation = annotations[0]
println describe(singleAnnotation)
1 Like

Thanks, I am currently struggling with the script not working correctly to setPathClass and I think what you are saying is also the solution to my problem :slight_smile:

I was trying to set the class of an annotation that is the only one of this class in the project. I tried

target = annotations.findAll {it.isAnnotation() && it.getPathClass() == getPathClass('Positive')}
and as you mention this creates a list…

Is your suggestion of

def annotations = getAnnotationObjects()
def singleAnnotation = annotations[0]

the easiest way to get a single annotation if it is the only one of this class or is there another way to get an annotation as PathObject instead of a list?

1 Like

You could use find instead of findAll – see
http://docs.groovy-lang.org/next/html/documentation/working-with-collections.html#List-Filtering

Although usually I’d probably get the list and check I just have one

if (annotations.size() != 1) {
   println 'Uh-oh, is this meant to happen?!'
}
3 Likes