Skip to content

Commit

Permalink
[WIP] modify module and test to manage freesurfer license
Browse files Browse the repository at this point in the history
  • Loading branch information
anroy1 committed Mar 7, 2024
1 parent f2ab543 commit fe3ce46
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .test_data/heavy/freesurfer/license.txt
Git LFS file not shown
16 changes: 15 additions & 1 deletion modules/nf-scil/registration/synthregistration/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions modules/nf-scil/registration/synthregistration/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/config/test_data.config
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 8 additions & 15 deletions tests/modules/nf-scil/registration/synthregistration/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
}
Original file line number Diff line number Diff line change
@@ -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()}" }
}
}

0 comments on commit fe3ce46

Please sign in to comment.