Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] add t1 option in fslbetcrop module #57

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
id: filter
with:
filters: "tests/config/pytest_modules.yml"
token: ""
token: "${{ secrets.GITHUB_TOKEN }}"

nf-core-lint:
runs-on: scilus-nf-scil-runners
Expand Down
57 changes: 40 additions & 17 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_cropped.nii.gz") , emit: image
tuple val(meta), path("*_bet_cropped_mask.nii.gz") , emit: mask
tuple val(meta), path("*_boundingBox.pkl") , emit: bbox
path "versions.yml" , emit: versions

when:
task.ext.when == null || task.ext.when
Expand All @@ -23,31 +23,53 @@ 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 : ""

"""
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 [[ -v $bval && -v $bvec ]]
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}__b0_bet_mask.nii.gz --data_type uint8 -f
mrcalc $image ${prefix}__b0_bet_mask.nii.gz -mult ${prefix}__dwi_bet.nii.gz -quiet -nthreads 1

if ( "$task.ext.crop" = true );
then
scil_crop_volume.py $image ${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
fi

else
bet $image ${prefix}__t1_bet.nii.gz -m -R $bet_f
scil_image_math.py convert ${prefix}__t1_bet_mask.nii.gz ${prefix}__t1_bet_mask.nii.gz --data_type uint8 -f

if ( "$task.ext.crop" = true );
then
scil_crop_volume.py $image ${prefix}__t1_bet_cropped.nii.gz -f \
--output_bbox ${prefix}__t1_boundingBox.pkl -f
scil_crop_volume.py ${prefix}__t1_bet_mask.nii.gz ${prefix}__t1_bet_cropped_mask.nii.gz -f\
--input_bbox ${prefix}__dwi_boundingBox.pkl -f
scil_image_math.py convert ${prefix}__t1_bet_cropped_mask.nii.gz ${prefix}__t1_bet_cropped_mask.nii.gz \
--data_type uint8 -f
fi
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 @@ -64,6 +86,7 @@ process BETCROP_FSLBETCROP {

touch ${prefix}__dwi_bet_cropped.nii.gz
touch ${prefix}__dwi_bet_cropped_mask.nii.gz
touch ${prefix}__dwi_boundingBox.pkl

cat <<-END_VERSIONS > versions.yml
"${task.process}":
Expand Down
17 changes: 9 additions & 8 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,19 +47,19 @@ 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_cropped.{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_cropped_mask.{nii,nii.gz}"

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

- versions:
Expand Down
21 changes: 19 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,19 @@ 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 )
}
8 changes: 7 additions & 1 deletion tests/modules/nf-scil/betcrop/fslbetcrop/nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ process {
publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" }

withName: "BETCROP_FSLBETCROP" {
ext.bet_dwi_f = 0.16
ext.bet_f = 0.16
ext.b0_thr = 10
ext.crop = false
}

withName: "workflow test_betcrop_fslbetcrop_t1:BETCROP_FSLBETCROP" {
ext.bet_f = 0.5
ext.crop = true
}
}
Loading