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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
69 changes: 47 additions & 22 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include { DENOISING_MPPCA } from './modules/nf-neuro/denoising/mppca/main.nf'
include { PREPROC_SINGLEEDDY } from './modules/local/preproc/singleeddy/main.nf'
include { UTILS_EXTRACTB0 } from './modules/nf-neuro/utils/extractb0/main.nf'
include { NNUNET } from './subworkflows/local/nnunet/'
include { BET } from './subworkflows/local/bet/main.nf'
include { MOUSE_N4 } from './modules/local/mouse/n4/main.nf'
include { IMAGE_RESAMPLE as RESAMPLE_DWI} from './modules/nf-neuro/image/resample/main.nf'
include { IMAGE_RESAMPLE as RESAMPLE_MASK} from './modules/nf-neuro/image/resample/main.nf'
Expand Down Expand Up @@ -36,13 +37,17 @@ workflow get_data {
log.info ""
log.info " [input]"
log.info " ├-- S1"
log.info " | ├-- *dwi.nii.gz"
log.info " | ├-- *dwi.bval"
log.info " | └-- *dwi.bvec"
log.info " | ├-- *dwi.bvec"
log.info " | ├-- *dwi.nii.gz"
log.info " | ├-- *anat.nii.gz (optional)"
log.info " | └-- *mask.nii.gz (optional)"
log.info " └-- S2"
log.info " ├-- *dwi.nii.gz"
log.info " ├-- *dwi.bval"
log.info " └-- *dwi.bvec"
log.info " ├-- *dwi.bval"
log.info " ├-- *dwi.bvec"
log.info " ├-- *dwi.nii.gz"
log.info " ├-- *anat.nii.gz (optional)"
log.info " └-- *mask.nii.gz (optional)"
log.info ""
log.info ""
error "Please resubmit your command with the previous file structure."
Expand All @@ -57,6 +62,10 @@ workflow get_data {
.map { mask_file -> def sid = mask_file.parent.name
[[id: sid], mask_file] }

anat_channel = Channel.fromPath("$input/**/*anat.nii.gz")
.map { anat_file -> def sid = anat_file.parent.name
[[id: sid], anat_file] }

template_channel = Channel.fromPath("$projectDir/assets/reference_rgb_mqc.png")

lut_channel = Channel.of([
Expand All @@ -68,6 +77,7 @@ workflow get_data {
emit:
dwi = dwi_channel
mask = mask_channel
anat = anat_channel
template_rgb = template_channel
lut = lut_channel
}
Expand Down Expand Up @@ -96,6 +106,8 @@ workflow {
}
ch_ref_rgb = data.template_rgb
ch_lut = data.lut
ch_bet = data.anat
ch_mask = Channel.empty()

if ( params.run_preqc ) {
PRE_QC(ch_dwi_bvalbvec.dwi.join(ch_dwi_bvalbvec.bvs_files).combine(ch_ref_rgb))
Expand All @@ -105,6 +117,7 @@ workflow {
log.warn('Using the output from the preqc module is highly experimental. Please be careful.')
ch_after_preqc = PRE_QC.out.dwi
bvs_after_preqc = PRE_QC.out.bvs

}
else {
ch_after_preqc = Channel.empty()
Expand Down Expand Up @@ -136,21 +149,31 @@ workflow {
else {
ch_after_eddy = ch_eddy
}

UTILS_EXTRACTB0(ch_after_eddy)
ch_nnunet = ch_after_eddy.join(UTILS_EXTRACTB0.out.b0)
.join(data.mask, by: 0, remainder: true)
.map { meta, dwi, bval, bvec, b0, mask ->
[meta, dwi, bval, b0, mask ?: [ ]]} // Use empty list if mask is null

NNUNET(ch_nnunet)

if (params.invivo) {
BET(ch_bet)
ch_mask = BET.out.mask
}
else if ( params.data_masked ) {
ch_mask = data.mask
}
else {
ch_nnunet = ch_after_eddy.join(UTILS_EXTRACTB0.out.b0)
.map { meta, dwi, bval, bvec, b0 ->
[meta, dwi, bval, b0 ?: [ ]]}

NNUNET(ch_nnunet)

ch_mask = NNUNET.out.mask
}

if ( params.run_n4 ) {
ch_N4 = ch_after_eddy
.map{ meta, dwi, _bval, _bvec ->
tuple(meta, dwi)}
.join(UTILS_EXTRACTB0.out.b0)
.join(NNUNET.out.mask)
.join(ch_mask)
MOUSE_N4(ch_N4)
ch_after_n4 = MOUSE_N4.out.dwi_n4
}
Expand All @@ -161,15 +184,15 @@ workflow {

if ( params.run_resampling ) {
RESAMPLE_DWI(ch_after_n4.map{ meta, dwi -> [meta, dwi, []] }) // Add an empty list for the optional reference image
RESAMPLE_MASK(NNUNET.out.mask.map{ meta, mask -> [meta, mask, []] })
RESAMPLE_MASK(ch_mask.map{ meta, mask -> [meta, mask, []] })
IMAGE_CONVERT(RESAMPLE_MASK.out.image)

dwi_after_resample = RESAMPLE_DWI.out.image
mask_after_resample = IMAGE_CONVERT.out.image
}
else {
dwi_after_resample = ch_after_n4
IMAGE_CONVERT(NNUNET.out.mask)
IMAGE_CONVERT(ch_mask)
mask_after_resample = IMAGE_CONVERT.out.image
}

Expand All @@ -187,13 +210,15 @@ workflow {
ch_multiqc_files = ch_multiqc_files.mix(RECONST_DTIMETRICS.out.mqc)

/* FODF */
RECONST_FRF(ch_for_reconst.map{ it + [[], [], []]})
ch_for_reconst_fodf = ch_for_reconst
.join(RECONST_DTIMETRICS.out.fa)
.join(RECONST_DTIMETRICS.out.md)
.join(RECONST_FRF.out.frf)
.map{ it + [[], []]}
RECONST_FODF(ch_for_reconst_fodf)
if ( params.run_fodf_metrics ) {
RECONST_FRF(ch_for_reconst.map{ it + [[], [], []]})
ch_for_reconst_fodf = ch_for_reconst
.join(RECONST_DTIMETRICS.out.fa)
.join(RECONST_DTIMETRICS.out.md)
.join(RECONST_FRF.out.frf)
.map{ it + [[], []]}
RECONST_FODF(ch_for_reconst_fodf)
}

/* QBALL */
RECONST_QBALL(ch_for_reconst)
Expand Down
21 changes: 8 additions & 13 deletions modules/local/mouse/betnnunet/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ process MOUSE_BETNNUNET {
container "scilus/nnunet_bet_mouse:0.1.0_cpu"

input:
tuple val(meta), path(dwi), path(b0), path(mask)
tuple val(meta), path(dwi), path(b0)
output:
tuple val(meta), path("*__mask.nii.gz") , emit: mask
path "versions.yml" , emit: versions
Expand All @@ -17,21 +17,16 @@ process MOUSE_BETNNUNET {
def prefix = task.ext.prefix ?: "${meta.id}"

"""
if [[ -f "$mask" ]]
then
mv $mask ${prefix}__mask.nii.gz
else
export nnUNet_raw="Database/RAW/"
export nnUNet_preprocessed="Database/PRE/"
export nnUNet_results="Database/RESULTS/"
mkdir -p Database/RAW/Dataset012_ExVivoBrainFSboth/imagesTs
ln -s /Database/RAW/Dataset012_ExVivoBrainFSboth/dataset.json Database/RAW/Dataset012_ExVivoBrainFSboth/dataset.json
ln -s /Database/RESULTS Database/RESULTS
mv $b0 Database/RAW/Dataset012_ExVivoBrainFSboth/imagesTs/exvivobrain_000_0000.nii.gz
mv $dwi Database/RAW/Dataset012_ExVivoBrainFSboth/imagesTs/exvivobrain_000_0001.nii.gz
nnUNetv2_predict -i Database/RAW/Dataset012_ExVivoBrainFSboth/imagesTs -o ./ -d 012 -c 3d_fullres -f all -npp 1 -nps 1 -device 'cpu' -tr nnUNetTrainer -chk checkpoint_best.pth
mv exvivobrain_000.nii.gz ${prefix}__mask.nii.gz
fi
mkdir -p Database/RAW/Dataset012_ExVivoBrainFSboth/imagesTs
ln -s /Database/RAW/Dataset012_ExVivoBrainFSboth/dataset.json Database/RAW/Dataset012_ExVivoBrainFSboth/dataset.json
ln -s /Database/RESULTS Database/RESULTS
mv $b0 Database/RAW/Dataset012_ExVivoBrainFSboth/imagesTs/exvivobrain_000_0000.nii.gz
mv $dwi Database/RAW/Dataset012_ExVivoBrainFSboth/imagesTs/exvivobrain_000_0001.nii.gz
nnUNetv2_predict -i Database/RAW/Dataset012_ExVivoBrainFSboth/imagesTs -o ./ -d 012 -c 3d_fullres -f all -npp 1 -nps 1 -device 'cpu' -tr nnUNetTrainer -chk checkpoint_best.pth
mv exvivobrain_000.nii.gz ${prefix}__mask.nii.gz

cat <<-END_VERSIONS > versions.yml
"${task.process}":
Expand Down
3 changes: 3 additions & 0 deletions modules/local/mouse/brainextraction/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
channels: []
dependencies: []
name: "mouse_bet"
37 changes: 37 additions & 0 deletions modules/local/mouse/brainextraction/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
process MOUSE_BRAINEXTRACTION {
tag "$meta.id"
label 'process_high'

container "scilus/antspynet:dev"

input:
tuple val(meta), path(anat)
output:
tuple val(meta), path("*__mask.nii.gz") , emit: mask
path "versions.yml" , emit: versions

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

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

"""
antsMouseBrainExtraction $anat ${prefix}__mask.nii.gz

cat <<-END_VERSIONS > versions.yml
"${task.process}":
ants: \$(antsMouseBrainExtraction --version 2>&1 | sed -n 's/ANTs Version: v\\([0-9.]\\+\\)/\\1/p')
END_VERSIONS
"""

stub:
"""
antsMouseBrainExtraction -h

cat <<-END_VERSIONS > versions.yml
"${task.process}":
ants: \$(antsMouseBrainExtraction --version 2>&1 | sed -n 's/ANTs Version: v\\([0-9.]\\+\\)/\\1/p')
END_VERSIONS
"""
}
44 changes: 44 additions & 0 deletions modules/local/mouse/brainextraction/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/scilus/nf-neuro/main/modules/meta-schema.json
name: "brainextraction"
description: Extraction of the brain from anatomical images using BET
keywords:
- BET
- T1
tools:
- "scilpy":
description: "The Sherbrooke Connectivity Imaging Lab (SCIL) Python dMRI processing toolbox."
homepage: "https://github.com/scilus/scilpy.git"
- "FSL":
description: "FSL Toolbox and Scilpy Toolbox"
homepage: "https://fsl.fmrib.ox.ac.uk/fsl/fslwiki"
input:
# Only when we have meta
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'test', single_end:false ]`

- anat:
type: file
description: Anat Nifti image
pattern: "*.{nii,nii.gz}"


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

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


authors:
- "@EliseCos"
3 changes: 3 additions & 0 deletions modules/local/mouse/convertbet/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
channels: []
dependencies: []
name: "mouse_convertbet"
51 changes: 51 additions & 0 deletions modules/local/mouse/convertbet/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
process MOUSE_CONVERTBET {
tag "$meta.id"
label 'process_low'

container "scilus/scilus:2.2.0"

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

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

script:
def prefix = task.ext.prefix ?: "${meta.id}"
def nb_vox = task.ext.nb_vox ?: ""
"""
fslmaths ${image} -bin ${prefix}_mask.nii.gz

scil_volume_math erosion ${prefix}_mask.nii.gz $nb_vox ${prefix}_mask.nii.gz --data_type uint8 -f
ImageMath 3 ${prefix}_mask.nii.gz GetLargestComponent ${prefix}_mask.nii.gz
scil_volume_math dilation ${prefix}_mask.nii.gz $nb_vox ${prefix}_mask.nii.gz --data_type uint8 -f
ImageMath 3 ${prefix}_mask.nii.gz FillHoles ${prefix}_mask.nii.gz

cat <<-END_VERSIONS > versions.yml
"${task.process}":
scilpy: \$(uv -q -n pip list | grep scilpy | tr -s ' ' | cut -d' ' -f2)
fsl: \$(flirt -version 2>&1 | sed -n 's/FLIRT version \\([0-9.]\\+\\)/\\1/p')
ants: \$(ImageMath --version 2>&1 | sed -n 's/ANTs Version: v\\([0-9.]\\+\\)/\\1/p')
END_VERSIONS
"""

stub:
def prefix = task.ext.prefix ?: "${meta.id}"
"""
fslmaths
scil_volume_math -h
ImageMath

touch ${prefix}_mask.nii.gz

cat <<-END_VERSIONS > versions.yml
"${task.process}":
scilpy: \$(uv pip -q -n list | grep scilpy | tr -s ' ' | cut -d' ' -f2)
fsl: \$(flirt -version 2>&1 | sed -n 's/FLIRT version \\([0-9.]\\+\\)/\\1/p')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing ants

ants: \$(ImageMath --version 2>&1 | sed -n 's/ANTs Version: v\\([0-9.]\\+\\)/\\1/p')
END_VERSIONS
"""
}
44 changes: 44 additions & 0 deletions modules/local/mouse/convertbet/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/scilus/nf-neuro/main/modules/meta-schema.json
name: "mouse_convertjson"
description: Convert stats to JSON
keywords:
- stats
- convert
tools:
- "scilpy":
description: "The Sherbrooke Connectivity Imaging Lab (SCIL) Python dMRI processing toolbox."
homepage: "https://github.com/scilus/scilpy.git"
input:
# Only when we have meta
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'test', single_end:false ]`

- stats:
type: list
description: DWI Nifti image
pattern: "*.{nii,nii.gz}"

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

- stats_json:
type: file
description: File with stats
pattern: "stats_reorganized.json"

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

authors:
- "@EliseCos"
1 change: 1 addition & 0 deletions modules/local/mouse/convertjson/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ process MOUSE_CONVERTJSON {
"""

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

Expand Down
3 changes: 3 additions & 0 deletions modules/local/mouse/preparebet/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
channels: []
dependencies: []
name: "mouse_preparebet"
Loading
Loading