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

[Module] Antsbet #69

Merged
merged 14 commits into from
Mar 18, 2024
Merged
3 changes: 3 additions & 0 deletions .test_data/heavy/mni_152/t1_brain_probability_map.nii.gz
Git LFS file not shown
3 changes: 3 additions & 0 deletions .test_data/heavy/mni_152/t1_template.nii.gz
Git LFS file not shown
63 changes: 63 additions & 0 deletions modules/nf-scil/betcrop/antsbet/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

process BETCROP_ANTSBET {
tag "$meta.id"
label 'process_single'

container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'https://scil.usherbrooke.ca/containers/scilus_1.6.0.sif':
'scilus/scilus:1.6.0' }"

input:

ThoumyreStanislas marked this conversation as resolved.
Show resolved Hide resolved
tuple val(meta), path(t1), path(template), path(map)
ThoumyreStanislas marked this conversation as resolved.
Show resolved Hide resolved

output:
tuple val(meta), path("*t1_bet.nii.gz") , emit: t1
tuple val(meta), path("*t1_bet_mask.nii.gz"), emit: mask
path "versions.yml" , emit: versions

when:
task.ext.when == null || task.ext.when

script:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"

"""
export ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=$task.cpus
export OMP_NUM_THREADS=1
export OPENBLAS_NUM_THREADS=1
export ANTS_RANDOM_SEED=1234

antsBrainExtraction.sh -d 3 -a $t1 -e $template -o bet/ -m $map -u 0
scil_image_math.py convert bet/BrainExtractionMask.nii.gz ${prefix}__t1_bet_mask.nii.gz --data_type uint8
mrcalc $t1 ${prefix}__t1_bet_mask.nii.gz -mult ${prefix}__t1_bet.nii.gz -nthreads 1

cat <<-END_VERSIONS > versions.yml
"${task.process}":
scilpy: 1.6.0
mrtrix: \$(mrcalc -version 2>&1 | sed -n 's/== mrcalc \\([0-9.]\\+\\).*/\\1/p')
ants: 2.4.3
END_VERSIONS
"""

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

"""
antsBrainExtraction.sh -h
scil_image_math.py -h
mrcalc -h

touch ${prefix}__t1_bet.nii.gz
touch ${prefix}__t1_bet_mask.nii.gz

cat <<-END_VERSIONS > versions.yml
"${task.process}":
scilpy: 1.6.0
mrtrix: \$(mrcalc -version 2>&1 | sed -n 's/== mrcalc \\([0-9.]\\+\\).*/\\1/p')
ants: 2.4.3
END_VERSIONS
"""
}
65 changes: 65 additions & 0 deletions modules/nf-scil/betcrop/antsbet/meta.yml
ThoumyreStanislas marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/yaml-schema.json
name: "betcrop_antsbet"
description: Perform Brain extraction using antsBrainExtraction.sh on t1 image.
keywords:
- t1
- BET
- ants
tools:
- "Scilpy":
description: "The Sherbrooke Connectivity Imaging Lab (SCIL) Python dMRI processing toolbox."
homepage: "https://github.com/scilus/scilpy.git"
- "MRtrix3":
description: "Toolbox for image processing, analysis and visualisation of dMRI."
homepage: "https://mrtrix.readthedocs.io/en/latest/"
- "ants":
description: "Advanced Normalization Tools."
homepage: "https://github.com/ANTsX/ANTs"

input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'test', single_end:false ]`

- t1:
type: file
description: Nifti t1 volume to perform BET.
pattern: "*.{nii,nii.gz}"

- template:
type: file
description: Nifti Anatomical template to perform BET.
pattern: "*.{nii,nii.gz}"

- map:
type: file
description: Brain probability mask, with intensity range 1 (definitely brain) to 0 (definitely background).
pattern: "*.{nii,nii.gz}"

output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'test', single_end:false ]`

- t1:
type: file
description: Nifti t1 volume brain-extracted.
pattern: "*t1_bet.{nii,nii.gz}"

- mask:
type: file
description: t1 mask brain-extracted and cropped.
pattern: "*t1_bet_mask.{nii,nii.gz}"

- versions:
type: file
description: File containing software versions
pattern: "versions.yml"

authors:
- "@ThoumyreStanislas"
4 changes: 4 additions & 0 deletions tests/config/pytest_modules.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
betcrop/antsbet:
- modules/nf-scil/betcrop/antsbet/**
- tests/modules/nf-scil/betcrop/antsbet/**

betcrop/cropvolume:
- modules/nf-scil/betcrop/cropvolume/**
- tests/modules/nf-scil/betcrop/cropvolume/**
Expand Down
5 changes: 5 additions & 0 deletions tests/config/test_data.config
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ params {
bval = "${params.test_data_base}/heavy/dwi/dwi.bval"
bvec = "${params.test_data_base}/heavy/dwi/dwi.bvec"
}
"antsbet" {
t1 = "${params.test_data_base}/heavy/anat/anat_image.nii.gz"
template = "${params.test_data_base}/heavy/mni_152/t1_template.nii.gz"
map = "${params.test_data_base}/heavy/mni_152/t1_brain_probability_map.nii.gz"
}
}
"denoising" {
"nlmeans" {
Expand Down
17 changes: 17 additions & 0 deletions tests/modules/nf-scil/betcrop/antsbet/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env nextflow

nextflow.enable.dsl = 2

include { BETCROP_ANTSBET } from '../../../../../modules/nf-scil/betcrop/antsbet/main.nf'

workflow test_betcrop_antsbet {

input = [
[ id:'test', single_end:false ], // meta map
file(params.test_data['betcrop']['antsbet']['t1'], checkIfExists: true),
file(params.test_data['betcrop']['antsbet']['template'], checkIfExists: true),
file(params.test_data['betcrop']['antsbet']['map'], checkIfExists: true)
]

BETCROP_ANTSBET ( input )
}
5 changes: 5 additions & 0 deletions tests/modules/nf-scil/betcrop/antsbet/nextflow.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process {

publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" }

}
11 changes: 11 additions & 0 deletions tests/modules/nf-scil/betcrop/antsbet/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- name: betcrop antsbet test_betcrop_antsbet
command: nextflow run ./tests/modules/nf-scil/betcrop/antsbet -entry test_betcrop_antsbet -c ./tests/config/nextflow.config
tags:
- betcrop/antsbet
- betcrop
files:
- path: output/betcrop/test__t1_bet.nii.gz
md5sum: 159d59b9ca8f69c025daacaf3bb1113d
- path: output/betcrop/test__t1_bet_mask.nii.gz
md5sum: 2ef09348ed5b3abfd64676516cdb6909
- path: output/betcrop/versions.yml
Loading