forked from scilus/nf-neuro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from anroy1/warpconvert
[New module] Freesurfer registration/convert
- Loading branch information
Showing
11 changed files
with
671 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
channels: [] | ||
dependencies: [] | ||
name: registration_convert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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 | ||
""" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
- 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" |
Oops, something went wrong.