Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Module] Freewater module #61

Merged
merged 20 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ environment.
## Contributing to the `nf-scil` project

If you want to propose a new `module` to the repository, follow the guidelines in the
[module creation](./docs/MODULE.md) documentation. we follow standards closely
[module creation](./docs/MODULE.md) documentation. We follow standards closely
aligned with `nf-core`, with some exceptions on process atomicity and how test data is
handled. Modules that don't abide to them won't be accepted and PR containing them will
be closed automatically.
Expand Down
4 changes: 2 additions & 2 deletions docs/MODULE.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ nf-core modules create \
--author @scilus \
--label process_single \
--meta \
<category/tool>
<category>/<tool>
```

You will still have to interact with the **bioconda** prompt, still select `no`.
Expand Down Expand Up @@ -217,7 +217,7 @@ nf-core modules create-test-yml \
--run-tests \
--force \
--no-prompts \
<category/tool>
<category>/<tool>
```

All the test case you defined will be run, watch out for errors ! Once everything runs
Expand Down
6 changes: 6 additions & 0 deletions modules/nf-scil/reconst/freewater/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: "reconst_freewater"
channels:
- Docker
- Apptainer
dependencies:
- "scilpy"
karanphil marked this conversation as resolved.
Show resolved Hide resolved
78 changes: 78 additions & 0 deletions modules/nf-scil/reconst/freewater/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@

process RECONST_FREEWATER {
tag "$meta.id"
label 'process_single'

container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'https://scil.usherbrooke.ca/containers/scilus_2.0.0.sif':
'scilus/scilus:2.0.0' }"

input:
tuple val(meta), path(dwi), path(bval), path(bvec), path(mask), path(kernels)

output:
tuple val(meta), path("*_dwi_fw_corrected.nii.gz") , emit: dwi_fw_corrected, optional: true
tuple val(meta), path("*_FIT_dir.nii.gz") , emit: dir, optional: true
tuple val(meta), path("*_FIT_FiberVolume.nii.gz") , emit: fibervolume, optional: true
tuple val(meta), path("*_FIT_FW.nii.gz") , emit: fw, optional: true
tuple val(meta), path("*_FIT_nrmse.nii.gz") , emit: nrmse, optional: true
path("kernels") , emit: kernels, optional: true
path "versions.yml" , emit: versions

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

script:
def prefix = task.ext.prefix ?: "${meta.id}"

def para_diff = task.ext.para_diff ? "--para_diff " + task.ext.para_diff : ""
def perp_diff_min = task.ext.perp_diff_min ? "--perp_diff_min " + task.ext.perp_diff_min : ""
def perp_diff_max = task.ext.perp_diff_max ? "--perp_diff_max " + task.ext.perp_diff_max : ""
def iso_diff = task.ext.iso_diff ? "--iso_diff " + task.ext.iso_diff : ""
def lambda1 = task.ext.lambda1 ? "--lambda1 " + task.ext.lambda1 : ""
def lambda2 = task.ext.lambda2 ? "--lambda2 " + task.ext.lambda2 : ""
def nb_threads = task.ext.nb_threads ? "--processes " + task.ext.nb_threads : ""
def b_thr = task.ext.b_thr ? "--b_thr " + task.ext.b_thr : ""
def set_kernels = kernels ? "--load_kernels $kernels" : "--save_kernels kernels/ --compute_only"
def set_mask = mask ? "--mask $mask" : ""

"""
scil_freewater_maps.py $dwi $bval $bvec $para_diff $perp_diff_min \
$perp_diff_max $iso_diff $lambda1 $lambda2 $nb_threads $b_thr \
$set_mask $set_kernels


if [ -d "$kernels" ]; then
mv results/dwi_fw_corrected.nii.gz ${prefix}__dwi_fw_corrected.nii.gz
mv results/FIT_dir.nii.gz ${prefix}__FIT_dir.nii.gz
mv results/FIT_FiberVolume.nii.gz ${prefix}__FIT_FiberVolume.nii.gz
mv results/FIT_FW.nii.gz ${prefix}__FIT_FW.nii.gz
mv results/FIT_nrmse.nii.gz ${prefix}__FIT_nrmse.nii.gz

rm -rf results
fi

cat <<-END_VERSIONS > versions.yml
"${task.process}":
scilpy: 2.0.0
END_VERSIONS
"""

