Skip to content

Commit

Permalink
Merge pull request scilus#62 from ThoumyreStanislas/t1_betcrop
Browse files Browse the repository at this point in the history
 [WIP] add t1 option in fslbetcrop module
  • Loading branch information
AlexVCaron authored Mar 1, 2024
2 parents fa34ffb + db1b02d commit 887e6ee
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 40 deletions.
57 changes: 38 additions & 19 deletions modules/nf-scil/betcrop/fslbetcrop/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ process BETCROP_FSLBETCROP {
'scilus/scilus:1.6.0' }"

input:
tuple val(meta), path(dwi), path(bval), path(bvec)
tuple val(meta), path(image), 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
tuple val(meta), path("*_bet.nii.gz") , emit: image
tuple val(meta), path("*_bet_mask.nii.gz") , emit: mask
tuple val(meta), path("*_boundingBox.pkl") , emit: bbox , optional: true
path "versions.yml" , emit: versions

when:
task.ext.when == null || task.ext.when
Expand All @@ -23,31 +23,49 @@ process BETCROP_FSLBETCROP {
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 : ""
def bet_f = task.ext.bet_f ? "-f " + task.ext.bet_f : ""
def size_dil = task.ext.size_dil ? task.ext.size_dil : ""

"""
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
if [[ -f "$bval" ]]
then
scil_extract_b0.py $image $bval $bvec ${prefix}__b0.nii.gz --mean \
$b0_thr --force_b0_threshold
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
bet ${prefix}__b0.nii.gz ${prefix}__b0_bet.nii.gz -m -R $bet_f
scil_image_math.py convert ${prefix}__b0_bet_mask.nii.gz ${prefix}__image_bet_mask.nii.gz --data_type uint8 -f
mrcalc $image ${prefix}__b0_bet_mask.nii.gz -mult ${prefix}__image_bet.nii.gz -quiet -nthreads 1
else
bet $image ${prefix}__image_bet.nii.gz -m -R $bet_f
scil_image_math.py convert ${prefix}__image_bet_mask.nii.gz ${prefix}__image_bet_mask.nii.gz --data_type uint8 -f
fi
if [ "$task.ext.crop" = "true" ];
then
scil_crop_volume.py ${prefix}__image_bet.nii.gz ${prefix}__image_bet.nii.gz -f \
--output_bbox ${prefix}__image_boundingBox.pkl -f
scil_crop_volume.py ${prefix}__image_bet_mask.nii.gz ${prefix}__image_bet_mask.nii.gz -f\
--input_bbox ${prefix}__image_boundingBox.pkl -f
scil_image_math.py convert ${prefix}__image_bet_mask.nii.gz ${prefix}__image_bet_mask.nii.gz \
--data_type uint8 -f
fi
if [ "$task.ext.dilate" = "true" ];
then
scil_image_math.py dilation ${prefix}__image_bet_mask.nii.gz $size_dil ${prefix}__image_bet_mask.nii.gz --data_type uint8 -f
fi
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
"""

Expand All @@ -62,8 +80,9 @@ process BETCROP_FSLBETCROP {
mrcalc -h
scil_crop_volume.py -h
touch ${prefix}__dwi_bet_cropped.nii.gz
touch ${prefix}__dwi_bet_cropped_mask.nii.gz
touch ${prefix}__image_bet.nii.gz
touch ${prefix}__image_bet_mask.nii.gz
touch ${prefix}__image_boundingBox.pkl
cat <<-END_VERSIONS > versions.yml
"${task.process}":
Expand Down
19 changes: 10 additions & 9 deletions modules/nf-scil/betcrop/fslbetcrop/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ name: "betcrop_fslbetcrop"
description: Perform Brain extraction using FSL BET followed by cropping empty planes around the data.
keywords:
- DWI
- T1
- BET
- Crop
tools:
Expand All @@ -24,9 +25,9 @@ input:
Groovy Map containing sample information
e.g. `[ id:'test', single_end:false ]`
- dwi:
- image:
type: file
description: Nifti DWI volume to perform BET + crop.
description: Nifti image volume to perform BET + crop.
pattern: "*.{nii,nii.gz}"

- bval:
Expand All @@ -46,20 +47,20 @@ output:
Groovy Map containing sample information
e.g. `[ id:'test', single_end:false ]`
- dwi:
- image:
type: file
description: Nifti DWI volume brain-extracted and cropped.
pattern: "*dwi_bet_cropped.{nii,nii.gz}"
description: Nifti volume brain-extracted and cropped.
pattern: "*_bet.{nii,nii.gz}"

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

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

- versions:
type: file
Expand Down
41 changes: 39 additions & 2 deletions tests/modules/nf-scil/betcrop/fslbetcrop/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
nextflow.enable.dsl = 2

include { BETCROP_FSLBETCROP } from '../../../../../modules/nf-scil/betcrop/fslbetcrop/main.nf'
include { LOAD_TEST_DATA } from '../../../../../subworkflows/nf-scil/load_test_data/main'

workflow test_betcrop_fslbetcrop {

workflow test_betcrop_fslbetcrop_dwi {
input = [
[ id:'test', single_end:false ], // meta map
file(params.test_data['betcrop']['fslbetcrop']['dwi'], checkIfExists: true),
Expand All @@ -15,3 +16,39 @@ workflow test_betcrop_fslbetcrop {

BETCROP_FSLBETCROP ( input )
}

workflow test_betcrop_fslbetcrop_t1 {

input_fetch = Channel.from( [ "others.zip" ] )

LOAD_TEST_DATA ( input_fetch, "test.test_betcrop_fslbetcrop_t1" )

input = LOAD_TEST_DATA.out.test_data_directory
.map{ test_data_directory -> [
[ id:'test', single_end:false ], // meta map
file("${test_data_directory}/t1.nii.gz"),
[],
[]

]}

BETCROP_FSLBETCROP ( input )
}

workflow test_betcrop_fslbetcrop_t1_dilate {

input_fetch = Channel.from( [ "others.zip" ] )

LOAD_TEST_DATA ( input_fetch, "test.test_betcrop_fslbetcrop_t1" )

input = LOAD_TEST_DATA.out.test_data_directory
.map{ test_data_directory -> [
[ id:'test', single_end:false ], // meta map
file("${test_data_directory}/t1.nii.gz"),
[],
[]

]}

BETCROP_FSLBETCROP ( input )
}
19 changes: 17 additions & 2 deletions tests/modules/nf-scil/betcrop/fslbetcrop/nextflow.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
process {

publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" }

withName: "BETCROP_FSLBETCROP" {
ext.bet_dwi_f = 0.16
publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" }
ext.bet_f = 0.16
ext.b0_thr = 10
ext.crop = true
ext.dilate = false
}

withName: "test_betcrop_fslbetcrop_t1:BETCROP_FSLBETCROP" {
ext.bet_f = 0.5
ext.crop = true
ext.dilate = false
}

withName: "test_betcrop_fslbetcrop_t1_dilate:BETCROP_FSLBETCROP" {
ext.bet_f = 0.5
ext.size_dil = 5
ext.crop = true
ext.dilate = true
}
}
48 changes: 40 additions & 8 deletions tests/modules/nf-scil/betcrop/fslbetcrop/test.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
- name: betcrop fslbetcrop test_betcrop_fslbetcrop
command: nextflow run ./tests/modules/nf-scil/betcrop/fslbetcrop -entry test_betcrop_fslbetcrop -c ./tests/config/nextflow.config
- name: betcrop fslbetcrop test_betcrop_fslbetcrop_dwi
command: nextflow run ./tests/modules/nf-scil/betcrop/fslbetcrop -entry test_betcrop_fslbetcrop_dwi -c ./tests/config/nextflow.config
tags:
- betcrop/fslbetcrop
- betcrop
files:
- path: output/betcrop/test__b0_bet.nii.gz
md5sum: 884a9b20cfae5f44ede3b3f57a087066
- path: output/betcrop/test__b0_bet_mask.nii.gz
md5sum: 73a197481d8654357add819aac01ac4f
- path: output/betcrop/test__image_bet.nii.gz
md5sum: a7f148ee905b3e2c3d6b3a19a82ab646
- path: output/betcrop/test__image_bet_mask.nii.gz
md5sum: f529265040a1564c9e6711238e3c8339
- path: output/betcrop/test__image_boundingBox.pkl
md5sum: 9e5e03281a8bd90e1b4e4496e71c1b95
- path: output/betcrop/versions.yml

- name: betcrop fslbetcrop test_betcrop_fslbetcrop_t1
command: nextflow run ./tests/modules/nf-scil/betcrop/fslbetcrop -entry test_betcrop_fslbetcrop_t1 -c ./tests/config/nextflow.config
tags:
- betcrop/fslbetcrop
- betcrop
files:
- path: output/betcrop/test__image_bet.nii.gz
md5sum: 9ceef378099fffe2fc1ff29a3d0105a9
- path: output/betcrop/test__image_bet_mask.nii.gz
md5sum: 8744aa4315845bec621a0d2c5bcc2647
- path: output/betcrop/test__image_boundingBox.pkl
md5sum: e863210ecc0902fa11548f3f896658a6
- path: output/betcrop/versions.yml

- name: betcrop fslbetcrop test_betcrop_fslbetcrop_t1_dilate
command: nextflow run ./tests/modules/nf-scil/betcrop/fslbetcrop -entry test_betcrop_fslbetcrop_t1_dilate -c ./tests/config/nextflow.config
tags:
- betcrop/fslbetcrop
- betcrop
files:
- path: output/betcrop/test__dwi_bet_cropped.nii.gz
md5sum: e597e3030800fbf9de681c1a5e539c9d
- path: output/betcrop/test__dwi_bet_cropped_mask.nii.gz
md5sum: d511acb62d15958b5a8f2116cdb3ce3a
- path: output/betcrop/test__dwi_boundingBox.pkl
md5sum: 89012d5b4f0f1bee03658b193911e0a1
- path: output/betcrop/test__image_bet.nii.gz
md5sum: 9ceef378099fffe2fc1ff29a3d0105a9
- path: output/betcrop/test__image_bet_mask.nii.gz
md5sum: c21d1270d4713e6fe7cf09bfdf97fe6a
- path: output/betcrop/test__image_boundingBox.pkl
md5sum: e863210ecc0902fa11548f3f896658a6
- path: output/betcrop/versions.yml

0 comments on commit 887e6ee

Please sign in to comment.