Skip to content

Commit

Permalink
Merge pull request #68 from gagnonanthony/fixerrorcodes
Browse files Browse the repository at this point in the history
#40 - Catch antsBrainExtraction.sh exit error code in stub-run + add stub test
  • Loading branch information
arnaudbore authored Dec 19, 2024
2 parents 51bb259 + eef148b commit 81ec899
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 54 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
"""
}
72 changes: 66 additions & 6 deletions modules/nf-neuro/betcrop/antsbet/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 - antsbet") {

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 Down Expand Up @@ -68,14 +66,76 @@ nextflow_process {
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
{ assert snapshot(
niftiMD5SUM(process.out.t1.get(0).get(1)),
niftiMD5SUM(process.out.mask.get(0).get(1)),
process.out.versions
).match() }
)
}
}
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() }
)
}

}

}
61 changes: 19 additions & 42 deletions modules/nf-neuro/betcrop/antsbet/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -1,51 +1,28 @@
{
"betcrop - antsbet": {
"content": [
{
"0": [
[
{
"id": "test"
},
"test__t1_bet.nii.gz:md5,bd666c4ce559eab93690131f8b2a9101"
]
],
"1": [
[
{
"id": "test"
},
"test__t1_bet_mask.nii.gz:md5,48c91d01a6c59d48e4ce84431d5e4971"
]
],
"2": [
"versions.yml:md5,9fde1445bc10857db69e440781e58cb7"
],
"mask": [
[
{
"id": "test"
},
"test__t1_bet_mask.nii.gz:md5,48c91d01a6c59d48e4ce84431d5e4971"
]
],
"t1": [
[
{
"id": "test"
},
"test__t1_bet.nii.gz:md5,bd666c4ce559eab93690131f8b2a9101"
]
],
"versions": [
"versions.yml:md5,9fde1445bc10857db69e440781e58cb7"
]
}
"test__t1_bet.nii.gz:md5:header,72167012fa8893d3c3531d5d1245b84a,data,e31b24e1dadf5b067211544fca1f3f01",
"test__t1_bet_mask.nii.gz:md5:header,f7389fe98c9a7e3a87c90b7ca05ea14a,data,1572808125554e50ff73fbe0e28037a9",
[
"versions.yml:md5,9fde1445bc10857db69e440781e58cb7"
]
],
"meta": {
"nf-test": "0.9.0",
"nextflow": "24.04.4"
"nextflow": "24.10.1"
},
"timestamp": "2024-10-30T17:42:18.337235926"
"timestamp": "2024-12-17T20:31:09.4739"
},
"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 81ec899

Please sign in to comment.