Skip to content

Commit

Permalink
Merge pull request #66 from EmmaRenauld/module_reconall
Browse files Browse the repository at this point in the history
[Module] Freesurfer reconall
  • Loading branch information
arnaudbore committed May 21, 2024
2 parents 2cc9b03 + 36004d1 commit 8eb34b1
Show file tree
Hide file tree
Showing 41 changed files with 252 additions and 113 deletions.
3 changes: 0 additions & 3 deletions .test_data/betcrop/cropvolume_image.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/betcrop/cropvolume_mask.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/betcrop/fslbetcrop_bval.bval

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/betcrop/fslbetcrop_bvec.bvec

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/denoising/nlmeans_image.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/denoising/nlmeans_mask.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/heavy/anat/anat_image.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/heavy/anat/anat_mask.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/heavy/dwi/dwi.bval

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/heavy/dwi/dwi.bvec

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/heavy/dwi/dwi.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/heavy/dwi/mask.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/heavy/dwi_with_b0/b0.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/heavy/dwi_with_b0/dwi.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/heavy/dwi_with_b0/mask.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/heavy/freesurfer/aparc_aseg.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/heavy/freesurfer/wmparc.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/heavy/mni_152/t1_brain_probability_map.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/heavy/mni_152/t1_template.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/light/box_3d/box_3d_image.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/light/box_3d/box_3d_mask.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/light/priors/s1__iso_diff.txt

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/light/priors/s1__para_diff.txt

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/light/priors/s2__iso_diff.txt

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/light/priors/s2__para_diff.txt

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/preproc/b0.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/preproc/b0_mask.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/preproc/dwi.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/preproc/dwi_normalize.nii.gz

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/preproc/dwi_normalize_bval.bval

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/preproc/dwi_normalize_bvec.bvec

This file was deleted.

3 changes: 0 additions & 3 deletions .test_data/preproc/dwi_normalize_mask.nii.gz

This file was deleted.

7 changes: 7 additions & 0 deletions modules/nf-scil/segmentation/fsreconall/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: "segmentation_fsreconall"
channels:
- Docker
- Apptainer
dependencies:
- "FreeSurfer"
71 changes: 71 additions & 0 deletions modules/nf-scil/segmentation/fsreconall/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
process SEGMENTATION_FSRECONALL {
tag "$meta.id"
label 'process_single'

// Note. Freesurfer is already on Docker. See documentation on
// https://hub.docker.com/r/freesurfer/freesurfer
container "freesurfer/freesurfer:7.4.1"

input:
tuple val(meta), path(anat), path(fs_license) /* optional, value = [] */

output:
tuple val(meta), path("*__recon_all") , emit: recon_all_out_folder
path "versions.yml" , emit: versions

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

// Note. In dsl1, we used an additional option: -parallel -openmp $params.nb_threads.
// Removed here.
script:
def prefix = task.ext.prefix ?: "${meta.id}"
def dev_debug_test = task.ext.debug ? task.ext.debug : "" // If true, we will only run the help (for unit tests )
"""
# Manage the license. (Save old one if existed.)
if [[ ! -f "$fs_license" ]]
then
echo "License not given in input, or not found. Will probably fail. "
else
cp "$fs_license" .license
here=`pwd`
export FS_LICENSE=\$here/.license
fi
if [ -z $dev_debug_test ]
then
# Run the main script
export SUBJECTS_DIR=`pwd`
recon-all -i $anat -s ${prefix}__recon_all -all
else
# (for developers: unit tests: skip the long processing. help only.)
export SUBJECTS_DIR=`pwd`
recon-all -i $anat -s ${prefix}__recon_all -autorecon1 -dontrun
fi
# Remove the license
if [ ! $fs_license = [] ]; then
rm .license
fi
# Finish
cat <<-END_VERSIONS > versions.yml
"${task.process}":
freesurfer: \$(recon-all -version)
END_VERSIONS
"""

stub:
def prefix = task.ext.prefix ?: "${meta.id}"
"""
recon-all --help
mkdir ${prefix}__recon_all
cat <<-END_VERSIONS > versions.yml
"${task.process}":
freesurfer: \$(recon-all -version)
END_VERSIONS
"""
}
48 changes: 48 additions & 0 deletions modules/nf-scil/segmentation/fsreconall/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
name: "segmentation_fsreconall"
description: "Performs Freesurfer's recon-all script to segment your anatomy (probably a T1) into labels, surfaces, and much more. See the full documentation here: https://surfer.nmr.mgh.harvard.edu/fswiki/recon-all."
keywords:
- FreeSurfer
- Segmentation
- Tissues
tools:
- "Freesurfer":
description: "An open source neuroimaging toolkit for processing, analyzing, and visualizing human brain MR images."
homepage: "https://surfer.nmr.mgh.harvard.edu/"