stub:
def prefix = task.ext.prefix ?: "${meta.id}"

"""
scil_freewater_maps.py -h
mkdir kernels
touch "${prefix}__dwi_fw_corrected.nii.gz"
touch "${prefix}__FIT_dir.nii.gz"
touch "${prefix}__FIT_FiberVolume.nii.gz"
touch "${prefix}__FIT_FW.nii.gz"
touch "${prefix}__FIT_nrmse.nii.gz"

cat <<-END_VERSIONS > versions.yml
"${task.process}":
scilpy: 2.0.0
END_VERSIONS
"""
}
96 changes: 96 additions & 0 deletions modules/nf-scil/reconst/freewater/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/yaml-schema.json
name: "reconst_freewater"
description: Run freewater modelling pipeline using AMICO from DWI data.
keywords:
- Diffusion MRI
- Freewater
- Microstructure modeling
tools:
- "Scilpy":
description: "The Sherbrooke Connectivity Imaging Lab (SCIL) Python dMRI processing toolbox."
homepage: "https://github.com/scilus/scilpy.git"
- "Freewater":
description: "Free water elimination and mapping from diffusion MRI."
doi: "10.1002/mrm.22055"
- "AMICO":
description: "Accelerated Microstructure Imaging via Convex Optimization."
homepage: "https://github.com/daducci/AMICO"
doi: "10.1016/j.neuroimage.2014.10.026"

input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'test', single_end:false ]`

- dwi:
type: file
description: Nifti DWI file acquired with a freewater compatible protocol (single-shell or multi-shell).
pattern: "*.{nii,nii.gz}"

- bval:
type: file
description: B-values in FSL format.
pattern: "*.bval"

- bvec:
type: file
description: B-vectors in FSL format.
pattern: "*.bvec"

- mask:
type: file
description: Nifti brain mask.
pattern: "*mask.{nii,nii.gz}"

- kernels:
type: directory
description: Folder containg kernels.
pattern: "kernels"

output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'test', single_end:false ]`

- dwi_fw_corrected:
type: file
description: Nifti file freewater corrected DWI.
pattern: "*__dwi_fw_corrected.{nii,nii.gz}"

- dir:
type: file
description: Nifti file main direction.
pattern: "*__FIT_dir.{nii,nii.gz}"

- fibervolume:
type: file
description: Nifti file for fiber volume.
pattern: "*__FIT_fibervolume.{nii,nii.gz}"

- fw:
type: file
description: Nifti file for freewater (isotropic volume).
pattern: "*__FIT_FW.{nii,nii.gz}"

- nrmse:
type: file
description: Nifti file for nrmse.
pattern: "*__FIT_nrmse.{nii,nii.gz}"

- kernels:
type: directory
description: Folder containing kernels.
pattern: "kernels"

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

authors:
- "@karanphil"
85 changes: 85 additions & 0 deletions modules/nf-scil/reconst/freewater/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
nextflow_process {

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

tag "modules"
tag "modules_nfcore"
tag "reconst"
tag "reconst/freewater"

tag "subworkflows"
tag "subworkflows/load_test_data"

config "./nextflow.config"

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

test("reconst - freewater") {

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}/dwi.nii.gz", checkIfExists: true),
file("\${test_data_directory}/dwi.bval", checkIfExists: true),
file("\${test_data_directory}/dwi.bvec", checkIfExists: true),
file("\${test_data_directory}/mask.nii.gz", checkIfExists: true),
[]
]
}
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}

}

test("reconst - freewater_no_mask") {

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}/dwi.nii.gz", checkIfExists: true),
file("\${test_data_directory}/dwi.bval", checkIfExists: true),
file("\${test_data_directory}/dwi.bvec", checkIfExists: true),
[],
[]
]
}
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}
karanphil marked this conversation as resolved.
Show resolved Hide resolved

}

}