Skip to content

Commit

Permalink
Merge pull request #122 from anroy1/synthbet
Browse files Browse the repository at this point in the history
[Module] Freesurfer BET
  • Loading branch information
AlexVCaron committed Jun 13, 2024
2 parents f402276 + 38183a4 commit 5a8a54e
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 0 deletions.
8 changes: 8 additions & 0 deletions modules/nf-scil/betcrop/synthbet/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: betcrop_synthbet

channels:
- Docker
- Apptainer

dependencies:
- "Freesurfer:synthstrip"
54 changes: 54 additions & 0 deletions modules/nf-scil/betcrop/synthbet/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
process BETCROP_SYNTHBET {
tag "$meta.id"
label 'process_single'

container "freesurfer/synthstrip:latest"
containerOptions "--entrypoint ''"

input:
tuple val(meta), path(image), path(weights) /* optional, input = [] */

output:
tuple val(meta), path("*__bet_image.nii.gz"), emit: bet_image
tuple val(meta), path("*__brain_mask.nii.gz"), emit: brain_mask
path "versions.yml" , emit: versions

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

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

def gpu = task.ext.gpu ? "--gpu" : ""
def border = task.ext.border ? "-b " + task.ext.border : ""
def nocsf = task.ext.nocsf ? "--no-csf" : ""
def model = "$weights" ? "--model $weights" : ""

"""
export ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=$task.cpus
export OMP_NUM_THREADS=1
export OPENBLAS_NUM_THREADS=1
mri_synthstrip -i $image --out ${prefix}__bet_image.nii.gz --mask ${prefix}__brain_mask.nii.gz $gpu $border $nocsf $model
cat <<-END_VERSIONS > versions.yml
"${task.process}":
freesurfer: 7.4
END_VERSIONS
"""

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

"""
mri_synthstrip -h
touch ${prefix}__bet_image.nii.gz
touch ${prefix}__brain_mask.nii.gz
cat <<-END_VERSIONS > versions.yml
"${task.process}":
freesurfer: 7.4
END_VERSIONS
"""
}
53 changes: 53 additions & 0 deletions modules/nf-scil/betcrop/synthbet/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
name: "betcrop_synthbet"
description: Perform brain extraction using synthstrip on image
keywords:
- anatomical image
- BET
- freesurfer
tools:
- "Freesurfer":
description: "Software package for the analysis and visualization of structural and functional neuroimaging data."
homepage: "https://surfer.nmr.mgh.harvard.edu/fswiki"

input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'test', single_end:false ]`
- image:
type: file
description: Nifti image volume to perform BET.
pattern: "*.{nii,nii.gz}"

- weights:
type: file
description: Alternative model weights
pattern: "*.pt"

output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'test', single_end:false ]`
- bet_image:
type: file
description: Nifti brain-extracted volume.
pattern: "*__bet_image.{nii,nii.gz}"

- brain_mask:
type: file
description: Brain-extracted image mask .
pattern: "*__brain_mask.{nii,nii.gz}"

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

authors:
- "@anroy1"
51 changes: 51 additions & 0 deletions modules/nf-scil/betcrop/synthbet/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
nextflow_process {

name "Test Process BETCROP_SYNTHBET"
script "../main.nf"
process "BETCROP_SYNTHBET"
config "./nextflow.config"

tag "modules"
tag "modules_nfcore"
tag "betcrop"
tag "betcrop/synthbet"

tag "subworkflows"
tag "subworkflows/load_test_data"

test("betcrop - synthbet") {

setup {
run("LOAD_TEST_DATA", alias: "LOAD_DATA") {
script "../../../../../subworkflows/nf-scil/load_test_data/main.nf"
process {
"""
input[0] = Channel.from( [ "freesurfer.zip" ] )
input[1] = "test.load-test-data"
"""
}
}
}

when {
process {
"""
input[0] = LOAD_DATA.out.test_data_directory.map{
test_data_directory -> [
[ id:'test', single_end:false ], // meta map
file("\${test_data_directory}/anat_image.nii.gz"),
[]
]
}
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}
}
}
55 changes: 55 additions & 0 deletions modules/nf-scil/betcrop/synthbet/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"betcrop - synthbet": {
"content": [
{
"0": [
[
{
"id": "test",
"single_end": false
},
"test__bet_image.nii.gz:md5,6f5eb365a11dfc52b8c80cd7bcee7b9d"
]
],
"1": [
[
{
"id": "test",
"single_end": false
},
"test__brain_mask.nii.gz:md5,52871114b59d09dca864cb0ea4f12832"
]
],
"2": [
"versions.yml:md5,f0a96d8fd7ca9d9935818dceaf91f457"
],
"bet_image": [
[
{
"id": "test",
"single_end": false
},
"test__bet_image.nii.gz:md5,6f5eb365a11dfc52b8c80cd7bcee7b9d"
]
],
"brain_mask": [
[
{
"id": "test",
"single_end": false
},
"test__brain_mask.nii.gz:md5,52871114b59d09dca864cb0ea4f12832"
]
],
"versions": [
"versions.yml:md5,f0a96d8fd7ca9d9935818dceaf91f457"
]
}
],
"meta": {
"nf-test": "0.8.4",
"nextflow": "23.10.1"
},
"timestamp": "2024-06-11T14:52:54.970673"
}
}
7 changes: 7 additions & 0 deletions modules/nf-scil/betcrop/synthbet/tests/nextflow.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
process {
withName: "BETCROP_SYNTHBET" {
publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" }
memory = 8.GB
ext.nocsf = true
}
}
2 changes: 2 additions & 0 deletions modules/nf-scil/betcrop/synthbet/tests/tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
betcrop/synthbet:
- "modules/nf-scil/betcrop/synthbet/**"

0 comments on commit 5a8a54e

Please sign in to comment.