input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'test', single_end:false ]`
- anat:
type: file
description: An anatomy (ex, .nii.gz).
pattern: "*.{nii,nii.gz,mgz}"

- 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 ]`
- recon_all_out_folder:
type: directory
description: Directory containing all recon-all outputs.
pattern: "*.{nii,nii.gz}"

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

authors:
- "@EmmaRenauld"
83 changes: 83 additions & 0 deletions modules/nf-scil/segmentation/fsreconall/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
nextflow_process {

name "Test Process SEGMENTATION_FSRECONALL"
script "../main.nf"
process "SEGMENTATION_FSRECONALL"

tag "modules"
tag "modules_nfcore"
tag "segmentation"
tag "segmentation/fsreconall"

tag "subworkflows"
tag "subworkflows/load_test_data"

setup {
run("LOAD_TEST_DATA", alias: "LOAD_DATA") {
script "../../../../../subworkflows/nf-scil/load_test_data/main.nf"
process {
"""
input[0] = Channel.from( [ "freesurfer.zip" ] )
input[1] = "test.load-test-data"
"""
}
}
}

test("segmentation - fsreconall") {

when {
config "./nextflow_debug.config"

process {
"""
input[0] = LOAD_DATA.out.test_data_directory.map{
test_data_directory -> [
[ id:'test', single_end:false ], // meta map
file("\${test_data_directory}/anat_image.nii.gz"),
file("\${test_data_directory}/license.txt")
]}
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(
file(process.out.recon_all_out_folder.get(0).get(1)).name,
process.out.versions
).match() }
)
}

}


test("segmentation - fsreconall - nolicense") {

when {
// Not in mode debug + no license = should fail.
config "./nextflow.config"

process {
"""
input[0] = LOAD_DATA.out.test_data_directory.map{
test_data_directory -> [
[ id:'test', single_end:false ], // meta map
file("\${test_data_directory}/anat_image.nii.gz"),
[]
]}
"""
}
}

then {
assertAll(
{ assert ! process.success }
)
}

}

}
15 changes: 15 additions & 0 deletions modules/nf-scil/segmentation/fsreconall/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"segmentation - fsreconall": {
"content": [
"test__recon_all",
[
"versions.yml:md5,12027dd965b94e4d68b7e8a630a04d00"
]
],
"meta": {
"nf-test": "0.8.4",
"nextflow": "23.10.1"
},
"timestamp": "2024-05-21T18:19:43.835172"
}
}
5 changes: 5 additions & 0 deletions modules/nf-scil/segmentation/fsreconall/tests/nextflow.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process {
withName: "SEGMENTATION_FSRECONALL" {
ext.debug = false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process {
withName: "SEGMENTATION_FSRECONALL" {
ext.debug = true
}
}
2 changes: 2 additions & 0 deletions modules/nf-scil/segmentation/fsreconall/tests/tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
segmentation/fsreconall:
- "modules/nf-scil/segmentation/fsreconall/**"

0 comments on commit 8eb34b1

Please sign in to comment.