From 7b8fb95e764e220967c4ae2414184c4f9dad5aaa Mon Sep 17 00:00:00 2001 From: Anthony Gagnon Date: Thu, 12 Dec 2024 13:02:28 -0500 Subject: [PATCH] catch error in stub for eddy and topup + add stub test --- modules/nf-neuro/preproc/eddy/main.nf | 30 +++++++++++-------- .../nf-neuro/preproc/eddy/tests/main.nf.test | 30 +++++++++++++++++++ .../preproc/eddy/tests/main.nf.test.snap | 12 ++++++++ modules/nf-neuro/preproc/topup/main.nf | 19 +++++++----- .../nf-neuro/preproc/topup/tests/main.nf.test | 28 +++++++++++++++++ .../preproc/topup/tests/main.nf.test.snap | 12 ++++++++ 6 files changed, 111 insertions(+), 20 deletions(-) diff --git a/modules/nf-neuro/preproc/eddy/main.nf b/modules/nf-neuro/preproc/eddy/main.nf index dd1c5ef5..a50fef51 100644 --- a/modules/nf-neuro/preproc/eddy/main.nf +++ b/modules/nf-neuro/preproc/eddy/main.nf @@ -114,32 +114,36 @@ process PREPROC_EDDY { """ stub: - def args = task.ext.args ?: '' def prefix = task.ext.prefix ?: "${meta.id}" """ - scil_volume_math.py -h - maskfilter -h - bet -h - scil_dwi_extract_b0.py -h - scil_gradients_validate_correct_eddy.py -h - scil_dwi_concatenate.py -h - mrconvert -h - scil_dwi_prepare_eddy_command.py -h - scil_header_print_info.py -h - touch ${prefix}__dwi_corrected.nii.gz touch ${prefix}__dwi_eddy_corrected.bval touch ${prefix}__dwi_eddy_corrected.bvec touch ${prefix}__b0_bet_mask.nii.gz - cat <<-END_VERSIONS > versions.yml "${task.process}": scilpy: \$(pip list | grep scilpy | tr -s ' ' | cut -d' ' -f2) mrtrix: \$(dwidenoise -version 2>&1 | sed -n 's/== dwidenoise \\([0-9.]\\+\\).*/\\1/p') fsl: \$(flirt -version 2>&1 | sed -n 's/FLIRT version \\([0-9.]\\+\\)/\\1/p') - END_VERSIONS + + function handle_code () { + local code=\$? + ignore=( 1 ) + exit \$([[ " \${ignore[@]} " =~ " \$code " ]] && echo 0 || echo \$code) + } + trap 'handle_code' ERR + + scil_volume_math.py -h + maskfilter -h + bet -h + scil_dwi_extract_b0.py -h + scil_gradients_validate_correct_eddy.py -h + scil_dwi_concatenate.py -h + mrconvert -h + scil_dwi_prepare_eddy_command.py -h + scil_header_print_info.py -h """ } diff --git a/modules/nf-neuro/preproc/eddy/tests/main.nf.test b/modules/nf-neuro/preproc/eddy/tests/main.nf.test index bfe7eb1b..bc5d31ab 100644 --- a/modules/nf-neuro/preproc/eddy/tests/main.nf.test +++ b/modules/nf-neuro/preproc/eddy/tests/main.nf.test @@ -93,4 +93,34 @@ nextflow_process { ) } } + + test("eddy - stub-run") { + options "-stub-run" + when { + process { + """ + input[0] = LOAD_DATA.out.test_data_directory + .map{ test_data_directory -> [ + [ id:'test', single_end:false ], // meta map + file("\${test_data_directory}/sub-01_dir-AP_dwi.nii.gz", checkIfExists: true), + file("\${test_data_directory}/sub-01_dir-AP_dwi.bval", checkIfExists: true), + file("\${test_data_directory}/sub-01_dir-AP_dwi.bvec", checkIfExists: true), + file("\${test_data_directory}/sub-01_dir-PA_dwi.nii.gz", checkIfExists: true), + file("\${test_data_directory}/sub-01_dir-PA_dwi.bval", checkIfExists: true), + file("\${test_data_directory}/sub-01_dir-PA_dwi.bvec", checkIfExists: true), + file("\${test_data_directory}/sub-01__corrected_b0s.nii.gz", checkIfExists: true), + file("\${test_data_directory}/topup_results_fieldcoef.nii.gz", checkIfExists: true), + file("\${test_data_directory}/topup_results_movpar.txt", checkIfExists: true) + ] + } + """ + } + } + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out.versions).match() } + ) + } + } } diff --git a/modules/nf-neuro/preproc/eddy/tests/main.nf.test.snap b/modules/nf-neuro/preproc/eddy/tests/main.nf.test.snap index 239baba4..617a4012 100644 --- a/modules/nf-neuro/preproc/eddy/tests/main.nf.test.snap +++ b/modules/nf-neuro/preproc/eddy/tests/main.nf.test.snap @@ -62,5 +62,17 @@ "nextflow": "24.04.4" }, "timestamp": "2024-11-21T19:53:14.315721034" + }, + "eddy - stub-run": { + "content": [ + [ + "versions.yml:md5,137e3ce0fd25e5b16de2d8cc5a5aefca" + ] + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.10.1" + }, + "timestamp": "2024-12-12T12:50:30.654366" } } \ No newline at end of file diff --git a/modules/nf-neuro/preproc/topup/main.nf b/modules/nf-neuro/preproc/topup/main.nf index 99fa3412..3299c91b 100644 --- a/modules/nf-neuro/preproc/topup/main.nf +++ b/modules/nf-neuro/preproc/topup/main.nf @@ -73,16 +73,10 @@ process PREPROC_TOPUP { """ stub: - def args = task.ext.args ?: '' def prefix = task.ext.prefix ?: "${meta.id}" def prefix_topup = task.ext.prefix_topup ? task.ext.prefix_topup : "" """ - scil_volume_math.py -h - scil_dwi_extract_b0.py -h - antsRegistrationSyNQuick.sh -h - scil_dwi_prepare_topup_command.py -h - touch ${prefix}__corrected_b0s.nii.gz touch ${prefix}__rev_b0_warped.nii.gz touch ${prefix}__rev_b0_mean.nii.gz @@ -95,7 +89,18 @@ process PREPROC_TOPUP { scilpy: \$(pip list | grep scilpy | tr -s ' ' | cut -d' ' -f2) antsRegistration: \$(antsRegistration --version | grep "Version" | sed -E 's/.*v([0-9]+\\+\\).*/\\1/') fsl: \$(flirt -version 2>&1 | sed -n 's/FLIRT version \\([0-9.]\\+\\)/\\1/p') - END_VERSIONS + + function handle_code () { + local code=\$? + ignore=( 1 ) + exit \$([[ " \${ignore[@]} " =~ " \$code " ]] && echo 0 || echo \$code) + } + trap 'handle_code' ERR + + scil_volume_math.py -h + scil_dwi_extract_b0.py -h + antsRegistrationSyNQuick.sh + scil_dwi_prepare_topup_command.py -h """ } diff --git a/modules/nf-neuro/preproc/topup/tests/main.nf.test b/modules/nf-neuro/preproc/topup/tests/main.nf.test index f404355c..146ceb93 100644 --- a/modules/nf-neuro/preproc/topup/tests/main.nf.test +++ b/modules/nf-neuro/preproc/topup/tests/main.nf.test @@ -95,4 +95,32 @@ nextflow_process { ) } } + + test("topup - stub-run") { + options "-stub-run" + when { + process { + """ + input[0] = LOAD_DATA.out.test_data_directory + .map{ test_data_directory -> [ + [ id:'test', single_end:false ], // meta map + file("\${test_data_directory}/sub-01_dir-AP_dwi.nii.gz", checkIfExists: true), + file("\${test_data_directory}/sub-01_dir-AP_dwi.bval", checkIfExists: true), + file("\${test_data_directory}/sub-01_dir-AP_dwi.bvec", checkIfExists: true), + file("\${test_data_directory}/sub-01_dir-AP_sbref.nii.gz", checkIfExists: true), + file("\${test_data_directory}/sub-01_dir-PA_dwi.nii.gz", checkIfExists: true), + file("\${test_data_directory}/sub-01_dir-PA_dwi.bval", checkIfExists: true), + file("\${test_data_directory}/sub-01_dir-PA_dwi.bvec", checkIfExists: true), + file("\${test_data_directory}/sub-01_dir-PA_sbref.nii.gz", checkIfExists: true)]} + input[1] = [] + """ + } + } + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out.versions).match() } + ) + } + } } diff --git a/modules/nf-neuro/preproc/topup/tests/main.nf.test.snap b/modules/nf-neuro/preproc/topup/tests/main.nf.test.snap index efe20842..171632b7 100644 --- a/modules/nf-neuro/preproc/topup/tests/main.nf.test.snap +++ b/modules/nf-neuro/preproc/topup/tests/main.nf.test.snap @@ -33,6 +33,18 @@ }, "timestamp": "2024-11-01T16:21:18.752887499" }, + "topup - stub-run": { + "content": [ + [ + "versions.yml:md5,1e46217f093e27a6a26cd479f074296b" + ] + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.10.1" + }, + "timestamp": "2024-12-12T11:56:01.860981" + }, "topup_light": { "content": [ "test__corrected_b0s.nii.gz",