Skip to content

Commit

Permalink
create pipeline fiber cup
Browse files Browse the repository at this point in the history
  • Loading branch information
ThoumyreStanislas committed Nov 29, 2023
1 parent 800b48d commit 754962f
Show file tree
Hide file tree
Showing 21 changed files with 1,623 additions and 316 deletions.
119 changes: 63 additions & 56 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -11,72 +11,79 @@

nextflow.enable.dsl = 2

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GENOME PARAMETER VALUES
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
params.help = false

// TODO nf-core: Remove this line if you don't need a FASTA file
// This is an example of how to use getGenomeAttribute() to fetch parameters
// from igenomes.config using `--genome`
params.fasta = WorkflowMain.getGenomeAttribute(params, 'fasta')
// Importing modules and processes

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
VALIDATE & PRINT PARAMETER SUMMARY
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
include { DENOISING_MPPCA } from "./modules/nf-scil/denoising/mppca/main.nf"
include { UTILS_EXTRACTB0 } from "../modules/nf-scil/utils/extractb0/main.nf"
include { BETCROP_FSLBETCROP } from "./modules/nf-scil/betcrop/fslbetcrop/main.nf"
include { PREPROC_N4 } from "./modules/nf-scil/preproc/n4/main.nf"
include { RECONST_DTIMETRICS } from "./modules/nf-scil/reconst/dtimetrics/main.nf"
include { RECONST_FRF } from "./modules/nf-scil/reconst/frf/main.nf"
include { RECONST_FODF } from "./modules/nf-scil/reconst/fodf/main.nf"
include { TRACKING_LOCALTRACKING } from "./modules/nf-scil/tracking/localtracking/main.nf"

include { validateParameters; paramsHelp } from 'plugin/nf-validation'
workflow {

// Print help message if needed
if (params.help) {
def logo = NfcoreTemplate.logo(workflow, params.monochrome_logs)
def citation = '\n' + WorkflowMain.citation(workflow) + '\n'
def String command = "nextflow run ${workflow.manifest.name} --input samplesheet.csv --genome GRCh37 -profile docker"
log.info logo + paramsHelp(command) + citation + NfcoreTemplate.dashedLine(params.monochrome_logs)
System.exit(0)
}
main:

// Validate input parameters
if (params.validate_params) {
validateParameters()
}
dwi_channel = Channel.fromFilePairs("$input/**/*dwi.nii.gz", size: 1, flat: true)
{ fetch_id(it.parent, input) }
bval_channel = Channel.fromFilePairs("$input/**/*bval", size: 1, flat: true)
{ fetch_id(it.parent, input) }
bvec_channel = Channel.fromFilePairs("$input/**/*bvec", size: 1, flat: true)
{ fetch_id(it.parent, input) }

WorkflowMain.initialise(workflow, params, log)
// ** Denoising ** //
DENOISING_MPPCA(dwi_channel)

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NAMED WORKFLOW FOR PIPELINE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
// ** Extract b0 ** //
b0_channel = DENOISING_MPPCA.out.dwi
.combine(bval_channel)
.combine(bvec_channel)
UTILS_EXTRACTB0(b0_channel)

include { FIBERCUP } from './workflows/fibercup'
// ** Bet ** //
bet_channel = DENOISING_MPPCA.out.dwi
.combine(bval_channel)
.combine(bvec_channel)
BETCROP_FSLBETCROP(bet_channel)

//
// WORKFLOW: Run main nf-core/fibercup analysis pipeline
//
workflow NFCORE_FIBERCUP {
FIBERCUP ()
}
// ** N4 ** //
n4_channel = BETCROP_FSLBETCROP.out.dwi
.combine(UTILS_EXTRACTB0.out.b0)
.combine(BETCROP_FSLBETCROP.out.mask)
PREPROC_N4(n4_channel)

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RUN ALL WORKFLOWS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
// ** DTI ** //
dti_channel = PREPROC_N4.out.dwi
.combine(bval_channel)
.combine(bvec_channel)
RECONST_DTIMETRICS(dti_channel)

// ** FRF ** //
frf_channel = PREPROC_N4.out.dwi
.combine(bval_channel)
.combine(bvec_channel)
.combine(b0_mask_channel)
RECONST_FRF(frf_channel)

// ** FODF ** //
fodf_channel = PREPROC_N4.out.dwi
.combine(bval_channel)
.combine(bvec_channel)
.combine(b0_mask_channel)
.combine(RECONST_DTIMETRICS.out.fa)
.combine(RECONST_DTIMETRICS.out.md)
.combine(RECONST_FRF.out.frf)
RECONST_FODF(fodf_channel)

// ** Local Tracking ** //
tracking_channel = RECONST_FODF.out.fodf
.combine(tracking_mask_channel)
.combine(seed_channel)
TRACKING_LOCALTRACKING(tracking_channel)

//
// WORKFLOW: Execute a single named workflow for the pipeline
// See: https://github.com/nf-core/rnaseq/issues/619
//
workflow {
NFCORE_FIBERCUP ()
}

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
THE END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
51 changes: 51 additions & 0 deletions modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,57 @@
}
}
}
},
"https://github.com/scilus/nf-scil.git": {
"modules": {
"nf-scil": {
"betcrop/fslbetcrop": {
"branch": "main",
"git_sha": "701c3dacd90d5129ac11b030dbf461b221dd6937",
"installed_by": ["modules"]
},
"denoising/mppca": {
"branch": "main",
"git_sha": "98796d3551ad5c0ebf6356e375d3850e7cfc64fe",
"installed_by": ["modules"]
},
"denoising/nlmeans": {
"branch": "main",
"git_sha": "c91e5d948830cfc5fc83b984060dd22bf269d81b",
"installed_by": ["modules"]
},
"preproc/n4": {
"branch": "main",
"git_sha": "7eea58371b89dfe254989183fd23262e233d4653",
"installed_by": ["modules"]
},
"reconst/dtimetrics": {
"branch": "main",
"git_sha": "ef9ea4fd26019062173a9bba52ca4914a4944c0c",
"installed_by": ["modules"]
},
"reconst/fodf": {
"branch": "main",
"git_sha": "4c325c5be9a4f8d6a45172d5b6a9fc932c945b0f",
"installed_by": ["modules"]
},
"reconst/frf": {
"branch": "main",
"git_sha": "1c1dda1aae448bc64bc738d13ddcca76ae5448c8",
"installed_by": ["modules"]
},
"tracking/pfttracking": {
"branch": "main",
"git_sha": "0560d8365bdb14d3722aebbd9f3d3be3a70698bb",
"installed_by": ["modules"]
},
"utils/extractb0": {
"branch": "main",
"git_sha": "6b200ce524794bd512c5590bba38c2662dce1e46",
"installed_by": ["modules"]
}
}
}
}
}
}
75 changes: 75 additions & 0 deletions modules/nf-scil/betcrop/fslbetcrop/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

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

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

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

