Hi, I am trying to create a custom afterScript groovy function that runs after every process (basically, it implements some custom logging and cleanup). It uses a custom class, which I have created in a file in the lib/ subdirectory. However, I can’t figure out how to import the custom class.
Based on some searching (a relevant post here), below I have what I’ve tried. However, I’m not sure how to get groovy code (and particularly the parseClass call) to execute before the configuration is parsed and an ‘unable to resolve class’ error is thrown.
What’s the correct way to do this?
nextflow.config:
process.afterScript = {
customAfterScript()
}
lib/common.groovy:
import groovy.lang.GroovyClassLoader
GroovyClassLoader class_loader = new GroovyClassLoader()
def parseClass = {filename -> class_loader.parseClass(new File(filename))}
CustomClass = parseClass("CustomClass.groovy")
def customAfterScript = {
// do some stuff, then
// fail here
// error: /path/to/lib/common.groovy: linenumber: unable to resolve class CustomClass
// also, I've tried moving the parseClass into this script; no change.
new CustomClass(params.foo)
}
lib/CustomClass.groovy:
class CustomClass{
//do stuff
}