Skip to content

Commit

Permalink
[WIP] Initial module commit
Browse files Browse the repository at this point in the history
  • Loading branch information
anroy1 committed Aug 9, 2024
1 parent 719ea69 commit ac5b6a5
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 8 deletions.
26 changes: 18 additions & 8 deletions subworkflows/nf-scil/preproc_t1/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ include { DENOISING_NLMEANS } from '../../../modules/nf-scil/denoising/nlmeans/m
include { PREPROC_N4 } from '../../../modules/nf-scil/preproc/n4/main'
include { IMAGE_RESAMPLE } from '../../../modules/nf-scil/image/resample/main'
include { BETCROP_ANTSBET } from '../../../modules/nf-scil/betcrop/antsbet/main'
include { BETCROP_SYNTHBET} from '../../../modules/nf-scil/betcrop/synthbet/main'
include { BETCROP_CROPVOLUME as BETCROP_CROPVOLUME_T1 } from '../../../modules/nf-scil/betcrop/cropvolume/main'
include { BETCROP_CROPVOLUME as BETCROP_CROPVOLUME_MASK } from '../../../modules/nf-scil/betcrop/cropvolume/main'

workflow PREPROC_T1 {

take:
ch_image // channel: [ val(meta), [ image ] ]
ch_template // channel: [ val(meta), [ template ] ]
ch_probability_map // channel: [ val(meta), [ probability_map ] ]
ch_template // channel: [ val(meta), [ template ] ] , optional
ch_probability_map // channel: [ val(meta), [ probability_map ] ] , optional
ch_mask_nlmeans // channel: [ val(meta), [ mask ] ] , optional
ch_ref_n4 // channel: [ val(meta), [ ref, ref_mask ] ] , optional
ch_ref_resample // channel: [ val(meta), [ ref ] ] , optional
val_synth(false) // value: (default: false)

main:

Expand All @@ -36,9 +38,17 @@ workflow PREPROC_T1 {
ch_versions = ch_versions.mix(IMAGE_RESAMPLE.out.versions.first())

// ** Brain extraction ** //
ch_bet = IMAGE_RESAMPLE.out.image.join(ch_template).join(ch_probability_map)
BETCROP_ANTSBET ( ch_bet )
ch_versions = ch_versions.mix(BETCROP_ANTSBET.out.versions.first())
if ( val_synth ) {
ch_bet = IMAGE_RESAMPLE.out.image.join(ch_fs_license)
BETCROP_SYNTHBET ( ch_bet )
ch_versions = ch_versions.mix(BETCROP_SYNTHBET.out.versions.first())
}

else {
ch_bet = IMAGE_RESAMPLE.out.image.join(ch_template).join(ch_probability_map)
BETCROP_ANTSBET ( ch_bet )
ch_versions = ch_versions.mix(BETCROP_ANTSBET.out.versions.first())
}

// ** crop image ** //
ch_crop = BETCROP_ANTSBET.out.t1.map{it + [[]]}
Expand All @@ -54,10 +64,10 @@ workflow PREPROC_T1 {
image_nlmeans = DENOISING_NLMEANS.out.image // channel: [ val(meta), [ image ] ]
image_N4 = PREPROC_N4.out.image // channel: [ val(meta), [ image ] ]
image_resample = IMAGE_RESAMPLE.out.image // channel: [ val(meta), [ image ] ]
image_bet = BETCROP_ANTSBET.out.t1 // channel: [ val(meta), [ t1 ] ]
mask_bet = BETCROP_ANTSBET.out.mask // channel: [ val(meta), [ mask ] ]
image_bet = ch_bet_out.t1 // channel: [ val(meta), [ t1 ] ]
mask_bet = ch_bet_out.out.mask // channel: [ val(meta), [ mask ] ]
crop_box = BETCROP_CROPVOLUME_T1.out.bounding_box // channel: [ val(meta), [ bounding_box ] ]
mask_final = BETCROP_CROPVOLUME_MASK.out.image // channel: [ val(meta), [ mask ] ]
t1_final = BETCROP_CROPVOLUME_T1.out.image // channel: [ val(meta), [ image ] ]
t1_final = BETCROP_CROPVOLUME_T1.out.image // channel: [ val(meta), [ image ] ]
versions = ch_versions // channel: [ versions.yml ]
}
56 changes: 56 additions & 0 deletions subworkflows/nf-scil/preproc_t1/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ nextflow_workflow {
tag "preproc/n4"
tag "image/resample"
tag "betcrop/antsbet"
tag "betcrop/synthbet"
tag "betcrop/cropvolume"

tag "load_test_data"
Expand Down Expand Up @@ -127,6 +128,61 @@ nextflow_workflow {
}
}

then {
assertAll(
{ assert workflow.success},
{ assert snapshot(workflow.out).match()}
)
}
}

test("preproc_t1_synth") {
config "./nextflow_synth.config"

when {
workflow {
"""
ch_split_test_data = LOAD_DATA.out.test_data_directory
.branch{
antsbet: it.simpleName == "antsbet"
others: it.simpleName == "others"
}
input[0] = ch_split_test_data.antsbet.map{
test_data_directory -> [
[ id:'test', single_end:false ],
file("\${test_data_directory}/t1_unaligned.nii.gz")
]}
input[1] = ch_split_test_data.antsbet.map{
test_data_directory -> [
[ id:'test', single_end:false ],
[]
]}
input[2] = ch_split_test_data.antsbet.map{
test_data_directory -> [
[ id:'test', single_end:false ],
[]
]}
input[3] = ch_split_test_data.antsbet.map{
test_data_directory -> [
[ id:'test', single_end:false ],
[]
]}
input[4] = ch_split_test_data.others.map{
test_data_directory -> [
[ id:'test', single_end:false ],
[],
[]
]}
input[5] = ch_split_test_data.antsbet.map{
test_data_directory -> [
[ id:'test', single_end:false ],
[]
]}
input[6] = true
"""
}
}

then {
assertAll(
{ assert workflow.success},
Expand Down
10 changes: 10 additions & 0 deletions subworkflows/nf-scil/preproc_t1/tests/nextflow_synth.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
process {
publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" }
withName: "IMAGE_RESAMPLE" {
ext.interp = "lin"
}
withName: "BETCROP_CROPVOLUME_T1" {
ext.output_bbox = true
ext.first_suffix = "t1"
}
}

0 comments on commit ac5b6a5

Please sign in to comment.