Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#40 - Catch errors in stub for fastseg, fsreconall, and fastsurfer + add stub tests #77

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion modules/nf-neuro/registration/synthregistration/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ process REGISTRATION_SYNTHREGISTRATION {
label 'process_high'

container "freesurfer/synthmorph:3"
containerOptions "--entrypoint '' --env PYTHONPATH='/freesurfer/env/lib/python3.11/site-packages'"
containerOptions {
(workflow.containerEngine == 'docker') ? '--entrypoint "" --env PYTHONPATH="/freesurfer/env/lib/python3.11/site-packages"' : "--env PYTHONPATH='/freesurfer/env/lib/python3.11/site-packages'"
}

input:
tuple val(meta), path(moving), path(fixed)
Expand Down
13 changes: 10 additions & 3 deletions modules/nf-neuro/segmentation/fastseg/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ process SEGMENTATION_FASTSEG {
def prefix = task.ext.prefix ?: "${meta.id}"

"""
fast -h
scil_volume_math.py -h

touch ${prefix}__mask_wm.nii.gz
touch ${prefix}__mask_gm.nii.gz
touch ${prefix}__mask_csf.nii.gz
Expand All @@ -69,5 +66,15 @@ process SEGMENTATION_FASTSEG {
scilpy: 2.0.0
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

fast -h
scil_volume_math.py -h
"""
}
23 changes: 23 additions & 0 deletions modules/nf-neuro/segmentation/fastseg/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,27 @@ nextflow_process {
)
}
}
test("segmentation - fastseg - 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}/T1w.nii.gz", checkIfExists: true,),
[]
]
}
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out.versions).match() }
)
}
}
}
12 changes: 12 additions & 0 deletions modules/nf-neuro/segmentation/fastseg/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,17 @@
"nextflow": "24.04.4"
},
"timestamp": "2024-09-04T20:03:24.730234"
},
"segmentation - fastseg - stub-run": {
"content": [
[
"versions.yml:md5,e9c2afb5537207544dc1b54cbdc389a4"
]
],
"meta": {
"nf-test": "0.9.0",
"nextflow": "24.10.1"
},
"timestamp": "2024-12-12T14:01:36.729872"
}
}
33 changes: 22 additions & 11 deletions modules/nf-neuro/segmentation/fastsurfer/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@ process SEGMENTATION_FASTSURFER {
label 'process_single'

container "${ 'deepmi/fastsurfer:cpu-v2.2.0' }"

containerOptions '--entrypoint ""'
containerOptions {
(workflow.containerEngine == 'docker') ? '--entrypoint ""' : ''
}

input:
tuple val(meta), path(anat), path(fs_license)

output:
tuple val(meta), path("*_fastsurfer") , emit: fastsurferdirectory
path "versions.yml" , emit: versions
tuple val(meta), path("*_fastsurfer") , emit: fastsurferdirectory
path "versions.yml" , emit: versions

when:
task.ext.when == null || task.ext.when

script:
def prefix = task.ext.prefix ?: "${meta.id}"
def acq3T = task.ext.acq3T ? "--3T" : ""
def FASTSURFER_HOME = "/fastsurfer"
def SUBJECTS_DIR = "${prefix}_fastsurfer"
def prefix = task.ext.prefix ?: "${meta.id}"
def acq3T = task.ext.acq3T ? "--3T" : ""
def FASTSURFER_HOME = "/fastsurfer"
def SUBJECTS_DIR = "${prefix}_fastsurfer"
"""
mkdir ${prefix}_fastsurfer/
$FASTSURFER_HOME/run_fastsurfer.sh --allow_root \
Expand All @@ -38,14 +39,24 @@ process SEGMENTATION_FASTSURFER {
"""

stub:
def prefix = task.ext.prefix ?: "${meta.id}"
def prefix = task.ext.prefix ?: "${meta.id}"
def FASTSURFER_HOME = "/fastsurfer"

"""
$FASTSURFER_HOME/run_fastsurfer.sh --version
mkdir ${prefix}_fastsurfer/

cat <<-END_VERSIONS > versions.yml
"${task.process}":
fastersurfer: 2.2.0+9f37d02
fastersurfer: \$($FASTSURFER_HOME/run_fastsurfer.sh --version)
END_VERSIONS

function handle_code () {
local code=\$?
ignore=( 1 )
exit \$([[ " \${ignore[@]} " =~ " \$code " ]] && echo 0 || echo \$code)
}
trap 'handle_code' ERR

$FASTSURFER_HOME/run_fastsurfer.sh --version
"""
}
23 changes: 23 additions & 0 deletions modules/nf-neuro/segmentation/fastsurfer/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,27 @@ nextflow_process {
)
}
}

test("segmentation - fastsurfer - stub-run") {
options "-stub-run"
when {
process {
"""
input[0] = LOAD_DATA.out.test_data_directory.map{
test_data_directory -> [
[ id:'test' ],
file("\${test_data_directory}/anat_image.nii.gz"),
file("\${test_data_directory}/license.txt")
]
}
"""
}
}
then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out.versions).match() }
)
}
}
}
12 changes: 12 additions & 0 deletions modules/nf-neuro/segmentation/fastsurfer/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
{
"segmentation - fastsurfer - stub-run": {
"content": [
[
"versions.yml:md5,b263ce2ef1818492be3805ba8e49b50f"
]
],
"meta": {
"nf-test": "0.9.0",
"nextflow": "24.10.1"
},
"timestamp": "2024-12-12T13:38:50.551338"
},
"segmentation - fastsurfer": {
"content": [
"test_fastsurfer",
Expand Down
11 changes: 9 additions & 2 deletions modules/nf-neuro/segmentation/fsreconall/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,20 @@ process SEGMENTATION_FSRECONALL {
stub:
def prefix = task.ext.prefix ?: "${meta.id}"
"""
recon-all --help

mkdir ${prefix}__recon_all

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

recon-all --help
"""
}
26 changes: 26 additions & 0 deletions modules/nf-neuro/segmentation/fsreconall/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,30 @@ nextflow_process {

}

test("segmentation - fsreconall - stub-run") {
options "-stub-run"
when {
config "./nextflow_debug.config"

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"),
file("\${test_data_directory}/license.txt")
]}
"""
}
}

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

}

}
12 changes: 12 additions & 0 deletions modules/nf-neuro/segmentation/fsreconall/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
{
"segmentation - fsreconall - stub-run": {
"content": [
[
"versions.yml:md5,2a7185588fa8c664d53c4c08637285e6"
]
],
"meta": {
"nf-test": "0.9.0",
"nextflow": "24.10.1"
},
"timestamp": "2024-12-12T13:55:39.259005"
},
"segmentation - fsreconall": {
"content": [
"test__recon_all",
Expand Down
Loading