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.
# List all modules nf-core modules list remote
INFO Modules available from https://github.com/scilus/nf-neuro.git (main):
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓┃ Module Name ┃┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩│ betcrop/antsbet ││ betcrop/fslbetcrop ││ betcrop/synthbet ││ bundle/centroid ││ bundle/coloring ││ bundle/fixelafd ││ bundle/labelmap ││ bundle/recognize ││ bundle/stats ││ bundle/uniformize ││ connectivity/afdfixel ││ connectivity/decompose ││ connectivity/visualize ││ denoising/mppca ││ denoising/nlmeans ││ image/applymask ││ image/burnvoxels ││ image/convert ││ image/cropvolume ││ image/powderaverage ││ image/resample ││ io/nii2dcm ││ io/readbids ││ preproc/eddy ││ preproc/gibbs ││ preproc/n4 ││ preproc/normalize ││ preproc/topup ││ reconst/diffusivitypriors ││ reconst/dtimetrics ││ reconst/fodf ││ reconst/freewater ││ reconst/frf ││ reconst/ihmt ││ reconst/meanfrf ││ reconst/noddi ││ reconst/shmetrics ││ reconst/shsignal ││ registration/anattodwi ││ registration/ants ││ registration/antsapplytransforms ││ registration/convert ││ registration/easyreg ││ registration/synthregistration ││ registration/tractogram ││ segmentation/fastseg ││ segmentation/fastsurfer ││ segmentation/freesurferseg ││ segmentation/fsreconall ││ segmentation/synthseg ││ stats/metricsinroi ││ tracking/localtracking ││ tracking/pfttracking ││ tractogram/densitymap ││ tractogram/removeinvalid ││ tractogram/resample ││ utils/extractb0 │└──────────────────────────────────┘
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.
nf-core modules install denoising/mppca
You should see this output:
,--./,-. ___ __ __ __ ___ /,-._.--~\|\ | |__ __ / ` / \ |__) |__ } {| \| | \__, \__/ | \ |___ \`-._,-`-, `._,._,'
nf-core/tools version 2.14.1 - https://nf-co.reThere is a new version of nf-core/tools available! (3.2.0)
INFO Installing 'denoising/mppca'INFO Use the following statement to include this module:
include { DENOISING_MPPCA } from '../modules/nf-neuro/denoising/mppca/main'
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.
-
Include the module in your
main.nf
:include { DENOISING_MPPCA } from './modules/nf-neuro/denoising/mppca/main'
-
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 thebval
andbvec
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 )}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 + [[]] }} -
Configure the denosing module in the
nextflow.config
using the API Documentation as a reference. -
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 + [[]] }}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 + [[]] }DENOISING_MPPCA( ch_denoise_dwi )ch_dwi_denoised = DENOISING_MPPCA.out.image// You can now reuse the outputs and supply them to another module!// Update the input for RECONST_DTIMETRICS with DWI denoised outputinput_dti_denoised = ch_dwi_denoised.join(ch_dwi_bvalbvec.bvs_files).map{ it + [[]] }// Update input nameRECONST_DTIMETRICS( input_dti_denoised )}
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 )}
profiles { docker { docker.enabled = true conda.enabled = false singularity.enabled = false podman.enabled = false shifter.enabled = false charliecloud.enabled = false apptainer.enabled = false docker.runOptions = '-u $(id -u):$(id -g)' }}
manifest { name = 'scilus/nf-neuro-tutorial' description = """nf-neuro-tutorial is a Nextflow pipeline for processing neuroimaging data.""" version = '0.1dev'}
params.input = falseparams.output = 'result'
process {
publishDir = { "${params.output}/$meta.id/${task.process.replaceAll(':', '-')}" }
withName: "DENOISING_MPPCA" { ext.extent = 3 }
withName: "RECONST_DTIMETRICS" { ext.ad = false ext.evecs = false ext.evals = false ext.fa = true ext.ga = false ext.rgb = false ext.md = true ext.mode = false ext.norm = false ext.rd = false ext.tensor = false ext.nonphysical = false ext.pulsation = false ext.residual = false ext.b0_thr_extract_b0 = 10 ext.dwi_shell_tolerance = 50 ext.max_dti_shell_value = 1200 ext.run_qc = false }}
5. Run nextflow
Now, you can run nextflow..
nextflow run main.nf --input data -profile docker
N E X T F L O W ~ version 24.10.4
Launching `main.nf` [astonishing_borg] DSL2 - revision: d69b63f305
executor > local (2)[ec/62dd72] process > DENOISING_MPPCA (sub-003_ses-01) [100%] 1 of 1 ✔[6e/837a31] process > RECONST_DTIMETRICS (sub-003_ses-01) [100%] 1 of 1 ✔Completed at: Date HourDuration : 1m 19sCPU hours : (a few seconds)Succeeded : 2
Check your resulting images in the results folder!