Skip to content

Commit

Permalink
Merge pull request #70 from gagnonanthony/synthbeterror
Browse files Browse the repository at this point in the history
#40 - Catch exit code error for `betcrop/synthstrip` + stub run test
  • Loading branch information
arnaudbore authored Dec 19, 2024
2 parents 81ec899 + 3c29e13 commit fb6f35a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
11 changes: 9 additions & 2 deletions modules/nf-neuro/betcrop/synthbet/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,21 @@ process BETCROP_SYNTHBET {
def prefix = task.ext.prefix ?: "${meta.id}"

"""
mri_synthstrip -h
touch ${prefix}__bet_image.nii.gz
touch ${prefix}__brain_mask.nii.gz
cat <<-END_VERSIONS > versions.yml
"${task.process}":
Freesurfer: \$(mri_convert -version | grep "freesurfer" | sed -E 's/.* ([0-9]+\\.[0-9]+\\.[0-9]+).*/\\1/')
END_VERSIONS
function handle_code () {
local code=\$?
ignore=( 1 )
exit \$([[ " \${ignore[@]} " =~ " \$code " ]] && echo 0 || echo \$code)
}
trap 'handle_code' ERR
mri_synthstrip -h
"""
}
37 changes: 34 additions & 3 deletions modules/nf-neuro/betcrop/synthbet/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ nextflow_process {
tag "subworkflows/load_test_data"

test("betcrop - synthbet") {

setup {
run("LOAD_TEST_DATA", alias: "LOAD_DATA") {
script "../../../../../subworkflows/nf-neuro/load_test_data/main.nf"
Expand All @@ -26,7 +25,6 @@ nextflow_process {
}
}
}

when {
process {
"""
Expand All @@ -40,12 +38,45 @@ nextflow_process {
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}
}

test("betcrop - synthbet - stub-run") {
options "-stub-run"
setup {
run("LOAD_TEST_DATA", alias: "LOAD_DATA") {
script "../../../../../subworkflows/nf-neuro/load_test_data/main.nf"
process {
"""
input[0] = Channel.from( [ "freesurfer.zip" ] )
input[1] = "test.load-test-data"
"""
}
}
}
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}/anat_image.nii.gz"),
[]
]
}
"""
}
}
then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out.versions).match() }
)
}
}
}
14 changes: 13 additions & 1 deletion modules/nf-neuro/betcrop/synthbet/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
{
"betcrop - synthbet - stub-run": {
"content": [
[
"versions.yml:md5,c639461870ca534b5105f61d672f740f"
]
],
"meta": {
"nf-test": "0.9.0",
"nextflow": "24.10.1"
},
"timestamp": "2024-12-12T10:54:37.644838"
},
"betcrop - synthbet": {
"content": [
{
Expand Down Expand Up @@ -52,4 +64,4 @@
},
"timestamp": "2024-11-25T18:19:01.459548926"
}
}
}

0 comments on commit fb6f35a

Please sign in to comment.