Skip to content

Commit

Permalink
catch antsBrainExtraction.sh exit error code in stub-run + add stub test
Browse files Browse the repository at this point in the history
  • Loading branch information
gagnonanthony committed Dec 12, 2024
1 parent 83edced commit c8cea3e
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 8 deletions.
18 changes: 12 additions & 6 deletions modules/nf-neuro/betcrop/antsbet/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,9 @@ process BETCROP_ANTSBET {
"""

stub:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"

"""
antsBrainExtraction.sh -h
scil_volume_math.py -h
mrcalc -h
"""
touch ${prefix}__t1_bet.nii.gz
touch ${prefix}__t1_bet_mask.nii.gz
Expand All @@ -62,5 +57,16 @@ process BETCROP_ANTSBET {
mrtrix: \$(mrcalc -version 2>&1 | sed -n 's/== mrcalc \\([0-9.]\\+\\).*/\\1/p')
ants: \$(antsRegistration --version | grep "Version" | sed -E 's/.*v([0-9]+\\+\\).*/\\1/')
END_VERSIONS
function handle_code () {
local code=\$?
ignore=( 1 )
exit \$([[ " \${ignore[@]} " =~ " \$code " ]] && echo 0 || echo \$code)
}
trap 'handle_code' ERR
antsBrainExtraction.sh
scil_volume_math.py -h
mrcalc -h
"""
}
67 changes: 67 additions & 0 deletions modules/nf-neuro/betcrop/antsbet/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,71 @@ nextflow_process {

}

test("betcrop - antsbet - 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( [ "T1w.zip", "transform.zip", "antsbet.zip" ] )
input[1] = "test.load-test-data"
"""
}
}
}

when {
process {
"""
ch_split_test_data = LOAD_DATA.out.test_data_directory
.branch{
t1: it.simpleName == "T1w"
transform: it.simpleName == "transform"
template: it.simpleName == "antsbet"
}
ch_t1 = ch_split_test_data.t1.map{
test_data_directory -> [
[ id:'test' ],
file("\${test_data_directory}/T1w.nii.gz")
]
}
ch_template = ch_split_test_data.template.map{
test_data_directory -> [
[ id: 'test' ],
file("\${test_data_directory}/t1_template.nii.gz"),
file("\${test_data_directory}/t1_brain_probability_map.nii.gz")
]
}
ch_mask = ch_split_test_data.transform.map{
test_data_directory -> [
[ id:'test' ],
file("\${test_data_directory}/t1_to_bet_template_mask.nii.gz")
]
}
ch_transform = ch_split_test_data.transform.map{
test_data_directory -> [
[ id:'test' ],
file("\${test_data_directory}/t1_to_bet_template.mat")
]
}
input[0] = ch_t1
.join(ch_template)
.join(ch_mask)
.join(ch_transform)
"""
}
}

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

}

}
16 changes: 14 additions & 2 deletions modules/nf-neuro/betcrop/antsbet/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,20 @@
],
"meta": {
"nf-test": "0.9.0",
"nextflow": "24.04.4"
"nextflow": "24.10.1"
},
"timestamp": "2024-10-30T17:42:18.337235926"
"timestamp": "2024-12-12T09:39:00.302246"
},
"betcrop - antsbet - stub-run": {
"content": [
[
"versions.yml:md5,9fde1445bc10857db69e440781e58cb7"
]
],
"meta": {
"nf-test": "0.9.0",
"nextflow": "24.10.1"
},
"timestamp": "2024-12-12T10:20:29.72452"
}
}

0 comments on commit c8cea3e

Please sign in to comment.