Skip to content

Commit

Permalink
[FIX] infant profile issues + better assertions for failed test + tes…
Browse files Browse the repository at this point in the history
…t cases
  • Loading branch information
gagnonanthony committed Nov 18, 2024
1 parent cf7626c commit 67531b6
Show file tree
Hide file tree
Showing 14 changed files with 372 additions and 55 deletions.
34 changes: 34 additions & 0 deletions conf/modules.config
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand Down Expand Up @@ -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
}
Expand All @@ -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' {
Expand Down
109 changes: 73 additions & 36 deletions modules/local/connectivity/metrics.nf
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
}
}
49 changes: 49 additions & 0 deletions modules/local/image/convert.nf
Original file line number Diff line number Diff line change
@@ -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
"""
}
2 changes: 1 addition & 1 deletion modules/nf-neuro/betcrop/synthbet/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions subworkflows/local/utils_nfcore_pediatric_pipeline/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
}
}

Expand Down Expand Up @@ -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}")
}
Expand Down Expand Up @@ -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}")
}
}

Expand Down
12 changes: 11 additions & 1 deletion subworkflows/nf-neuro/preproc_dwi/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions tests/data/samplesheet_testall_infant.csv
Original file line number Diff line number Diff line change
@@ -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,,,,,,,
2 changes: 2 additions & 0 deletions tests/data/samplesheet_testconn_infant.csv
Original file line number Diff line number Diff line change
@@ -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/,
2 changes: 2 additions & 0 deletions tests/data/samplesheet_testconn_notrk.csv
Original file line number Diff line number Diff line change
@@ -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/,
2 changes: 2 additions & 0 deletions tests/data/samplesheet_testtracking_withmetrics.csv
Original file line number Diff line number Diff line change
@@ -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,
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 67531b6

Please sign in to comment.