output:
tuple val(meta), path("*dwi_bet_cropped.nii.gz") , emit: dwi
tuple val(meta), path("*dwi_bet_cropped_mask.nii.gz") , emit: mask
tuple val(meta), path("*dwi_boundingBox.pkl") , emit: bbox
path "versions.yml" , emit: versions

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

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

def b0_thr = task.ext.b0_thr ? "--b0_thr " + task.ext.b0_thr : ""
def bet_dwi_f = task.ext.bet_dwi_f ? "-f " + task.ext.bet_dwi_f : ""

"""
export ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=1
export OMP_NUM_THREADS=1
export OPENBLAS_NUM_THREADS=1
scil_extract_b0.py $dwi $bval $bvec ${prefix}__b0.nii.gz --mean \
$b0_thr --force_b0_threshold
bet ${prefix}__b0.nii.gz ${prefix}__b0_bet.nii.gz -m -R $bet_dwi_f
scil_image_math.py convert ${prefix}__b0_bet_mask.nii.gz ${prefix}__b0_bet_mask.nii.gz --data_type uint8 -f
mrcalc $dwi ${prefix}__b0_bet_mask.nii.gz -mult ${prefix}__dwi_bet.nii.gz -quiet -nthreads 1
scil_crop_volume.py $dwi ${prefix}__dwi_bet_cropped.nii.gz -f \
--output_bbox ${prefix}__dwi_boundingBox.pkl -f
scil_crop_volume.py ${prefix}__b0_bet_mask.nii.gz ${prefix}__dwi_bet_cropped_mask.nii.gz -f\
--input_bbox ${prefix}__dwi_boundingBox.pkl -f
scil_image_math.py convert ${prefix}__dwi_bet_cropped_mask.nii.gz ${prefix}__dwi_bet_cropped_mask.nii.gz \
--data_type uint8 -f
cat <<-END_VERSIONS > versions.yml
"${task.process}":
scilpy: 1.6.0
mrtrix: \$(mrcalc -version 2>&1 | sed -n 's/== mrcalc \\([0-9.]\\+\\).*/\\1/p')
fsl: \$(flirt -version 2>&1 | sed -n 's/FLIRT version \\([0-9.]\\+\\)/\\1/p')
END_VERSIONS
"""

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

