From cdf932bede93541d0b74dbb94c4681b28af08757 Mon Sep 17 00:00:00 2001 From: Anthony Gagnon Date: Thu, 28 Nov 2024 20:23:30 +0000 Subject: [PATCH 1/2] split transforms into 2 inputs + cleanup + stub test --- .../registration/antsapplytransforms/main.nf | 23 +++++------ .../antsapplytransforms/tests/main.nf.test | 40 +++++++++++++++++-- .../tests/main.nf.test.snap | 22 +++++++--- .../antsapplytransforms/tests/nextflow.config | 5 +++ 4 files changed, 67 insertions(+), 23 deletions(-) diff --git a/modules/nf-neuro/registration/antsapplytransforms/main.nf b/modules/nf-neuro/registration/antsapplytransforms/main.nf index 4adac58c..315819dc 100644 --- a/modules/nf-neuro/registration/antsapplytransforms/main.nf +++ b/modules/nf-neuro/registration/antsapplytransforms/main.nf @@ -7,7 +7,7 @@ process REGISTRATION_ANTSAPPLYTRANSFORMS { 'scilus/scilus:2.0.2' }" input: - tuple val(meta), path(image), path(reference), path(transform) + tuple val(meta), path(image), path(reference), path(warp), path(affine) output: tuple val(meta), path("*__warped.nii.gz") , emit: warped_image @@ -17,9 +17,8 @@ process REGISTRATION_ANTSAPPLYTRANSFORMS { task.ext.when == null || task.ext.when script: - def args = task.ext.args ?: '' def prefix = task.ext.prefix ?: "${meta.id}" - def suffix = task.ext.first_suffix ? "${task.ext.first_suffix}_warped" : "warped" + def suffix = task.ext.first_suffix ? "${task.ext.first_suffix}__warped" : "warped" def dimensionality = task.ext.dimensionality ? "-d " + task.ext.dimensionality : "" def image_type = task.ext.image_type ? "-e " + task.ext.image_type : "" @@ -37,24 +36,20 @@ process REGISTRATION_ANTSAPPLYTRANSFORMS { -r $reference\ -o ${prefix}__${suffix}.nii.gz\ $interpolation\ - -t $transform\ + -t $warp $affine\ + $image_type\ + $default_val\ + $output_dtype cat <<-END_VERSIONS > versions.yml "${task.process}": - ants: antsRegistration --version | grep "Version" | sed -E 's/.*v([0-9]+\\.[0-9]+\\.[0-9]+).*/\\1/' + ants: \$(antsRegistration --version | grep "Version" | sed -E 's/.*v([0-9]+\\.[0-9]+\\.[0-9]+).*/\\1/') END_VERSIONS """ stub: - def args = task.ext.args ?: '' def prefix = task.ext.prefix ?: "${meta.id}" - def suffix = task.ext.first_suffix ? "${task.ext.first_suffix}_warped" : "warped" - - def dimensionality = task.ext.dimensionality ? "-d " + task.ext.dimensionality : "" - def image_type = task.ext.image_type ? "-e " + task.ext.image_type : "" - def interpolation = task.ext.interpolation ? "-n " + task.ext.interpolation : "" - def output_dtype = task.ext.output_dtype ? "-u " + task.ext.output_dtype : "" - def default_val = task.ext.default_val ? "-f " + task.ext.default_val : "" + def suffix = task.ext.first_suffix ? "${task.ext.first_suffix}__warped" : "warped" """ antsApplyTransforms -h @@ -63,7 +58,7 @@ process REGISTRATION_ANTSAPPLYTRANSFORMS { cat <<-END_VERSIONS > versions.yml "${task.process}": - ants: antsRegistration --version | grep "Version" | sed -E 's/.*v([0-9]+\\.[0-9]+\\.[0-9]+).*/\\1/' + ants: \$(antsRegistration --version | grep "Version" | sed -E 's/.*v([0-9]+\\.[0-9]+\\.[0-9]+).*/\\1/') END_VERSIONS """ } diff --git a/modules/nf-neuro/registration/antsapplytransforms/tests/main.nf.test b/modules/nf-neuro/registration/antsapplytransforms/tests/main.nf.test index bd45e73a..8447aa39 100644 --- a/modules/nf-neuro/registration/antsapplytransforms/tests/main.nf.test +++ b/modules/nf-neuro/registration/antsapplytransforms/tests/main.nf.test @@ -17,7 +17,7 @@ nextflow_process { script "../../../../../subworkflows/nf-neuro/load_test_data/main.nf" process { """ - input[0] = Channel.from( [ "bst.zip" ] ) + input[0] = Channel.from( [ "registration.zip" ] ) input[1] = "test.load-test-data" """ } @@ -25,15 +25,19 @@ nextflow_process { } test("registration - antsapplytransforms") { + + config "./nextflow.config" + 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}/fa.nii.gz"), - file("\${test_data_directory}/mask.nii.gz"), - file("\${test_data_directory}/output1InverseWarp.nii.gz") + file("\${test_data_directory}/b0.nii.gz"), + file("\${test_data_directory}/mni_masked_2x2x2.nii.gz"), + file("\${test_data_directory}/output1Warp.nii.gz"), + file("\${test_data_directory}/output0GenericAffine.mat") ]} """ } @@ -45,4 +49,32 @@ nextflow_process { ) } } + + test("registration - antsapplytransforms - stub-run") { + + options "-stub-run" + + config "./nextflow.config" + + 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}/b0.nii.gz"), + file("\${test_data_directory}/mni_masked_2x2x2.nii.gz"), + file("\${test_data_directory}/output1Warp.nii.gz"), + file("\${test_data_directory}/output0GenericAffine.mat") + ]} + """ + } + } + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out.versions).match() } + ) + } + } } diff --git a/modules/nf-neuro/registration/antsapplytransforms/tests/main.nf.test.snap b/modules/nf-neuro/registration/antsapplytransforms/tests/main.nf.test.snap index 66d4bd85..bd6edac8 100644 --- a/modules/nf-neuro/registration/antsapplytransforms/tests/main.nf.test.snap +++ b/modules/nf-neuro/registration/antsapplytransforms/tests/main.nf.test.snap @@ -8,14 +8,14 @@ "id": "test", "single_end": false }, - "test__warped.nii.gz:md5,f5df5ab8622bfd2f3ea4c59e3c4f482e" + "test__b0__warped.nii.gz:md5,3ae49aacab66fb2378da92155453b1be" ] ], "1": [ - "versions.yml:md5,f45b96ead53b75f1fc565461836b1475" + "versions.yml:md5,180609e91d7d492cd7db9b09f47f055d" ], "versions": [ - "versions.yml:md5,f45b96ead53b75f1fc565461836b1475" + "versions.yml:md5,180609e91d7d492cd7db9b09f47f055d" ], "warped_image": [ [ @@ -23,7 +23,7 @@ "id": "test", "single_end": false }, - "test__warped.nii.gz:md5,f5df5ab8622bfd2f3ea4c59e3c4f482e" + "test__b0__warped.nii.gz:md5,3ae49aacab66fb2378da92155453b1be" ] ] } @@ -32,6 +32,18 @@ "nf-test": "0.9.0", "nextflow": "24.04.4" }, - "timestamp": "2024-10-25T18:07:26.443335534" + "timestamp": "2024-11-28T20:21:53.029255208" + }, + "registration - antsapplytransforms - stub-run": { + "content": [ + [ + "versions.yml:md5,180609e91d7d492cd7db9b09f47f055d" + ] + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.04.4" + }, + "timestamp": "2024-11-28T20:21:57.642570655" } } \ No newline at end of file diff --git a/modules/nf-neuro/registration/antsapplytransforms/tests/nextflow.config b/modules/nf-neuro/registration/antsapplytransforms/tests/nextflow.config index 3932fd59..d29a0427 100644 --- a/modules/nf-neuro/registration/antsapplytransforms/tests/nextflow.config +++ b/modules/nf-neuro/registration/antsapplytransforms/tests/nextflow.config @@ -1,5 +1,10 @@ process { withName: "REGISTRATION_ANTSAPPLYTRANSFORMS" { ext.interpolation = "linear" + ext.first_suffix = "b0" + ext.dimensionality = 3 + ext.image_type = 0 + ext.output_dtype = "float" + ext.default_val = 0 } } From 89c21b369e7e48b4ae1549e68c7977d405cf837b Mon Sep 17 00:00:00 2001 From: Anthony Gagnon Date: Fri, 29 Nov 2024 17:06:09 +0000 Subject: [PATCH 2/2] update meta --- .../registration/antsapplytransforms/meta.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/nf-neuro/registration/antsapplytransforms/meta.yml b/modules/nf-neuro/registration/antsapplytransforms/meta.yml index 83070817..8314569e 100644 --- a/modules/nf-neuro/registration/antsapplytransforms/meta.yml +++ b/modules/nf-neuro/registration/antsapplytransforms/meta.yml @@ -27,10 +27,15 @@ input: description: Reference image for registration pattern: "*.{nii.nii.gz}" - - transform: + - warp: type: file - description: file or tuple of files, transformation file(s) to warp image or trk (*mat or [nii Warp, mat file]). If a rigid or affine transformation needs to be inverted before being applied, use antsApplyTransforms with the -o Linear[inversedTransform,1], as this module does not handles it. - pattern: "*.{nii,nii.gz,mat}" + description: Warp transformation file to warp image or trk. + pattern: "*.{nii,nii.gz}" + + - affine: + type: file + description: Affine or rigig transformation file to warp image or trk (*mat). If a rigid or affine transformation needs to be inverted before being applied, use antsApplyTransforms with the -o Linear[inversedTransform,1], as this module does not handles it. + pattern: "*.mat" output: - meta: