Skip to content

Part 4: Install and use a new nf-neuro module

1. List available modules

Use the nf-core modules list command to check available modules. It supports remote (for online repositories) and local (for installed modules). You can filter modules using category name (bundle, denoising, reconst, …). To list all modules available on nf-neuro/modules, you can use nf-core modules list remote, which will print all available modules to the terminal.

Terminal window
# List all modules
nf-core modules list remote

2. Install a new module

Now, you can install the modules you want to include in your pipeline. Let’s install the denoising/mppca module for DWI denoising. You can install the module using nf-core modules install command. The new module will be installed to the ./modules/nf-neuro/modules/ directory.

Terminal window
nf-core modules install denoising/mppca

3. Configure and use the module

The purpose of adding this module is to denoise the DWI image before computing the DTI metrics. To do this, simply repeat the sequence of sub-steps seen in Part 3: Use and configure a nf-neuro module.

  1. Include the module in your main.nf : include { DENOISING_MPPCA } from './modules/nf-neuro/denoising/mppca/main'

  2. Use the module in the workflow. The MPPCA denoising module requires only the DWI image, opposed to the DTI_METRICS modules which takes the dwi volume with its bval/bvec directly. Both can take a mask as input, but it is optional.

    The challenge is to leverage Nextflow tools to restructure the input data into individual channels, making it easier to handle. The goal is to efficiently extract individual files, such as the dwi image or the bval and bvec files. To achieve this, we’ll use Nextflow’s multiMap operator to generate multiple output channels from a single input channel, as shown below.

    workflow {
    // ** Now call your input workflow to fetch your files ** //
    data = get_data()
    input_dti_metric = data.dwi.map{ it + [[]] }
    input_dti_metric.view()
    RECONST_DTIMETRICS( input_dti_metric )
    }
  3. Configure the denosing module in the nextflow.config using the API Documentation as a reference.

  4. Adapt the input for RECONST_DTIMETRICS module to attach it after the newly included denoised DWI module, reusing its outputs as inputs.

    workflow {
    // ** Now call your input workflow to fetch your files ** //
    data = get_data()
    ch_dwi_bvalbvec = data.dwi
    .multiMap { meta, dwi, bval, bvec ->
    dwi: [ meta, dwi ]
    bvs_files: [ meta, bval, bvec ]
    dwi_bval_bvec: [ meta, dwi, bval, bvec ]
    }
    ch_denoise_dwi = ch_dwi_bvalbvec.dwi
    .map{ it + [[]] }
    }

4. Verify your files

#!/usr/bin/env nextflow
include { RECONST_DTIMETRICS } from './modules/nf-neuro/reconst/dtimetrics/main'
include { DENOISING_MPPCA } from './modules/nf-neuro/denoising/mppca/main'
workflow get_data {
main:
if ( !params.input ) {
log.info "You must provide an input directory containing all images using:"
log.info ""
log.info " --input=/path/to/[input] Input directory containing your subjects"
log.info " |"
log.info " ├-- S1"
log.info " | └-- ses-01"
log.info " | | ├-- anat"
log.info " | | | |--*t1.nii.gz"
log.info " | | |--dwi"
log.info " | | | |--*dwi.nii.gz"
log.info " | | | ├-- *dwi.bval"
log.info " | | | └-- *dwi.bvec"
log.info " | └-- ses-02"
log.info " └-- S2"
log.info " └-- ses-01"
log.info " | ├-- anat"
log.info " | | |--*t1.nii.gz"
log.info " | |--dwi"
log.info " | | |--*dwi.nii.gz"
log.info " | | ├-- *dwi.bval"
log.info " | | └-- *dwi.bvec"
log.info " └-- ses-02"
log.info ""
error "Please resubmit your command with the previous file structure."
}
input = file(params.input)
// ** Loading all files. ** //
dwi_channel = Channel.fromFilePairs("$input/**/**/dwi/*dwi.{nii.gz,bval,bvec}", size: 3, flat: true)
{ it.parent.parent.parent.name + "_" + it.parent.parent.name}
.map{ sid, bvals, bvecs, dwi -> [ [id: sid], dwi, bvals, bvecs ] }
emit:
dwi = dwi_channel
}
workflow {
inputs = get_data()
// Use Multimap to split the tuple into multi inputs structure
ch_dwi_bvalbvec = inputs.dwi
.multiMap { meta, dwi, bval, bvec ->
dwi: [ meta, dwi ]
bvs_files: [ meta, bval, bvec ]
dwi_bval_bvec: [ meta, dwi, bval, bvec ]
}
// Denoising DWI
input_dwi_denoise = ch_dwi_bvalbvec.dwi
.map{ it + [[]] }
DENOISING_MPPCA( input_dwi_denoise )
// Fetch specific output
ch_dwi_denoised = DENOISING_MPPCA.out.image
// Input DTI update with DWI denoised output
input_dti_denoised = ch_dwi_denoised
.join(ch_dwi_bvalbvec.bvs_files)
.map{ it + [[]] }
RECONST_DTIMETRICS( input_dti_denoised )
}

5. Run nextflow

Now, you can run nextflow..

Terminal window
nextflow run main.nf --input data -profile docker

Check your resulting images in the results folder!