I am new to the Nextflow. I want to define a environment a in the process A:
process define_env {
output:
env var_a
"""
echo var_a="test" > var_file.txt
source var_file.txt
"""
}
And then I want to call environment var_a in the following process:
process call_var {
"""
echo This is a $var_a.
"""
}
//And run two processes
workflow {
define_env()
call_var()
}
It reports the error: No such variable: var_a. Could you please help me to figure out how to fix it?
Thanks a lot!
Every processing environment is different, so to my knowledge environmental variables will need to be defined for each process you use.
If you're creating the file
var_file.txt, you can output the file usingpath(var_file.txt)in the output declaration. In the processcall_var, you can then usepath(var_file.txt)in the input declaration but would need to amend your workflow declaration so thatcall_vartakes the output of the first process.An alternative if you are using the same env variable in all processes would be to define it in the config file and export it as an environmental variable in each process (i.e.,
export ${params.global_variable}=testin each process. You can even use thebeforeScriptdirective to ensure it's read into the environment in each process.