Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions modules/nf-neuro/reconst/noddi/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,8 @@ process RECONST_NODDI {
def set_kernels = kernels ? "--load_kernels $kernels" : "--save_kernels kernels/"
def set_mask = mask ? "--mask $mask" : ""
def compute_only = task.ext.compute_only && !kernels ? "--compute_only" : ""
def ignore_single_shell = task.ext.ignore_single_shell ?: false

"""
# Set home directory. This is problematic if the container is run
# with non-root user which does not create a home directory, whilst
# AMICO attempts to write in the home directory, raising an error.
export HOME=/tmp

# Check if data are multi-shell based on b-values and set number of clusters accordingly
# Set tolerance threshold (default 40 if not specified)
b_threshold=${task.ext.b_thr ?: 40}
Expand All @@ -58,27 +52,29 @@ process RECONST_NODDI {

if [ \$clusters -lt 3 ]; then
echo "Error: NODDI reconstruction requires multi-shell data (at least 2 non-zero b-value shells). Detected only \$clusters shell(s) with b-values: \${uniq_bvals[@]}"
if [ "$ignore_single_shell" = "false" ]; then
exit 1
fi
exit 1
else
echo "Detected \$clusters unique b-value shells: \${uniq_bvals[@]}"
fi

# Set home directory. This is problematic if the container is run
# with non-root user which does not create a home directory, whilst
# AMICO attempts to write in the home directory, raising an error.
export HOME=/tmp

scil_NODDI_maps $dwi $bval $bvec $para_diff_str $iso_diff_str $lambda1 \
$lambda2 $nb_threads $b_thr $set_mask $set_kernels --skip_b0_check $compute_only
scil_NODDI_maps $dwi $bval $bvec $para_diff_str $iso_diff_str $lambda1 \
$lambda2 $nb_threads $b_thr $set_mask $set_kernels --skip_b0_check $compute_only

if [ -z "${compute_only}" ];
then
mv results/fit_dir.nii.gz ${prefix}__dir.nii.gz
mv results/fit_NDI.nii.gz ${prefix}__icvf.nii.gz # ICVF -> NDI
mv results/fit_FWF.nii.gz ${prefix}__isovf.nii.gz # ISOVF -> FWF
mv results/fit_ODI.nii.gz ${prefix}__odi.nii.gz # ODI -> OD
if [ -z "${compute_only}" ];
then
mv results/fit_dir.nii.gz ${prefix}__dir.nii.gz
mv results/fit_NDI.nii.gz ${prefix}__icvf.nii.gz # ICVF -> NDI
mv results/fit_FWF.nii.gz ${prefix}__isovf.nii.gz # ISOVF -> FWF
mv results/fit_ODI.nii.gz ${prefix}__odi.nii.gz # ODI -> OD

scil_volume_math subtraction 1 ${prefix}__isovf.nii.gz ${prefix}__ecvf.nii.gz
scil_volume_math subtraction 1 ${prefix}__isovf.nii.gz ${prefix}__ecvf.nii.gz

rm -rf results
fi
rm -rf results
fi

cat <<-END_VERSIONS > versions.yml
Expand Down
4 changes: 1 addition & 3 deletions modules/nf-neuro/reconst/noddi/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ args:
- compute_only:
type: boolean
description: Compute kernels only.
- ignore_single_shell:
type: boolean
description: Ignore single shell data instead of raising an error. With this flag enabled, simply no output will be produced for single shell data.

output:
dir:
- - meta:
Expand Down
7 changes: 7 additions & 0 deletions subworkflows/nf-neuro/reconst_fw_noddi/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ workflow RECONST_FW_NODDI {
ch_noddi_input = ch_noddi_custom_subj
.mix( ch_noddi_custom )
.mix( ch_noddi_computed )
.filter{ _meta, _dwi, bval, _bvec, _b0_mask, _para, _iso ->
def is_multi_shell = bval.text.tokenize().unique().size() > 2
if (!is_multi_shell && !options.silence_single_shell_warnings){
log.warn "Subject ${_meta.id} has single-shell data. Skipping NODDI reconstruction."
}
return is_multi_shell
}
.map{ meta, dwi, bval, bvec, b0_mask, para, iso ->
[meta, dwi, bval, bvec, b0_mask, [], para, iso] }

Expand Down
4 changes: 4 additions & 0 deletions subworkflows/nf-neuro/reconst_fw_noddi/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ input:
type: boolean
description: If 'true', the diffusivity priors computed from the RECONST/DIFFUSIVITYPRIORS module will be averaged across all subjects. (Recommended)
default: false
silence_single_shell_warnings:
type: boolean
description: If 'true', the workflow will silence warnings about single-shell data (e.g. when filtering subjects for NODDI).
default: false
mandatory: false
output:
- noddi_dir:
Expand Down
Loading