Sometimes when a Nextflow task fails in mysterious ways, it can be useful to debug the execution of the bash scripts (.command.run
and .command.sh
) in the task’s work folder extra carefully.
I have found two things that help a lot:
- Commenting out the deletion of the temporary run folder, so that its contents can be explored
- Turning on printing of all executed bash commands, by adding
set -x
in the top of both.command.sh
and.command.run
This can be done with the following bash function, which is supposed to be executed inside a task’s work folder:
function debugnf() {
# Inserts `set -x` on the second line of .command.run and .command.sh
# so that all executed commands are printed during execution.
sed -i '2s/^/set -x\n/' .command.{run,sh};
# Comments out all rm commands in .command.run so temp folder is kept
sed -i 's/rm /#rm /g' .command.run;
}
To use it:
- Check for a failing task’s work folder (similar to
/tmp/nf/work/a3/0e2ea68c421ced4797e00de9e73155
), and change directory into it, e.g. with:cd /tmp/nf/work/a3/0e2ea68c421ced4797e00de9e73155
- Run
debugnf
- Now execute either
.command.run
or.command.sh
using bash, e.g:bash .command.run
Some more context is provided in this blog post.