Skip to content
Open
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
8 changes: 5 additions & 3 deletions modules/nf-neuro/image/applymask/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ process IMAGE_APPLYMASK {

script:
def prefix = task.ext.prefix ?: "${meta.id}"
def suffix = task.ext.first_suffix ? task.ext.first_suffix + "_masked" : "masked"
def nthreads_mrtrix = task.ext.single_thread ? "-nthreads 0" : "-nthreads ${task.cpus}"
def data_type = task.ext.data_type ? "-datatype ${task.ext.data_type}" : " -datatype float32"

"""
export OMP_NUM_THREADS=${task.ext.single_thread ? 1 : task.cpus}

mrcalc $image $mask -mult ${prefix}_masked.nii.gz -force -quiet ${nthreads_mrtrix}
mrcalc $image $mask -mult ${prefix}_${suffix}.nii.gz -force -quiet ${nthreads_mrtrix} ${data_type}

cat <<-END_VERSIONS > versions.yml
"${task.process}":
Expand All @@ -31,9 +33,9 @@ process IMAGE_APPLYMASK {

stub:
def prefix = task.ext.prefix ?: "${meta.id}"

def suffix = task.ext.first_suffix ? task.ext.first_suffix + "_masked" : "masked"
"""
touch ${prefix}_masked.nii.gz
touch ${prefix}_${suffix}.nii.gz

mrcalc -h

Expand Down
10 changes: 10 additions & 0 deletions modules/nf-neuro/image/applymask/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,20 @@ input:
ontologies:
- edam: http://edamontology.org/format_3989 # GZIP format
args:
- first_suffix:
type: string
description: Suffix for the output image file. This will be used as the first part of the suffix, followed by "_masked".
default: ""
- single_thread:
type: boolean
description: If true, the command will be run in single-threaded mode. By default, the command will use multiple threads based on the number of CPUs allocated to the task.
default: false
- data_type:
type: string
description: |
Data type for the output image. Use the following format:
uint8, int16, int32, int64, float16, float32 or float64.
default: "float32"
output:
image:
- - meta:
Expand Down
7 changes: 5 additions & 2 deletions modules/nf-neuro/registration/anattodwi/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ process REGISTRATION_ANATTODWI {
container "scilus/scilus:2.2.2"

input:
tuple val(meta), path(fixed_reference), path(moving_anat), path(metric)
tuple val(meta), path(fixed_reference), path(moving_anat), path(metric), path(fixed_mask), path(moving_mask)

output:
tuple val(meta), path("*_warped.nii.gz") , emit: anat_warped
Expand All @@ -26,7 +26,9 @@ process REGISTRATION_ANATTODWI {
script:
def prefix = task.ext.prefix ?: "${meta.id}"
def run_qc = task.ext.run_qc as Boolean || false
def args = task.ext.args ?: ''

if ( task.ext.masking_strategy == "both" || task.ext.masking_strategy == "internal" ) args += " -x $fixed_mask?:NULL,$moving_mask?:NULL"
"""
export ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=${task.ext.single_thread ? 1 : task.cpus}
export OMP_NUM_THREADS=${task.ext.single_thread ? 1 : task.cpus}
Expand All @@ -49,7 +51,8 @@ process REGISTRATION_ANATTODWI {
--metric MI[$fixed_reference,$moving_anat,1,32]\
--metric CC[$metric,$moving_anat,1,4]\
--convergence [50x25x10,1e-6,10] --shrink-factors 4x2x1\
--smoothing-sigmas 3x2x1
--smoothing-sigmas 3x2x1\
$args

moving_base=\$(basename "${moving_anat}")
ext=\${moving_base#*.}
Expand Down
18 changes: 18 additions & 0 deletions modules/nf-neuro/registration/anattodwi/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ args:
type: integer
description: Random seed for ANTs registration. Setting a fixed seed can help with reproducibility of results.
default: 1234
- masking_strategy:
type: string
description: Masking strategy to use for registration. Options are 'none', 'apriori', 'both'.
default: "none"
input:
- - meta:
type: map
Expand Down Expand Up @@ -70,6 +74,20 @@ input:
mandatory: true
ontologies:
- edam: http://edamontology.org/format_4001 # NIFTI format
- fixed_mask:
type: file
description: Fixed image mask
pattern: "*.{nii,nii.gz}"
mandatory: false
ontologies:
- edam: http://edamontology.org/format_4001 # NIFTI format
- moving_mask:
type: file
description: Moving image mask
pattern: "*.{nii,nii.gz}"
mandatory: false
ontologies:
- edam: http://edamontology.org/format_4001 # NIFTI format
output:
anat_warped:
- - meta:
Expand Down
54 changes: 54 additions & 0 deletions modules/nf-neuro/registration/anattodwi/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,59 @@ nextflow_process {
input[0] = ch_b0
.join(ch_t1w)
.join(ch_fa)
.map{ meta, fixed, moving, fixed_metric -> [meta, fixed, moving, fixed_metric, [], []] }
"""
}
}

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

test("registration - anattodwi - fixed mask") {
config "./nextflow.config"
when {
process {
"""
ch_split_test_data = LOAD_DATA.out.test_data_directory
.branch{
t1w: it.simpleName == "T1w"
b0: it.simpleName == "b0"
dti: it.simpleName == "dti"
}
ch_t1w = ch_split_test_data.t1w.map{
test_data_directory -> [
[ id:'test', single_end:false ],
file("\${test_data_directory}/T1w.nii.gz")
]
}
ch_b0 = ch_split_test_data.b0.map{
test_data_directory -> [
[ id:'test', single_end:false ],
file("\${test_data_directory}/b0.nii.gz")
]
}
ch_fa = ch_split_test_data.dti.map{
test_data_directory -> [
[ id:'test', single_end:false ],
file("\${test_data_directory}/fa.nii.gz")
]
}
ch_fixed_mask = ch_split_test_data.t1w.map{
test_data_directory -> [
[ id:'test', single_end:false ],
file("\${test_data_directory}/T1w_mask.nii.gz")
]
}
input[0] = ch_b0
.join(ch_t1w)
.join(ch_fa)
.join(ch_fixed_mask)
.map{ meta, fixed, moving, fixed_metric, fixed_mask -> [meta, fixed, moving, fixed_metric, fixed_mask, []] }
"""
}
}
Expand Down Expand Up @@ -101,6 +154,7 @@ nextflow_process {
input[0] = ch_b0
.join(ch_t1w)
.join(ch_fa)
.map{ meta, fixed, moving, fixed_metric -> [meta, fixed, moving, fixed_metric, [], []] }
"""
}
}
Expand Down
Loading
Loading