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

[New module] Freesurfer registration/convert #5

Merged
merged 5 commits into from
Sep 25, 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
3 changes: 3 additions & 0 deletions modules/nf-neuro/registration/convert/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
channels: []
dependencies: []
name: registration_convert
89 changes: 89 additions & 0 deletions modules/nf-neuro/registration/convert/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
process REGISTRATION_CONVERT {
tag "$meta.id"
label 'process_single'

container "freesurfer/freesurfer:7.4.1"
containerOptions "--env FSLOUTPUTTYPE='NIFTI_GZ'"

input:
tuple val(meta), path(affine), path(deform), 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
path "versions.yml" , emit: versions

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

script:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"

//For arguments definition, lta_convert -h
def invert = task.ext.invert ? "--invert" : ""
def source_geometry_affine = "$source" ? "--src " + "$source" : ""
def target_geometry_affine = "$target" ? "--trg " + "$target" : ""
def in_format_affine = task.ext.in_format_affine ? "--in" + task.ext.in_format_affine + " " + "$affine" : "--inlta " + "$affine"
def out_format_affine = task.ext.out_format_affine ? "--out" + task.ext.out_format_affine : "--outitk"

//For arguments definition, mri_warp_convert -h
def source_geometry_deform = "$source" ? "--insrcgeom " + "$source" : ""
def in_format_deform = task.ext.in_format_deform ? "--in" + task.ext.in_format_deform + " " + "$deform" : "--inras " + "$deform"
def out_format_deform = task.ext.out_format_deform ? "--out" + task.ext.out_format_deform : "--outitk"
def downsample = task.ext.downsample ? "--downsample" : ""

"""
export ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=$task.cpus
AlexVCaron marked this conversation as resolved.
Show resolved Hide resolved
export OMP_NUM_THREADS=1
export OPENBLAS_NUM_THREADS=1

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" )

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

declare -A deform_dictionnary=( ["--outm3z"]="m3z" \
["--outfsl"]="nii.gz" \
["--outlps"]="nii.gz" \
["--outitk"]="nii.gz" \
["--outras"]="nii.gz" \
["--outvox"]="mgz" )

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}

rm \$FREESURFER_HOME/license.txt

cat <<-END_VERSIONS > versions.yml
"${task.process}":
Freesurfer: 7.4.1
END_VERSIONS
"""

stub:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"

"""
lta_convert -h
mri_warp_convert -h

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

cat <<-END_VERSIONS > versions.yml
"${task.process}":
Freesurfer: 7.4.1
END_VERSIONS
"""
}
70 changes: 70 additions & 0 deletions modules/nf-neuro/registration/convert/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
name: "registration_convert"
description: Freesurfer transform conversion tool. Default usage is aim at receiving freesurfer format and converting to ANTs (ITK). See lta_convert --help and mri_warp_convert --help for options.
keywords:
anroy1 marked this conversation as resolved.
Show resolved Hide resolved
- Registration
- Brain imaging
- MRI
- Conversion
tools:
- "Freesurfer":
description: "Freesurfer lta_convert (affine conversion) and mri_warp_convert (deform) tools for transform conversion"
homepage: "https://surfer.nmr.mgh.harvard.edu/"
documentation: "https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferWiki"

input:
- meta:
type: map
description: |
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}"

- source:
type: file
description: Moving Nifti volume used for registration. Defines source image geometry
pattern: "*.{nii,nii.gz}"

- target:
type: file
description: Fixed Nifti volume used for registration. Defines target image geometry. (optional)
pattern: "*.{nii,nii.gz}"

- fs_license:
type: file
description: The path to your FreeSurfer license. To get one, go to https://surfer.nmr.mgh.harvard.edu/registration.html. Optional. If you have already set your license as prescribed by Freesurfer (copied to a .license file in your $FREESURFER_HOME), this is not required.
pattern: "*.txt"

output:
- meta:
type: map
description: |
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}"

- versions:
type: file
description: File containing software versions
pattern: "versions.yml"

authors:
- "@anroy1"
Loading
Loading