diff --git a/modules/nf-neuro/tensor/ratio/environment.yml b/modules/nf-neuro/tensor/ratio/environment.yml new file mode 100644 index 00000000..ff7501ff --- /dev/null +++ b/modules/nf-neuro/tensor/ratio/environment.yml @@ -0,0 +1,6 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json +name: "tensor_ratio" +channels: [] +dependencies: [] + diff --git a/modules/nf-neuro/tensor/ratio/main.nf b/modules/nf-neuro/tensor/ratio/main.nf new file mode 100644 index 00000000..68c8123a --- /dev/null +++ b/modules/nf-neuro/tensor/ratio/main.nf @@ -0,0 +1,48 @@ +process TENSOR_RATIO { + tag "$meta.id" + label 'process_single' + + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'https://scil.usherbrooke.ca/containers/scilus_2.0.2.sif': + 'scilus/scilus:latest' }" + + input: + tuple val(meta), path(image) + + output: + tuple val(meta), path("*_Dxx_to_Dyy.nii.gz") , emit: tensor_x_to_y + tuple val(meta), path("*_Dxx_to_Dzz.nii.gz") , emit: tensor_x_to_z + path "versions.yml" , emit: versions + + when: + task.ext.when == null || task.ext.when + + script: + def prefix = task.ext.prefix ?: "${meta.id}" + + """ + fslsplit $image + fslmaths ${image}_0000.nii.gz -div ${image}_0003.nii.gz ${prefix}_Dxx_to_Dyy.nii.gz + fslmaths ${image}_0000.nii.gz -div ${image}_0005.nii.gz ${prefix}_Dxx_to_Dzz.nii.gz + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + fsl: \$(fslsplit -version 2>&1 | sed -n 's/FSLSPLIT version \\([0-9.]\\+\\)/\\1/p') + END_VERSIONS + """ + + stub: + def prefix = task.ext.prefix ?: "${meta.id}" + + """ + touch ${prefix}_Dxx_to_Dyy.nii.gz + touch ${prefix}_Dxx_to_Dzz.nii.gz + fslsplit + fslmaths + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + fsl: \$(fslsplit -version 2>&1 | sed -n 's/FSLSPLIT version \\([0-9.]\\+\\)/\\1/p') + END_VERSIONS + """ +} diff --git a/modules/nf-neuro/tensor/ratio/meta.yml b/modules/nf-neuro/tensor/ratio/meta.yml new file mode 100644 index 00000000..ab89dc9d --- /dev/null +++ b/modules/nf-neuro/tensor/ratio/meta.yml @@ -0,0 +1,51 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/meta-schema.json +name: "tensor_ratio" +description: Split the tensor image and compute the ratio of Dxx to Dyy and Dxx to Dzz for ALPS. +keywords: + - DWI + - tensor + - DTI-ALPS +tools: + - "FSL": + description: "FSL Toolbox" + homepage: "https://fsl.fmrib.ox.ac.uk/fsl/fslwiki" + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. `[ id:'test', single_end:false ]` + + - image: + type: file + description: Nifti tensor image volume to extract Dx to Dy and Dx to Dz. + pattern: "*.{nii,nii.gz}" + +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. `[ id:'test', single_end:false ]` + + - tensor_x_to_y: + type: file + description: Nifti volume ratio of Dxx to Dyy. + pattern: "*_Dxx_to_Dyy.{nii,nii.gz}" + + - tensor_x_to_z: + type: file + description: Nifti volume ratio of Dxx to Dzz. + pattern: "*_Dxx_to_Dzz.{nii,nii.gz}" + + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" + +authors: + - "@atsuch" +maintainers: + - "@atsuch" diff --git a/modules/nf-neuro/tensor/ratio/tests/main.nf.test b/modules/nf-neuro/tensor/ratio/tests/main.nf.test new file mode 100644 index 00000000..d14473dc --- /dev/null +++ b/modules/nf-neuro/tensor/ratio/tests/main.nf.test @@ -0,0 +1,78 @@ +// TODO nf-core: Once you have added the required tests, please run the following command to build this file: +// nf-core modules test tensor/ratio +nextflow_process { + + name "Test Process TENSOR_RATIO" + script "../main.nf" + process "TENSOR_RATIO" + + tag "modules" + tag "modules_nfcore" + tag "tensor" + tag "tensor/ratio" + + tag "subworkflows" + tag "subworkflows/load_test_data" + + setup { + run("LOAD_TEST_DATA", alias: "LOAD_DATA") { + script "../../../../../subworkflows/nf-neuro/load_test_data/main.nf" + process { + """ + input[0] = Channel.from( [ "dti.zip" ] ) + input[1] = "test.load-test-data" + """ + } + } + } + test("tensorratio - classic") { + when { + process { + """ + input[0] = LOAD_DATA.out.test_data_directory.map{ + test_data_directory -> [ + [ id:'test', single_end:false ], // meta map + file("\${test_data_directory}/dti/tensor.nii.gz") + ] + } + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } + + // TODO nf-core: Change the test name preferably indicating the test-data and file-format used but keep the " - stub" suffix. + test("tensorratio - stub") { + + options "-stub" + + when { + process { + """ + input[0] = LOAD_DATA.out.test_data_directory.map{ + test_data_directory -> [ + [ id:'test', single_end:false ], // meta map + file("\${test_data_directory}/dti/tensor.nii.gz") + ] + } + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } + +} diff --git a/modules/nf-neuro/tensor/ratio/tests/main.nf.test.snap b/modules/nf-neuro/tensor/ratio/tests/main.nf.test.snap new file mode 100644 index 00000000..1111d6c5 --- /dev/null +++ b/modules/nf-neuro/tensor/ratio/tests/main.nf.test.snap @@ -0,0 +1,60 @@ +{ + "tensorratio - classic": { + "content": [ + { + "0": [ + + ], + "1": [ + + ], + "2": [ + + ], + "tensor_x_to_y": [ + + ], + "tensor_x_to_z": [ + + ], + "versions": [ + + ] + } + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.10.4" + }, + "timestamp": "2025-02-27T14:05:10.553221131" + }, + "tensorratio - stub": { + "content": [ + { + "0": [ + + ], + "1": [ + + ], + "2": [ + + ], + "tensor_x_to_y": [ + + ], + "tensor_x_to_z": [ + + ], + "versions": [ + + ] + } + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.10.4" + }, + "timestamp": "2025-02-27T14:05:28.311339916" + } +} \ No newline at end of file diff --git a/modules/nf-neuro/tensor/ratio/tests/tags.yml b/modules/nf-neuro/tensor/ratio/tests/tags.yml new file mode 100644 index 00000000..d1b52ca0 --- /dev/null +++ b/modules/nf-neuro/tensor/ratio/tests/tags.yml @@ -0,0 +1,2 @@ +tensor/ratio: + - "modules/nf-neuro/tensor/ratio/**"