Skip to content

Commit

Permalink
niftiMD5SUM for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anroy1 committed Sep 10, 2024
1 parent 4bfc888 commit 6f157fd
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 30 deletions.
52 changes: 30 additions & 22 deletions subworkflows/nf-scil/anatomical_segmentation/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ workflow ANATOMICAL_SEGMENTATION {

ch_versions = Channel.empty()

if ( ch_image && ch_freesurferseg ) {
error('Both input channels cannot be passed simultaneously')
}

if ( ch_freesurferseg ) {
// ** Freesurfer segmentation ** //
SEGMENTATION_FREESURFERSEG ( ch_freesurferseg )
Expand All @@ -31,31 +35,35 @@ workflow ANATOMICAL_SEGMENTATION {
gm_map = Channel.empty()
csf_map = Channel.empty()
}
else if ( params.run_surgery ) {
// ** Freesurfer synthseg segmentation ** //
SEGMENTATION_SYNTHSEG ( ch_image )
ch_versions = ch_versions.mix(SEGMENTATION_SYNTHSEG.out.versions.first())

// ** Setting outputs ** //
wm_mask = SEGMENTATION_SYNTHSEG.out.wm_mask
gm_mask = SEGMENTATION_SYNTHSEG.out.gm_mask
csf_mask = SEGMENTATION_SYNTHSEG.out.csf_mask
wm_map = Channel.empty()
gm_map = Channel.empty()
csf_map = Channel.empty()
}
else {
// ** FSL fast segmentation ** //
SEGMENTATION_FASTSEG ( ch_image )
ch_versions = ch_versions.mix(SEGMENTATION_FASTSEG.out.versions.first())
if ( params.run_surgery ) {
// ** Freesurfer synthseg segmentation ** //
SEGMENTATION_SYNTHSEG ( ch_image )
ch_versions = ch_versions.mix(SEGMENTATION_SYNTHSEG.out.versions.first())

// ** Setting outputs ** //
wm_mask = SEGMENTATION_FASTSEG.out.wm_mask
gm_mask = SEGMENTATION_FASTSEG.out.gm_mask
csf_mask = SEGMENTATION_FASTSEG.out.csf_mask
wm_map = SEGMENTATION_FASTSEG.out.wm_map
gm_map = SEGMENTATION_FASTSEG.out.gm_map
csf_map = SEGMENTATION_FASTSEG.out.csf_map
// ** Setting outputs ** //
wm_mask = SEGMENTATION_SYNTHSEG.out.wm_mask
gm_mask = SEGMENTATION_SYNTHSEG.out.gm_mask
csf_mask = SEGMENTATION_SYNTHSEG.out.csf_mask
wm_map = Channel.empty()
gm_map = Channel.empty()
csf_map = Channel.empty()
}

else {
// ** FSL fast segmentation ** //
SEGMENTATION_FASTSEG ( ch_image )
ch_versions = ch_versions.mix(SEGMENTATION_FASTSEG.out.versions.first())

// ** Setting outputs ** //
wm_mask = SEGMENTATION_FASTSEG.out.wm_mask
gm_mask = SEGMENTATION_FASTSEG.out.gm_mask
csf_mask = SEGMENTATION_FASTSEG.out.csf_mask
wm_map = SEGMENTATION_FASTSEG.out.wm_map
gm_map = SEGMENTATION_FASTSEG.out.gm_map
csf_map = SEGMENTATION_FASTSEG.out.csf_map
}
}

emit:
Expand Down
39 changes: 31 additions & 8 deletions subworkflows/nf-scil/anatomical_segmentation/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ nextflow_workflow {
"""
ch_split_test_data = LOAD_DATA.out.test_data_directory
.branch{
t1w: it.simpleName == "T1w"
T1w: it.simpleName == "T1w"
freesurfer: it.simpleName == "freesurfer_nifti"
}
input[0] = ch_split_test_data.t1w.map{
input[0] = ch_split_test_data.T1w.map{
test_data_directory -> [
[ id:'test' ],
file("\${test_data_directory}/T1w.nii.gz", checkIfExists: true),
Expand All @@ -50,7 +50,15 @@ nextflow_workflow {
then {
assertAll(
{ assert workflow.success},
{ assert snapshot(workflow.out).match()}
{ assert snapshot(
niftiMD5SUM(workflow.out.wm_mask.get(0).get(1)),
niftiMD5SUM(workflow.out.gm_mask.get(0).get(1)),
niftiMD5SUM(workflow.out.csf_mask.get(0).get(1)),
niftiMD5SUM(workflow.out.wm_map.get(0).get(1)),
niftiMD5SUM(workflow.out.gm_map.get(0).get(1)),
niftiMD5SUM(workflow.out.csf_map.get(0).get(1)),
workflow.out.versions
).match()}
)
}
}
Expand All @@ -62,7 +70,7 @@ nextflow_workflow {
"""
ch_split_test_data = LOAD_DATA.out.test_data_directory
.branch{
t1w: it.simpleName == "T1w"
T1w: it.simpleName == "T1w"
freesurfer: it.simpleName == "freesurfer_nifti"
}
input[0] = []
Expand All @@ -80,18 +88,27 @@ nextflow_workflow {
then {
assertAll(
{ assert workflow.success },
{ assert snapshot(workflow.out).match() }
{ assert snapshot(
niftiMD5SUM(workflow.out.wm_mask.get(0).get(1)),
niftiMD5SUM(workflow.out.gm_mask.get(0).get(1)),
niftiMD5SUM(workflow.out.csf_mask.get(0).get(1)),
workflow.out.versions
).match() }
)
}
}
}

test("anatomical_segmentation - synthseg") {
config "./nextflow_surgery.config"
when {
workflow {
"""
input[0] = LOAD_DATA.out.test_data_directory.map{
ch_split_test_data = LOAD_DATA.out.test_data_directory
.branch{
T1w: it.simpleName == "T1w"
freesurfer: it.simpleName == "freesurfer_nifti"
}
input[0] = ch_split_test_data.T1w.map{
test_data_directory -> [
[ id:'test', single_end:false ], // meta map
file("\${test_data_directory}/anat/anat_image.nii.gz", checkIfExists: true),
Expand All @@ -105,7 +122,13 @@ nextflow_workflow {
then {
assertAll(
{ assert workflow.success},
{ assert snapshot(workflow.out).match()}
{ assert snapshot(
niftiMD5SUM(workflow.out.wm_mask.get(0).get(1)),
niftiMD5SUM(workflow.out.gm_mask.get(0).get(1)),
niftiMD5SUM(workflow.out.csf_mask.get(0).get(1)),
workflow.out.versions
).match()}
)
}
}
}

0 comments on commit 6f157fd

Please sign in to comment.