"""
scil_extract_b0.py -h
bet -h
scil_image_math.py -h
mrcalc -h
scil_crop_volume.py -h
touch ${prefix}__dwi_bet_cropped.nii.gz
touch ${prefix}__dwi_bet_cropped_mask.nii.gz
cat <<-END_VERSIONS > versions.yml
"${task.process}":
scilpy: 1.6.0
mrtrix: \$(mrcalc -version 2>&1 | sed -n 's/== mrcalc \\([0-9.]\\+\\).*/\\1/p')
fsl: \$(flirt -version 2>&1 | sed -n 's/FLIRT version \\([0-9.]\\+\\)/\\1/p')
END_VERSIONS
"""
}
70 changes: 70 additions & 0 deletions modules/nf-scil/betcrop/fslbetcrop/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/yaml-schema.json
name: "betcrop_fslbetcrop"
description: Perform Brain extraction using FSL BET followed by cropping empty planes around the data.
keywords:
- DWI
- BET
- Crop
tools:
- "FSL":
description: "FSL Toolbox and Scilpy Toolbox"
homepage: "https://fsl.fmrib.ox.ac.uk/fsl/fslwiki"
- "Scilpy":
description: "The Sherbrooke Connectivity Imaging Lab (SCIL) Python dMRI processing toolbox."
homepage: "https://github.com/scilus/scilpy.git"
- "MRtrix3":
description: "Toolbox for image processing, analysis and visualisation of dMRI."
homepage: "https://mrtrix.readthedocs.io/en/latest/"

input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'test', single_end:false ]`
- dwi:
type: file
description: Nifti DWI volume to perform BET + crop.
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"

output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'test', single_end:false ]`
- versions:
type: file
description: File containing software versions
pattern: "versions.yml"

- dwi:
type: file
description: Nifti DWI volume brain-extracted and cropped.
pattern: "*dwi_bet_cropped.{nii,nii.gz}"

- mask:
type: file
description: DWI mask brain-extracted and cropped.
pattern: "*dwi_bet_cropped_mask.{nii,nii.gz}"

- bbox:
type: file
description: DWI BoundingBox used for cropping.
pattern: "*dwi_boundingBox.pkl"

authors:
- "@gagnonanthony"
55 changes: 55 additions & 0 deletions modules/nf-scil/denoising/mppca/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

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

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

input:
tuple val(meta), path(dwi)

output:
tuple val(meta), path("*_dwi_denoised.nii.gz") , emit: image
path "versions.yml" , emit: versions

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

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

"""
export ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=1
export OMP_NUM_THREADS=1
export OPENBLAS_NUM_THREADS=1
dwidenoise $dwi ${prefix}__pre_dwi_denoised.nii.gz $extent -nthreads 1
fslmaths ${prefix}__pre_dwi_denoised.nii.gz -thr 0 ${prefix}_dwi_denoised.nii.gz
cat <<-END_VERSIONS > versions.yml
"${task.process}":
mrtrix: \$(mrcalc -version 2>&1 | sed -n 's/== mrcalc \\([0-9.]\\+\\).*/\\1/p')
fsl: \$(flirt -version 2>&1 | sed -n 's/FLIRT version \\([0-9.]\\+\\)/\\1/p')
END_VERSIONS
"""

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

"""
dwidenoise -h
fslmaths -h
touch ${prefix}_dwi_denoised.nii.gz
cat <<-END_VERSIONS > versions.yml
"${task.process}":
mrtrix: \$(mrcalc -version 2>&1 | sed -n 's/== mrcalc \\([0-9.]\\+\\).*/\\1/p')
fsl: \$(flirt -version 2>&1 | sed -n 's/FLIRT version \\([0-9.]\\+\\)/\\1/p')
END_VERSIONS
"""
}
Loading

0 comments on commit 754962f

Please sign in to comment.