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

[ENH] Update registration subworkflows and modules #62

Merged
merged 5 commits into from
Dec 5, 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
36 changes: 20 additions & 16 deletions modules/nf-neuro/registration/convert/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ process REGISTRATION_CONVERT {
containerOptions "--env FSLOUTPUTTYPE='NIFTI_GZ'"

input:
tuple val(meta), path(affine), path(deform), path(source), path(target), path(fs_license)
tuple val(meta), path(deform), path(affine), path(source), path(target), path(fs_license)

output:
tuple val(meta), path("*.{txt,lta,mat,dat}"), emit: affine_transform
tuple val(meta), path("*.{nii,nii.gz,mgz,m3z}"), emit: deform_transform
tuple val(meta), path("*out_deform_warp.{nii,nii.gz,mgz,m3z}") , emit: deform_transform
tuple val(meta), path("*out_affine_warp.{txt,lta,mat,dat}") , emit: affine_transform, optional: true
path "versions.yml" , emit: versions

when:
Expand Down Expand Up @@ -40,15 +40,20 @@ process REGISTRATION_CONVERT {

cp $fs_license \$FREESURFER_HOME/license.txt

declare -A affine_dictionnary=( ["--outlta"]="lta" \
["--outfsl"]="mat" \
["--outmni"]="xfm" \
["--outreg"]="dat" \
["--outniftyreg"]="txt" \
["--outitk"]="txt" \
["--outvox"]="txt" )
if [[ -f "$affine" ]];
then
declare -A affine_dictionnary=( ["--outlta"]="lta" \
["--outfsl"]="mat" \
["--outmni"]="xfm" \
["--outreg"]="dat" \
["--outniftyreg"]="txt" \
["--outitk"]="txt" \
["--outvox"]="txt" )

ext_affine=\${affine_dictionnary[${out_format_affine}]}
ext_affine=\${affine_dictionnary[${out_format_affine}]}

lta_convert ${invert} ${source_geometry_affine} ${target_geometry_affine} ${in_format_affine} ${out_format_affine} ${prefix}__out_affine_warp.\${ext_affine}
fi

declare -A deform_dictionnary=( ["--outm3z"]="m3z" \
["--outfsl"]="nii.gz" \
Expand All @@ -59,14 +64,13 @@ process REGISTRATION_CONVERT {

ext_deform=\${deform_dictionnary[${out_format_deform}]}

lta_convert ${invert} ${source_geometry_affine} ${target_geometry_affine} ${in_format_affine} ${out_format_affine} ${prefix}__affine_warp.\${ext_affine}
mri_warp_convert ${source_geometry_deform} ${downsample} ${in_format_deform} ${out_format_deform} ${prefix}__deform_warp.\${ext_deform}
mri_warp_convert ${source_geometry_deform} ${downsample} ${in_format_deform} ${out_format_deform} ${prefix}__out_deform_warp.\${ext_deform}

rm \$FREESURFER_HOME/license.txt

cat <<-END_VERSIONS > versions.yml
"${task.process}":
Freesurfer: 7.4.1
Freesurfer: \$(mri_convert -version | grep "freesurfer" | sed -E 's/.* ([0-9]+\\.[0-9]+\\.[0-9]+).*/\\1/')
END_VERSIONS
"""

Expand All @@ -78,12 +82,12 @@ process REGISTRATION_CONVERT {
lta_convert -h
mri_warp_convert -h

touch ${prefix}__affine_transform.txt
touch ${prefix}__deform_transform.nii.gz
touch ${prefix}__affine_transform.txt

cat <<-END_VERSIONS > versions.yml
"${task.process}":
Freesurfer: 7.4.1
Freesurfer: \$(mri_convert -version | grep "freesurfer" | sed -E 's/.* ([0-9]+\\.[0-9]+\\.[0-9]+).*/\\1/')
END_VERSIONS
"""
}
20 changes: 10 additions & 10 deletions modules/nf-neuro/registration/convert/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ input:
Groovy Map containing sample information
e.g. `[ id:'test', single_end:false ]`

- affine:
type: file
description: Affine transform to convert. Default usage expects Freesurfer .lta format from mri_synthmorph
pattern: "*.{lta,txt,xfm,dat}"

- deform:
type: file
description: Deform transform to convert. Default usage expects Freesurfer .mgz format from mri_synthmorph
pattern: "*.{nii,nii.gz,mgz,m3z}"

- affine:
type: file
description: Affine transform to convert. Default usage expects Freesurfer .lta format from mri_synthmorph
pattern: "*.{lta,txt,xfm,dat}"

- source:
type: file
description: Moving Nifti volume used for registration. Defines source image geometry
Expand All @@ -51,16 +51,16 @@ output:
Groovy Map containing sample information
e.g. `[ id:'test', single_end:false ]`

- affine_transform:
type: file
description: Affine transform. Default usage outputs ANTs (ITK) format .txt
pattern: "*.{txt,lta,mat,dat}"

- deform_transform:
type: file
description: Deform transform. Default usage outputs ANTs (ITK) format .nii.gz
pattern: "*.{nii,nii.gz,mgz,m3z}"

- affine_transform:
type: file
description: Affine transform. Default usage outputs ANTs (ITK) format .txt
pattern: "*.{txt,lta,mat,dat}"

- versions:
type: file
description: File containing software versions
Expand Down
66 changes: 57 additions & 9 deletions modules/nf-neuro/registration/convert/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ nextflow_process {
ch_transforms = ch_split_test_data.transforms.map{
test_data_directory -> [
[ id:'test' ],
file("\${test_data_directory}/fs_affine.lta"),
file("\${test_data_directory}/fs_deform.nii.gz"),
[]
]
}
ch_reslice = ch_split_test_data.reslice.map{
Expand Down Expand Up @@ -73,6 +73,54 @@ nextflow_process {
}
}

test("registration - convert - affine") {

config "./nextflow_default.config"

when {
process {
"""
ch_split_test_data = LOAD_DATA.out.test_data_directory
.branch{
freesurfer: it.simpleName == "freesurfer"
reslice: it.simpleName == "freesurfer_reslice"
transforms: it.simpleName == "freesurfer_transforms"
}
ch_transforms = ch_split_test_data.transforms.map{
test_data_directory -> [
[ id:'test' ],
file("\${test_data_directory}/fs_deform.nii.gz"),
file("\${test_data_directory}/fs_affine.lta")
]
}
ch_reslice = ch_split_test_data.reslice.map{
test_data_directory -> [
[ id:'test' ],
file("\${test_data_directory}/t1_reslice.nii.gz"),
file("\${test_data_directory}/fa_reslice.nii.gz")
]
}
ch_freesurfer = ch_split_test_data.freesurfer.map{
test_data_directory -> [
[ id:'test' ],
file("\${test_data_directory}/license.txt")
]
}
input[0] = ch_transforms
.join(ch_reslice)
.join(ch_freesurfer)
"""
}
}

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

test("registration - convert - fsants") {

config "./nextflow_fsants.config"
Expand All @@ -89,8 +137,8 @@ nextflow_process {
ch_transforms = ch_split_test_data.transforms.map{
test_data_directory -> [
[ id:'test' ],
file("\${test_data_directory}/fs_affine.lta"),
file("\${test_data_directory}/fs_deform.nii.gz")
file("\${test_data_directory}/fs_deform.nii.gz"),
file("\${test_data_directory}/fs_affine.lta")
]
}
ch_reslice = ch_split_test_data.reslice.map{
Expand Down Expand Up @@ -137,8 +185,8 @@ nextflow_process {
ch_transforms = ch_split_test_data.transforms.map{
test_data_directory -> [
[ id:'test' ],
file("\${test_data_directory}/fsl_affine.mat"),
file("\${test_data_directory}/fsl_deform.nii.gz")
file("\${test_data_directory}/fsl_deform.nii.gz"),
file("\${test_data_directory}/fsl_affine.mat")
]
}
ch_reslice = ch_split_test_data.reslice.map{
Expand Down Expand Up @@ -189,8 +237,8 @@ nextflow_process {
ch_transforms = ch_split_test_data.transforms.map{
test_data_directory -> [
[ id:'test' ],
file("\${test_data_directory}/fsl_affine.mat"),
file("\${test_data_directory}/fsl_deform.nii.gz")
file("\${test_data_directory}/fsl_deform.nii.gz"),
file("\${test_data_directory}/fsl_affine.mat")
]
}
ch_reslice = ch_split_test_data.reslice.map{
Expand Down Expand Up @@ -237,8 +285,8 @@ nextflow_process {
ch_transforms = ch_split_test_data.transforms.map{
test_data_directory -> [
[ id:'test' ],
file("\${test_data_directory}/ants_affine.txt"),
file("\${test_data_directory}/ants_deform.nii.gz")
file("\${test_data_directory}/ants_deform.nii.gz"),
file("\${test_data_directory}/ants_affine.txt")
]
}
ch_reslice = ch_split_test_data.reslice.map{
Expand Down
Loading
Loading