with include{MyTest}
Cannot find a component with name 'MyTest' in module: .../20230103.nf.class/./class.nf
-- Check script 'test.nf' at line: 2 or see '.nextflow.log' file for more details
without include{MyTest}
No such variable: MyTest
Hi all,
I would like to implement a custom java/groovy code in nextflow to help me document/parse the NF arguments params
. Something like
class ArgumentFactory {
private static final ArgumentFactory INSTANCE = new ArgumentFactory();
public static ArgumentFactory getInstance() { return INSTANCE;}
(...)
}
and in another NF file
ArgumentFactory.getInstance().
name("reference").
description("path to the indexed FASTA reference").
put(params)
and in another NF file
if(params.help) {
ArgumentFactory.getInstance().printUsage();
}
How can I do this in 'pure' NF ? I know I could write a java library and use it using the -lib
parameter, but I'd like to do this in pure NF.
EDIT: here is an implementation:
with include{MyTest}
Cannot find a component with name 'MyTest' in module: .../20230103.nf.class/./class.nf
-- Check script 'test.nf' at line: 2 or see '.nextflow.log' file for more details
without include{MyTest}
No such variable: MyTest
public class MyTest { | |
private static MyTest INSTANCE = new MyTest(); | |
private MyTest() { | |
} | |
public static MyTest getInstance() { | |
return INSTANCE; | |
} | |
public String getMessage() { | |
return "Hello world"; | |
} | |
} | |
process SAY { | |
input: | |
val(msg) | |
script: | |
""" | |
echo "${msg}" | |
""" | |
} |
include {SAY;MyTest} from './class.nf' | |
nextflow.enable.dsl=2 | |
workflow { | |
SAY( MyTest.getInstance().getMessage() ) | |
} |
I think we're doing some similar stuff in nf-core to check for args within the json schema and also to validate params and other things. You might want to look into it.
All our custom groovy stuff is in lib/: https://github.com/nf-core/tools/tree/master/nf_core/pipeline-template/lib
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
thank you Maxime, is it possible to write the code in NF files (!= .groovy) ?
Or if it's groovy file, should they be compiled before running nextflow or will they be compiled at runtime ? I would like to avoid a pre-compile step.
I don't think there's any issue to write groovy code in .nf files. Not sure at all about the when the compilation will happen though...
I added an example above. The code compiles but I cannot use the class
MyTest
within the other NF filetest.nf
(even if if try toinclude
it...)