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

Split transforms into 2 inputs and update versions in registrations/antsapplytransforms #55

Merged
merged 2 commits into from
Nov 29, 2024
Merged
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
23 changes: 9 additions & 14 deletions modules/nf-neuro/registration/antsapplytransforms/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 : ""
Expand All @@ -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
Expand All @@ -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
"""
}
11 changes: 8 additions & 3 deletions modules/nf-neuro/registration/antsapplytransforms/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,27 @@ 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"
"""
}
}
}

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")
]}
"""
}
Expand All @@ -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() }
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
"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": [
[
{
"id": "test",
"single_end": false
},
"test__warped.nii.gz:md5,f5df5ab8622bfd2f3ea4c59e3c4f482e"
"test__b0__warped.nii.gz:md5,3ae49aacab66fb2378da92155453b1be"
]
]
}
Expand All @@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}