-
Notifications
You must be signed in to change notification settings - Fork 17
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] Freesurfer registration #54
base: main
Are you sure you want to change the base?
Changes from all commits
73ca1de
f9b9b3b
819a821
943c25d
944b2d2
a4ab7bc
8527df2
ec3abcf
8563d0f
d865f3e
d3bbf09
f1cbf98
e0d3143
de0a5c5
5abd3ac
385b0fe
e4a816f
985d5a9
f642c8e
e840787
0154dcc
3969605
6b075e8
7ad4e6a
a4f0778
a7c45de
6570e2e
b802440
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
name: "registration_synthregistration" | ||
channels: | ||
- Docker | ||
- Apptainer | ||
dependencies: | ||
- "Freesurfer:synthmorph" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
process REGISTRATION_SYNTHREGISTRATION { | ||
tag "$meta.id" | ||
label 'process_single' | ||
|
||
container "freesurfer/synthmorph:latest" | ||
containerOptions "--entrypoint ''" | ||
|
||
input: | ||
tuple val(meta), path(moving), path(fixed) | ||
|
||
output: | ||
tuple val(meta), path("*__output_warped.nii.gz"), emit: warped_image | ||
tuple val(meta), path("*__deform_warp.nii.gz"), emit: deform_transform | ||
tuple val (meta), path("*__init_warp.lta"), emit: init_transform | ||
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}" | ||
|
||
def init = task.ext.init ? "-m " + task.ext.init : "-m affine" | ||
def warp = task.ext.warp ? "-m " + task.ext.warp : "-m deform" | ||
def header = task.ext.header ? "-H" : "" | ||
def threads = task.ext.threads ? "-j " + task.ext.threads : "" | ||
def gpu = task.ext.gpu ? "-g" : "" | ||
def lambda = task.ext.lambda ? "-r " + task.ext.lambda : "" | ||
def steps = task.ext.steps ? "-n " + task.ext.steps : "" | ||
def extent = task.ext.extent ? "-e " + task.ext.extent : "" | ||
def weight = task.ext.weight ? "-w " + task.ext.weight : "" | ||
|
||
""" | ||
export ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=1 | ||
export OMP_NUM_THREADS=1 | ||
export OPENBLAS_NUM_THREADS=1 | ||
|
||
mri_synthmorph ${init} -t ${prefix}__init_warp.lta $moving $fixed | ||
mri_synthmorph ${warp} ${gpu} ${lambda} ${steps} ${extent} ${weight} -i ${prefix}__init_warp.lta -t ${prefix}__deform_warp.nii.gz -o ${prefix}__output_warped.nii.gz $moving $fixed | ||
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering, is the command able to support multiple transforms ? Just thinking that the module should be able to take a sequence of transforms (not just affine+warp),. Not worth it if the whole script needs a redo though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I fully understand. There is a "rigid" model also, but initialization with it seems to break the registration, which is consstent with the doc: "Deformable assumes prior affine alignment or initialization with -i". The flag "-m joint" would work so it doesn't require successive affine + deform run: "Joint includes affine and deformable but differs from running both in sequence in that it applies the deformable step in an affine mid-space to guarantee symmetric joint transforms." But building it this way allows for producing a affine only transform also. The warp output of the second synthmorph run generates a combined warp field (of affine + deform). But if there were let's say a second initialzation (rigid + affine + deform), synthmorph always combine successive registration with any initialization. |
||
|
||
cat <<-END_VERSIONS > versions.yml | ||
"${task.process}": | ||
Freesurfer: 7.4 | ||
END_VERSIONS | ||
""" | ||
|
||
stub: | ||
def args = task.ext.args ?: '' | ||
def prefix = task.ext.prefix ?: "${meta.id}" | ||
|
||
""" | ||
mri_synthmorph -h | ||
|
||
touch ${prefix}__output_warped.nii.gz | ||
touch ${prefix}__deform_warp.nii.gz | ||
touch ${prefix}__init_warp.lta | ||
|
||
cat <<-END_VERSIONS > versions.yml | ||
"${task.process}": | ||
Freesurfer: 7.4 | ||
END_VERSIONS | ||
""" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
name: "registration_synthregistration" | ||
description: Perform registration using SynthMorph from Freesurfer. Outputs transforms in Freesurfer format .lta for affine and .nii.gz (synthmorph also supports .mgz) for deform, both in RAS orientation, which can be converted for ANTs with respectively lta_convert and mri_warp_convert, which support a wide range of conversion formats and orientations. Conversion can be processed using the registration/convert module which can be used successively to this one. | ||
keywords: | ||
- registration | ||
- Brain imaging | ||
- MRI | ||
tools: | ||
- "Freesurfer": | ||
description: "Freesurfer Synthmorph" | ||
homepage: "https://martinos.org/malte/synthmorph/" | ||
|
||
input: | ||
- meta: | ||
type: map | ||
description: | | ||
Groovy Map containing sample information | ||
e.g. `[ id:'test', single_end:false ]` | ||
|
||
- moving: | ||
type: file | ||
description: Nifti volume moving for registration | ||
pattern: "*.{nii,nii.gz}" | ||
|
||
- fixed: | ||
type: file | ||
description: Nifti volume fixed for registration | ||
pattern: "*.{nii,nii.gz}" | ||
|
||
output: | ||
- meta: | ||
type: map | ||
description: | | ||
Groovy Map containing sample information | ||
e.g. `[ id:'test', single_end:false ]` | ||
|
||
- init_transform: | ||
anroy1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type: file | ||
description: Affine transform for initialization | ||
pattern: "*.{lta}" | ||
|
||
- deform_transform: | ||
type: file | ||
description: Deform transformation | ||
pattern: "*.{nii.gz}" | ||
|
||
- warped_image: | ||
type: file | ||
description: Warped image | ||
pattern: "*.{nii,.nii.gz}" | ||
|
||
- versions: | ||
type: file | ||
description: File containing software versions | ||
pattern: "versions.yml" | ||
|
||
authors: | ||
- "@anroy1" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
nextflow_process { | ||
|
||
name "Test Process REGISTRATION_SYNTHREGISTRATION" | ||
script "../main.nf" | ||
process "REGISTRATION_SYNTHREGISTRATION" | ||
|
||
tag "modules" | ||
tag "modules_nfcore" | ||
tag "registration" | ||
tag "registration/synthregistration" | ||
|
||
tag "subworkflows" | ||
tag "subworkflows/load_test_data" | ||
|
||
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" | ||
""" | ||
} | ||
} | ||
} | ||
|
||
test("registration - synthregistration") { | ||
config "./nextflow.config" | ||
when { | ||
process { | ||
""" | ||
input[0] = LOAD_DATA.out.test_data_directory | ||
.map{ test_data_directory -> [ | ||
[ id:'test', single_end:false ], | ||
file("\${test_data_directory}/t1.nii.gz"), | ||
file("\${test_data_directory}/fa.nii.gz") | ||
]} | ||
""" | ||
} | ||
} | ||
then { | ||
assertAll( | ||
{ assert process.success }, | ||
{ assert snapshot( | ||
file(process.out.warped_image.get(0).get(1)).name, | ||
file(process.out.deform_transform.get(0).get(1)).name, | ||
file(process.out.init_transform.get(0).get(1)).name, | ||
process.out.versions | ||
).match() } | ||
) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"registration - synthregistration": { | ||
"content": [ | ||
"test__output_warped.nii.gz", | ||
"test__deform_warp.nii.gz", | ||
"test__init_warp.lta", | ||
[ | ||
"versions.yml:md5,49fb9c85da9f696926d1ab46ef0968fb" | ||
] | ||
], | ||
"meta": { | ||
"nf-test": "0.8.4", | ||
"nextflow": "23.10.1" | ||
}, | ||
"timestamp": "2024-06-06T13:03:51.883573" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
process { | ||
withName: "REGISTRATION_SYNTHREGISTRATION" { | ||
publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" } | ||
memory = 20 | ||
ext.init = "affine" | ||
ext.warp = "deform" | ||
ext.threads = 1 | ||
ext.lambda = 0.9 | ||
ext.steps = 9 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
registration/synthregistration: | ||
- "modules/nf-scil/registration/synthregistration/**" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be handled directly in the script with $task.cpus
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this, for both calls? :
mri_synthmorph -j $task.cpus [...]