From f5ed7c96a5b530ed42348458cfff9990a9fa769d Mon Sep 17 00:00:00 2001 From: Kelly Sovacool Date: Wed, 16 Oct 2024 12:00:31 -0400 Subject: [PATCH] fix: parse workflow attributes outside groovy function --- bin/crispin | 5 +++++ lib/Utils.groovy | 7 +++---- main.nf | 4 +++- main.py | 16 ++++++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100755 bin/crispin create mode 100755 main.py diff --git a/bin/crispin b/bin/crispin new file mode 100755 index 0000000..8fcdf75 --- /dev/null +++ b/bin/crispin @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +TOOLDIR=$(realpath $(dirname $(dirname ${BASH_SOURCE}))) + +${TOOLDIR}/main.py "$@" diff --git a/lib/Utils.groovy b/lib/Utils.groovy index db78a83..acae2da 100644 --- a/lib/Utils.groovy +++ b/lib/Utils.groovy @@ -1,8 +1,7 @@ class Utils { // run spooker for the workflow - public static String spooker(workflow) { - def pipeline_name = "${workflow.manifest.name.tokenize('/')[-1]}" - def command_string = "spooker ${workflow.launchDir} ${pipeline_name}" + public static String spooker(launch_dir, pipeline_name) { + def command_string = "spooker ${launch_dir} ${pipeline_name}" def out = new StringBuilder() def err = new StringBuilder() try { @@ -12,7 +11,7 @@ class Utils { } catch(IOException e) { err = e } - new FileWriter("${workflow.launchDir}/log/spooker.log").with { + new FileWriter("${launch_dir}/log/spooker.log").with { write("${out}\n${err}") flush() } diff --git a/main.nf b/main.nf index b2d4d30..f808523 100644 --- a/main.nf +++ b/main.nf @@ -28,7 +28,9 @@ include { DRUGZ } from './modules/local/drugz.nf' workflow.onComplete { if (!workflow.stubRun && !workflow.commandLine.contains('-preview')) { println "Running spooker" - def message = Utils.spooker(workflow) + def pipeline_name = "${workflow.manifest.name.tokenize('/')[-1]}" + def launch_dir = "${workflow.launchDir}" + def message = Utils.spooker(launch_dir, pipeline_name) if (message) { println message } diff --git a/main.py b/main.py new file mode 100755 index 0000000..2b8c3f7 --- /dev/null +++ b/main.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +import os +import re +import sys + +# add script directory to the path to allow champagne CLI to work out-of-the-box +# without the need to install it via pip first +SCRIPT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "src") +sys.path.append(SCRIPT_DIR) +from src.__main__ import main + +if ( + __name__ == "__main__" +): # this block is adapted from the executable file created by `pip install` + sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0]) + sys.exit(main())