From fe3ce46e3ad4e2669fb429882239af2d03b2821c Mon Sep 17 00:00:00 2001 From: anroy1 Date: Fri, 1 Mar 2024 20:31:32 +0000 Subject: [PATCH] [WIP] modify module and test to manage freesurfer license --- .test_data/heavy/freesurfer/license.txt | 3 +++ .../registration/synthregistration/main.nf | 16 ++++++++++++- .../registration/synthregistration/meta.yml | 5 ++++ tests/config/test_data.config | 6 +++++ .../registration/synthregistration/main.nf | 23 +++++++------------ .../synthregistration/nextflow.config | 7 +----- 6 files changed, 38 insertions(+), 22 deletions(-) create mode 100644 .test_data/heavy/freesurfer/license.txt diff --git a/.test_data/heavy/freesurfer/license.txt b/.test_data/heavy/freesurfer/license.txt new file mode 100644 index 000000000..9c31cab4c --- /dev/null +++ b/.test_data/heavy/freesurfer/license.txt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:05d2a544719626968d938cca74effbd673474fdc0db1d134f77f38e2fc497f49 +size 102 diff --git a/modules/nf-scil/registration/synthregistration/main.nf b/modules/nf-scil/registration/synthregistration/main.nf index a8d9cc343..3589e7a25 100644 --- a/modules/nf-scil/registration/synthregistration/main.nf +++ b/modules/nf-scil/registration/synthregistration/main.nf @@ -5,7 +5,7 @@ process REGISTRATION_SYNTHREGISTRATION { container "freesurfer/synthmorph:latest" input: - tuple val(meta), path(moving), path(fixed) + tuple val(meta), path(moving), path(fixed), path(fs_license) /* optional, value = [] */ output: @@ -35,6 +35,15 @@ process REGISTRATION_SYNTHREGISTRATION { def out_format = task.ext.out_format ? "--out" + task.ext.out_format : "--outlps" """ + # Manage the license. (Save old one if existed.) + if [ $fs_license = [] ]; then + echo "License not given in input. Using default environment. " + else + cp $fs_license .license + here=`pwd` + export FS_LICENSE=\$here/.license + fi + export ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=1 export OMP_NUM_THREADS=1 export OPENBLAS_NUM_THREADS=1 @@ -44,6 +53,11 @@ process REGISTRATION_SYNTHREGISTRATION { mri_warp_convert -g $moving --inras temp.mgz $out_format ${prefix}__deform_warp.nii.gz + # Remove the license + if [ ! $fs_license = [] ]; then + rm .license + fi + cat <<-END_VERSIONS > versions.yml "${task.process}": Freesurfer: 7.4 diff --git a/modules/nf-scil/registration/synthregistration/meta.yml b/modules/nf-scil/registration/synthregistration/meta.yml index 20b738314..1cca21c4a 100644 --- a/modules/nf-scil/registration/synthregistration/meta.yml +++ b/modules/nf-scil/registration/synthregistration/meta.yml @@ -28,6 +28,11 @@ input: description: Nifti volume fixed for registration 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 diff --git a/tests/config/test_data.config b/tests/config/test_data.config index 26adb5061..5af983a27 100644 --- a/tests/config/test_data.config +++ b/tests/config/test_data.config @@ -75,6 +75,12 @@ params { frf = "${params.test_data_base}/reconst/frf.txt" } } + "registration" { + "synthregistration"{ + t1 = "${params.test_data_base}/heavy/anat/anat_image.nii.gz" + fa = "${params.test_data_base}/heavy/dwi/dwi.nii.gz" + fs_license = "${params.test_data_base}/heavy/freesurfer/license.txt" + } "segmentation" { "freesurferseg" { aparc_aseg = "${params.test_data_base}/heavy/freesurfer/aparc_aseg.nii.gz" diff --git a/tests/modules/nf-scil/registration/synthregistration/main.nf b/tests/modules/nf-scil/registration/synthregistration/main.nf index 2b181af0d..dfa3dfe9e 100644 --- a/tests/modules/nf-scil/registration/synthregistration/main.nf +++ b/tests/modules/nf-scil/registration/synthregistration/main.nf @@ -2,23 +2,16 @@ nextflow.enable.dsl = 2 -include { LOAD_TEST_DATA } from '../../../../../subworkflows/nf-scil/load_test_data/main.nf' -include { - REGISTRATION_SYNTHREGISTRATION as REGISTRATION_SYNTHREGISTRATION_T1FA; } from '../../../../../modules/nf-scil/registration/synthregistration/main.nf' +include { REGISTRATION_SYNTHREGISTRATION } from '../../../../../modules/nf-scil/registration/synthregistration/main.nf' workflow test_registration_synthregistration { - input_fetch = Channel.from( [ "others.zip" ] ) - - LOAD_TEST_DATA ( input_fetch, "test.load-test-data" ) - - input_t1fa = LOAD_TEST_DATA.out.test_data_directory - .map{ test_data_directory -> [ - [ id:'test', single_end:false ], // meta map - file("${test_data_directory}/t1.nii.gz"), - file("${test_data_directory}/fa.nii.gz") - ]} - - REGISTRATION_SYNTHREGISTRATION_T1FA ( input_t1fa ) + input = [ + [ id:'test', single_end:false ], // meta map + file(params.test_data['registration']['synthregistration']['t1'], checkIfExists: true), + file(params.test_data['registration']['synthregistration']['fa'], checkIfExists: true), + file(params.test_data['registration']['synthregistration']['fs_license'], checkIfExists: true) + ] + REGISTRATION_SYNTHREGISTRATION ( input ) } diff --git a/tests/modules/nf-scil/registration/synthregistration/nextflow.config b/tests/modules/nf-scil/registration/synthregistration/nextflow.config index d347f93c2..8730f1c4b 100644 --- a/tests/modules/nf-scil/registration/synthregistration/nextflow.config +++ b/tests/modules/nf-scil/registration/synthregistration/nextflow.config @@ -1,10 +1,5 @@ process { - withName: "REGISTRATION_SYNTHREGISTRATION" { - publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" } - } + publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" } - withName: "REGISTRATION_SYNTHREGISTRATION_T1FA" { - publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" } - } }