diff --git a/conf/modules.config b/conf/modules.config index 72fd37f..813fee9 100644 --- a/conf/modules.config +++ b/conf/modules.config @@ -88,6 +88,20 @@ process { withName: 'NF_PEDIATRIC:PEDIATRIC:PREPROC_DWI:CROPDWI' { ext.output_bbox = true + ext.first_suffix = 'dwi' + } + + withName: 'NF_PEDIATRIC:PEDIATRIC:PREPROC_DWI:CROPB0' { + ext.first_suffix = 'b0' + } + + withName: 'NF_PEDIATRIC:PEDIATRIC:PREPROC_DWI:CROPMASK' { + ext.first_suffix = 'mask' + } + + withName: 'NF_PEDIATRIC:PEDIATRIC:PREPROC_DWI:CONVERT' { + ext.first_suffix = 'mask' + ext.datatype = 'uint8' } withName: 'NF_PEDIATRIC:PEDIATRIC:PREPROC_DWI:BETCROP_FSLBETCROP' { @@ -182,6 +196,25 @@ process { ext.ventricles_mask = true } + withName: 'NF_PEDIATRIC:PEDIATRIC:RESAMPLE_T2' { + ext.voxel_size = params.t1_resample_voxel_size + ext.interp = params.t1_resample_interp + } + + withName: 'NF_PEDIATRIC:PEDIATRIC:RESAMPLE_WMMASK' { + ext.voxel_size = params.t1_resample_voxel_size + ext.interp = "nn" + } + + withName: 'NF_PEDIATRIC:PEDIATRIC:CROPT2' { + ext.output_bbox = true + ext.first_suffix = 't2' + } + + withName: 'NF_PEDIATRIC:PEDIATRIC:CROPWMMASK' { + ext.first_suffix = 'wm_mask' + } + withName: 'NF_PEDIATRIC:PEDIATRIC:MASK_COMBINE' { ext.local_fa_seeding_mask_thr = params.local_fa_seeding_mask_threshold } @@ -190,6 +223,7 @@ process { ext.dimensionality = params.reg_dimensionality ext.interpolation = params.reg_interpolation ext.output_dtype = params.reg_output_dtype + ext.first_suffix = "wm_mask" } withName: 'NF_PEDIATRIC:PEDIATRIC:TRACKING_PFTTRACKING' { diff --git a/modules/local/connectivity/metrics.nf b/modules/local/connectivity/metrics.nf index d753990..ac00908 100644 --- a/modules/local/connectivity/metrics.nf +++ b/modules/local/connectivity/metrics.nf @@ -19,46 +19,83 @@ process CONNECTIVITY_METRICS { script: def prefix = task.ext.prefix ?: "${meta.id}" - String metrics_list = metrics.join(", ").replace(',', '') - - """ - metrics_args="" - - for metric in $metrics_list; do - base_name=\$(basename \${metric}) - metrics_args="\${metrics_args} --metrics \${metric} \$(basename \$base_name .nii.gz).npy" - done - - scil_connectivity_compute_matrices.py $h5 $labels \ - --processes $task.cpus \ - --volume "${prefix}__vol.npy" \ - --streamline_count "${prefix}__sc.npy" \ - --length "${prefix}__len.npy" \ - \$metrics_args \ - --density_weighting \ - --no_self_connection \ - --include_dps ./ \ - --force_labels_list $labels_list - - cat <<-END_VERSIONS > versions.yml - "${task.process}": - scilpy: \$(pip list | grep scilpy | tr -s ' ' | cut -d' ' -f2) - END_VERSIONS - """ + if ( metrics ) { + metrics_list = metrics.join(", ").replace(',', '') + + """ + metrics_args="" + + for metric in $metrics_list; do + base_name=\$(basename \${metric}) + metrics_args="\${metrics_args} --metrics \${metric} \$(basename \$base_name .nii.gz).npy" + done + + scil_connectivity_compute_matrices.py $h5 $labels \ + --processes $task.cpus \ + --volume "${prefix}__vol.npy" \ + --streamline_count "${prefix}__sc.npy" \ + --length "${prefix}__len.npy" \ + \$metrics_args \ + --density_weighting \ + --no_self_connection \ + --include_dps ./ \ + --force_labels_list $labels_list + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + scilpy: \$(pip list | grep scilpy | tr -s ' ' | cut -d' ' -f2) + END_VERSIONS + """ + } else { + """ + scil_connectivity_compute_matrices.py $h5 $labels \ + --processes $task.cpus \ + --volume "${prefix}__vol.npy" \ + --streamline_count "${prefix}__sc.npy" \ + --length "${prefix}__len.npy" \ + --density_weighting \ + --no_self_connection \ + --include_dps ./ \ + --force_labels_list $labels_list + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + scilpy: \$(pip list | grep scilpy | tr -s ' ' | cut -d' ' -f2) + END_VERSIONS + """ + } stub: def prefix = task.ext.prefix ?: "${meta.id}" - """ - touch ${prefix}__vol.npy - touch ${prefix}__sc.npy - touch ${prefix}__len.npy + if ( metrics ) { + metrics_list = metrics.join(", ").replace(',', '') + + """ + for metric in $metrics_list; do + base_name=\$(basename "\${metric}" .nii.gz) + touch "\${base_name}.npy" + done + + scil_connectivity_compute_matrices.py -h + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + scilpy: \$(pip list | grep scilpy | tr -s ' ' | cut -d' ' -f2) + END_VERSIONS + """ + } else { + """ + touch ${prefix}__vol.npy + touch ${prefix}__sc.npy + touch ${prefix}__len.npy - scil_connectivity_compute_matrices.py -h + scil_connectivity_compute_matrices.py -h - cat <<-END_VERSIONS > versions.yml - "${task.process}": - scilpy: \$(pip list | grep scilpy | tr -s ' ' | cut -d' ' -f2) - END_VERSIONS - """ + cat <<-END_VERSIONS > versions.yml + "${task.process}": + scilpy: \$(pip list | grep scilpy | tr -s ' ' | cut -d' ' -f2) + END_VERSIONS + """ + } } diff --git a/modules/local/image/convert.nf b/modules/local/image/convert.nf new file mode 100644 index 0000000..a68aabc --- /dev/null +++ b/modules/local/image/convert.nf @@ -0,0 +1,49 @@ +process IMAGE_CONVERT { + tag "$meta.id" + label 'process_single' + + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'https://scil.usherbrooke.ca/containers/scilus_2.0.2.sif': + 'scilus/scilus:2.0.2' }" + + input: + tuple val(meta), path(image) + + output: + tuple val(meta), path("*_converted.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 datatype = task.ext.datatype ? "--data_type ${task.ext.datatype}" : "--data_type uint8" + def suffix = task.ext.first_suffix ? "${task.ext.first_suffix}_${task.ext.datatype}_converted" : "${task.ext.datatype}_converted" + + """ + scil_volume_math.py convert $image ${prefix}_${suffix}.nii.gz $datatype + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + scilpy: \$(pip list | grep scilpy | tr -s ' ' | cut -d' ' -f2) + END_VERSIONS + """ + + stub: + def prefix = task.ext.prefix ?: "${meta.id}" + + def suffix = task.ext.first_suffix ? "${task.ext.first_suffix}_${task.ext.datatype}" : "${task.ext.datatype}" + + """ + touch ${prefix}_${suffix}.nii.gz + + scil_volume_math.py -h + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + scilpy: \$(pip list | grep scilpy | tr -s ' ' | cut -d' ' -f2) + END_VERSIONS + """ +} diff --git a/modules/nf-neuro/betcrop/synthbet/main.nf b/modules/nf-neuro/betcrop/synthbet/main.nf index 446bbc8..32dfb30 100644 --- a/modules/nf-neuro/betcrop/synthbet/main.nf +++ b/modules/nf-neuro/betcrop/synthbet/main.nf @@ -2,7 +2,7 @@ process BETCROP_SYNTHBET { tag "$meta.id" label 'process_single' - container "freesurfer/synthstrip:latest" + container "freesurfer/freesurfer:7.4.1" containerOptions "--entrypoint ''" input: diff --git a/subworkflows/local/utils_nfcore_pediatric_pipeline/main.nf b/subworkflows/local/utils_nfcore_pediatric_pipeline/main.nf index 3e0af61..bf955a9 100644 --- a/subworkflows/local/utils_nfcore_pediatric_pipeline/main.nf +++ b/subworkflows/local/utils_nfcore_pediatric_pipeline/main.nf @@ -133,7 +133,7 @@ workflow PIPELINE_INITIALISATION { error("Please provide a warp image for sample: ${meta.id}") } if (!metrics) { - error("You did not provide metric file for sample: ${meta.id}") + log.warn("You did not provide metric file for sample: ${meta.id}") } } @@ -214,12 +214,12 @@ workflow PIPELINE_INITIALISATION { error("Please provide a warp image for sample: ${meta.id}") } if (!metrics) { - error("You did not provide metric file for sample: ${meta.id}") + log.warn("You did not provide metric file for sample: ${meta.id}") } } // ** Validate files for profile children with tracking and connectomics. ** // - if ( params.tracking && params.connectomics && !params.infant ) { + if ( params.tracking && params.connectomics && !params.infant && !params.freesurfer ) { if (!t1) { error("Please provide a T1w image for sample: ${meta.id}") } @@ -270,7 +270,7 @@ workflow PIPELINE_INITIALISATION { error("Please provide a warp image for sample: ${meta.id}") } if (!metrics) { - error("You did not provide metric file for sample: ${meta.id}") + log.warn("You did not provide metric file for sample: ${meta.id}") } } diff --git a/subworkflows/nf-neuro/preproc_dwi/main.nf b/subworkflows/nf-neuro/preproc_dwi/main.nf index ed48ff7..6be8cb1 100644 --- a/subworkflows/nf-neuro/preproc_dwi/main.nf +++ b/subworkflows/nf-neuro/preproc_dwi/main.nf @@ -4,6 +4,8 @@ include { IMAGE_POWDERAVERAGE } from '../../../modules/nf-neuro/image/powderaver include { IMAGE_APPLYMASK as BET_DWI } from '../../../modules/nf-neuro/image/applymask/main' include { BETCROP_SYNTHBET } from '../../../modules/nf-neuro/betcrop/synthbet/main' include { BETCROP_CROPVOLUME as CROPDWI } from '../../../modules/nf-neuro/betcrop/cropvolume/main' +include { BETCROP_CROPVOLUME as CROPMASK } from '../../../modules/nf-neuro/betcrop/cropvolume/main' +include { IMAGE_CONVERT as CONVERT } from '../../../modules/local/image/convert' include { BETCROP_FSLBETCROP } from '../../../modules/nf-neuro/betcrop/fslbetcrop/main' include { BETCROP_CROPVOLUME as CROPB0 } from '../../../modules/nf-neuro/betcrop/cropvolume/main' include { PREPROC_N4 as N4_DWI } from '../../../modules/nf-neuro/preproc/n4/main' @@ -106,8 +108,16 @@ workflow PREPROC_DWI { .map{ it + [[]] }) ch_versions = ch_versions.mix(CROPDWI.out.versions.first()) + ch_cropmask = BETCROP_SYNTHBET.out.brain_mask + .join(CROPDWI.out.bounding_box) + CROPMASK ( ch_cropmask ) + ch_versions = ch_versions.mix(CROPMASK.out.versions.first()) + + CONVERT ( CROPMASK.out.image ) + ch_versions = ch_versions.mix(CONVERT.out.versions.first()) + ch_dwi = CROPDWI.out.image - ch_mask = BETCROP_SYNTHBET.out.brain_mask + ch_mask = CONVERT.out.image ch_bbox = CROPDWI.out.bounding_box } else { diff --git a/tests/data/samplesheet_testall_infant.csv b/tests/data/samplesheet_testall_infant.csv new file mode 100644 index 0000000..370d589 --- /dev/null +++ b/tests/data/samplesheet_testall_infant.csv @@ -0,0 +1,2 @@ +subject,t1,t2,dwi,bval,bvec,rev_b0,labels,wmparc,trk,peaks,fodf,mat,warp,metrics +sub-test,,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-test/t2.nii.gz,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-test/dwi.nii.gz,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-test/dwi.bval,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-test/dwi.bvec,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-test/rev_b0.nii.gz,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-test/labels.nii.gz,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-test/wm_mask.nii.gz,,,,,,, diff --git a/tests/data/samplesheet_testconn_infant.csv b/tests/data/samplesheet_testconn_infant.csv new file mode 100644 index 0000000..a52a422 --- /dev/null +++ b/tests/data/samplesheet_testconn_infant.csv @@ -0,0 +1,2 @@ +subject,t1,t2,dwi,bval,bvec,rev_b0,labels,wmparc,trk,peaks,fodf,mat,warp,metrics +sub-test,,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/t2.nii.gz,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/dwi.nii.gz,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/dwi.bval,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/dwi.bvec,,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/labels.nii.gz,,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/tracking.trk,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/peaks.nii.gz,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/fodf.nii.gz,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/0GenericAffine.mat,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/output1Warp.nii.gz,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/metrics/, diff --git a/tests/data/samplesheet_testconn_notrk.csv b/tests/data/samplesheet_testconn_notrk.csv new file mode 100644 index 0000000..e16b955 --- /dev/null +++ b/tests/data/samplesheet_testconn_notrk.csv @@ -0,0 +1,2 @@ +subject,t1,t2,dwi,bval,bvec,rev_b0,labels,wmparc,trk,peaks,fodf,mat,warp,metrics +sub-test,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/t1.nii.gz,,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/dwi.nii.gz,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/dwi.bval,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/dwi.bvec,,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/labels.nii.gz,,,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/peaks.nii.gz,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/fodf.nii.gz,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/0GenericAffine.mat,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/output1Warp.nii.gz,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-testconn/metrics/, diff --git a/tests/data/samplesheet_testtracking_withmetrics.csv b/tests/data/samplesheet_testtracking_withmetrics.csv new file mode 100644 index 0000000..ec87e6a --- /dev/null +++ b/tests/data/samplesheet_testtracking_withmetrics.csv @@ -0,0 +1,2 @@ +subject,t1,t2,dwi,bval,bvec,rev_b0,labels,wmparc,trk,peaks,fodf,mat,warp,metrics +sub-test,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-test/t1.nii.gz,,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-test/dwi.nii.gz,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-test/dwi.bval,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-test/dwi.bvec,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-test/rev_b0.nii.gz,,,,,,,,/Users/anthonygagnon/code/nf-pediatric/tests/data/sub-test/metrics, diff --git a/tests/data/sub-test/metrics/fa.nii.gz b/tests/data/sub-test/metrics/met1.nii.gz similarity index 100% rename from tests/data/sub-test/metrics/fa.nii.gz rename to tests/data/sub-test/metrics/met1.nii.gz diff --git a/tests/data/sub-test/metrics/rd.nii.gz b/tests/data/sub-test/metrics/met2.nii.gz similarity index 100% rename from tests/data/sub-test/metrics/rd.nii.gz rename to tests/data/sub-test/metrics/met2.nii.gz diff --git a/tests/main.nf.test b/tests/main.nf.test index f08f634..fef0409 100644 --- a/tests/main.nf.test +++ b/tests/main.nf.test @@ -39,6 +39,7 @@ nextflow_pipeline { then { assert workflow.failed + assert workflow.stdout.contains("Please provide a reverse phase encoded B0 image for sample: sub-test") } } @@ -58,6 +59,7 @@ nextflow_pipeline { then { assert workflow.failed + assert workflow.stdout.contains("Please provide a DWI image for sample: sub-test") } } @@ -108,6 +110,7 @@ nextflow_pipeline { then { assert workflow.failed + assert workflow.stdout.contains("Please provide a wmparc image for sample: sub-test") } } @@ -128,6 +131,7 @@ nextflow_pipeline { then { assert workflow.failed + assert workflow.stdout.contains("Please provide a reverse phase encoded B0 image for sample: sub-test") } } @@ -148,6 +152,7 @@ nextflow_pipeline { then { assert workflow.failed + assert workflow.stdout.contains("Please provide at least one anatomical image (T1w or T2w) for sample: sub-test") } } @@ -171,7 +176,7 @@ nextflow_pipeline { } - test("Connectomics profile without metrics - should fail") { + test("Connectomics profile without metrics - should run successfully") { when { params { @@ -185,7 +190,47 @@ nextflow_pipeline { } then { - assert workflow.failed + assert workflow.success + } + + } + + test("Connectomics profile without trk - should fail") { + + when { + params { + + params.input = "$projectDir/tests/data/samplesheet_testconn_notrk.csv" + params.outdir = "test_results/" + + params.connectomics = true + + } + } + + then { + assert workflow.success + assert workflow.stdout.contains("Please provide a trk file for sample: sub-test") + } + + } + + test("Connectomics + infant profile - should run successfully") { + + when { + params { + + params.input = "$projectDir/tests/data/samplesheet_testconn_infant.csv" + params.outdir = "test_results/" + + params.connectomics = true + params.infant = true + + } + } + + then { + assert workflow.success } } @@ -199,7 +244,103 @@ nextflow_pipeline { params.outdir = "test_results/" params.freesurfer = true - params.fs_license = "/Applications/freesurfer/7.4.1/license.txt" + params.fs_license = "https://www.dropbox.com/scl/fi/0s8lp6lydyd0rxawxb4jm/license.txt?rlkey=hz54oc0d4sor69avqphtrjvgn&st=9e0yij97&dl=0" + + } + } + + then { + assert workflow.success + } + + } + + test("Freesurfer + connectomics profiles - should run successfully") { + + when { + params { + + params.input = "$projectDir/tests/data/samplesheet_testconn.csv" + params.outdir = "test_results/" + + params.freesurfer = true + params.connectomics = true + params.fs_license = "https://www.dropbox.com/scl/fi/0s8lp6lydyd0rxawxb4jm/license.txt?rlkey=hz54oc0d4sor69avqphtrjvgn&st=9e0yij97&dl=0" + + } + } + + then { + assert workflow.success + } + + } + + test("Freesurfer + connectomics + tracking profiles - should run successfully") { + + when { + params { + + params.input = "$projectDir/tests/data/samplesheet_testtracking.csv" + params.outdir = "test_results/" + + params.freesurfer = true + params.connectomics = true + params.tracking = true + params.fs_license = "https://www.dropbox.com/scl/fi/0s8lp6lydyd0rxawxb4jm/license.txt?rlkey=hz54oc0d4sor69avqphtrjvgn&st=9e0yij97&dl=0" + + } + } + + then { + assert workflow.success + } + + } + + test("Freesurfer + connectomics + tracking profiles with additional metrics - should run successfully") { + + when { + params { + + params.input = "$projectDir/tests/data/samplesheet_testtracking_withmetrics.csv" + params.outdir = "test_results/" + + params.freesurfer = true + params.connectomics = true + params.tracking = true + params.fs_license = "https://www.dropbox.com/scl/fi/0s8lp6lydyd0rxawxb4jm/license.txt?rlkey=hz54oc0d4sor69avqphtrjvgn&st=9e0yij97&dl=0" + + } + } + + then { + assert workflow.success + } + + } + + test("Connectomics + tracking + infant profiles - should run successfully") { + + when { + params { + + params.input = "$projectDir/tests/data/samplesheet_testall_infant.csv" + params.outdir = "test_results/" + + params.connectomics = true + params.tracking = true + params.infant = true + + // ** Infant specific parameters ** // + params.dwi_run_synthstrip = true + params.dwi_normalize_fa_mask_threshold = 0.10 + params.fodf_max_fa_threshold = 0.01 + params.fodf_min_md_threshold = 0.00185 + params.frf_manual_frf = "12,5,5" + params.run_pft_tracking = false + params.local_min_len = 15 + params.local_fa_seeding_mask_threshold = 0.10 } } diff --git a/workflows/pediatric.nf b/workflows/pediatric.nf index 55f22f4..f05337a 100644 --- a/workflows/pediatric.nf +++ b/workflows/pediatric.nf @@ -15,6 +15,10 @@ include { FREESURFERFLOW } from '../subworkflows/local/freesu // ** T1 Preprocessing ** // include { PREPROC_T1 } from '../subworkflows/nf-neuro/preproc_t1/main' +include { IMAGE_RESAMPLE as RESAMPLE_T2 } from '../modules/nf-neuro/image/resample/main' +include { IMAGE_RESAMPLE as RESAMPLE_WMMASK } from '../modules/nf-neuro/image/resample/main' +include { BETCROP_CROPVOLUME as CROPT2 } from '../modules/nf-neuro/betcrop/cropvolume/main' +include { BETCROP_CROPVOLUME as CROPWMMASK } from '../modules/nf-neuro/betcrop/cropvolume/main' // ** DWI Preprocessing ** // include { PREPROC_DWI } from '../subworkflows/nf-neuro/preproc_dwi/main' @@ -223,9 +227,39 @@ workflow PEDIATRIC { // if ( params.infant ) { + // ** Apply resampling to input t2 and wmparc. ** // + ch_resample_t2 = ch_inputs.t2 + .map{ it + [[]] } + + RESAMPLE_T2 ( ch_resample_t2 ) + ch_versions = ch_versions.mix(RESAMPLE_T2.out.versions.first()) + // ch_multiqc_files = ch_multiqc_files.mix(RESAMPLE_T2.out.zip.collect{it[1]}) + + ch_resample_wmmask = ch_inputs.wmparc + .map{ it + [[]] } + + RESAMPLE_WMMASK ( ch_resample_wmmask ) + ch_versions = ch_versions.mix(RESAMPLE_WMMASK.out.versions.first()) + // ch_multiqc_files = ch_multiqc_files.mix(RESAMPLE_WMMASK.out.zip.collect{it[1]}) + + // ** Crop T2 and wm mask. ** // + ch_crop_t2 = RESAMPLE_T2.out.image + .map{ it + [[]] } + + CROPT2 ( ch_crop_t2 ) + ch_versions = ch_versions.mix(CROPT2.out.versions.first()) + // ch_multiqc_files = ch_multiqc_files.mix(CROPT2.out.zip.collect{it[1]}) + + ch_crop_wmmask = RESAMPLE_WMMASK.out.image + .join(CROPT2.out.bounding_box) + + CROPWMMASK ( ch_crop_wmmask ) + ch_versions = ch_versions.mix(CROPWMMASK.out.versions.first()) + // ch_multiqc_files = ch_multiqc_files.mix(CROPWMMASK.out.zip.collect{it[1]}) + REGISTRATION( - ch_inputs.t2, - PREPROC_DWI.out.pwdavg, + CROPT2.out.image, + PREPROC_DWI.out.b0, RECONST_DTIMETRICS.out.md, Channel.empty(), Channel.empty(), @@ -235,8 +269,8 @@ workflow PEDIATRIC { // ch_multiqc_files = ch_multiqc_files.mix(REGISTRATION.out.zip.collect{it[1]}) // ** Apply transforms to WM mask. ** // - ch_reg_wm_mask = ch_inputs.wmparc - .join(PREPROC_DWI.out.pwdavg) + ch_reg_wm_mask = CROPWMMASK.out.image + .join(REGISTRATION.out.image_warped) .join(REGISTRATION.out.transfo_image) REGISTRATION_ANTSAPPLYTRANSFORMS ( ch_reg_wm_mask ) @@ -262,7 +296,7 @@ workflow PEDIATRIC { // if ( params.infant ) { - ch_seg = ch_inputs.wmparc + ch_seg = REGISTRATION_ANTSAPPLYTRANSFORMS.out.warped_image .join(RECONST_DTIMETRICS.out.fa) MASK_COMBINE( ch_seg ) @@ -356,14 +390,15 @@ workflow PEDIATRIC { ch_provided_metrics = ch_inputs.metrics .map { meta, metrics -> - def metrics_files = file("$metrics/*.nii.gz").findAll { it.name.endsWith('.nii.gz') } + def metrics_files = file("$metrics/*.nii.gz").findAll { it.name.endsWith('.nii.gz') && it.name != '*.nii.gz' } return [meta, metrics_files] } .filter { it[1] } - ch_metrics = ch_metrics.concat( - ch_provided_metrics - ) + ch_metrics = ch_metrics + .combine(ch_provided_metrics, by: 0) + .map{ meta, defmet, provmet -> tuple(meta, defmet + provmet) } + } } else { @@ -383,7 +418,7 @@ workflow PEDIATRIC { ch_metrics = ch_inputs.metrics .map { meta, metrics -> - def metrics_files = file("$metrics/*.nii.gz").findAll { it.name.endsWith('.nii.gz') } + def metrics_files = file("$metrics/*.nii.gz").findAll { it.name.endsWith('.nii.gz') && it.name != '*.nii.gz' } return [meta, metrics_files] } .filter { it[1] } @@ -457,11 +492,14 @@ workflow PEDIATRIC { // // MODULE: Run CONNECTIVITY_METRICS // + ch_metrics.view() ch_metrics = CONNECTIVITY_AFDFIXEL.out.hdf5 .join(TRANSFORM_LABELS.out.warped_image) .join(TRACTOGRAM_DECOMPOSE.out.labels_list) .combine(ch_metrics, by: 0) + ch_metrics.view() + CONNECTIVITY_METRICS ( ch_metrics ) ch_versions = ch_versions.mix(CONNECTIVITY_METRICS.out.versions.first()) // ch_multiqc_files = ch_multiqc_files.mix(CONNECTIVITY_METRICS.out.zip.collect{it[1]})