-
Notifications
You must be signed in to change notification settings - Fork 0
/
dwi2anat_RegTra.py
136 lines (122 loc) · 3.32 KB
/
dwi2anat_RegTra.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from pydra import Workflow, ShellCommandTask
from pydra.engine.specs import File, SpecInfo, ShellSpec, ShellOutSpec
from pathlib import Path
# Define paths
output_path = Path("/Users/arkievdsouza/git/dwi-pipeline/working-dir/")
# Define input and output specifications
input_spec = {
"meanB0_brain": File,
"anat_brain": File,
}
output_spec = {
"warped_image": File,
"inversewarped_image": File,
}
# Create the workflow
wf = Workflow(
name="RegTra_ANTs_wf",
input_spec=input_spec,
cache_dir=output_path,
output_spec=output_spec,
)
# ANTs Registration specifications
ANTsReg_input_spec = SpecInfo(
name="Input",
fields=[
(
"anat_image",
File,
{
"help_string": "Path to input anatomical image",
"argstr": "-f {anat_image}",
"mandatory": True,
},
),
(
"meanb0_image",
File,
{
"help_string": "Path to input meanb0 image",
"argstr": "-m {meanb0_image}",
"mandatory": True,
},
),
(
"image_dimensions",
int,
{
"help_string": "Image dimensions (2 or 3)",
"argstr": "-d {image_dimensions}",
"mandatory": True,
},
),
(
"threads",
int,
{
"help_string": "Number of threads",
"argstr": "-o {threads}",
"mandatory": True,
},
),
(
"OutputPrefix",
str,
{
"help_string": "Output prefix",
"argstr": "-o {OutputPrefix}",
"output_file_template": "ANTs_output_",
},
),
],
bases=(ShellSpec,),
)
def warped_path(str):
return str("ANTs_output_Warped.nii.gz")
def invwarped_path(str):
return str("ANTs_output_InverseWarped.nii.gz")
ANTsReg_output_spec = SpecInfo(
name="Output",
fields=[
(
"warped_image",
File,
{
"help_string": "Warped image",
"output_file_template": "ANTs_output_Warped.nii.gz",
},
),
(
"inverse_warped_image",
File,
{
"help_string": "Inverse warped image",
"output_file_template": "ANTs_output_InverseWarped.nii.gz",
},
),
],
bases=(ShellOutSpec,),
)
# Add the ANTs registration task
wf.add(
ShellCommandTask(
name="ANTsReg_task",
executable="antsRegistrationSyN.sh",
input_spec=ANTsReg_input_spec,
output_spec=ANTsReg_output_spec,
anat_image=wf.lzin.anat_brain,
meanb0_image=wf.lzin.meanB0_brain,
threads=24,
image_dimensions=3,
OutputPrefix="ANTs_output_", # Ensure this prefix matches with your output file templates
)
)
# Set the output
wf.set_output(("warped_image", wf.ANTsReg_task.lzout.warped_image))
wf.set_output(("inversewarped_image", wf.ANTsReg_task.lzout.inverse_warped_image))
# Execute the workflow
result = wf(
meanB0_brain="/Users/arkievdsouza/Desktop/data/temp_B0img.nii.gz",
anat_brain="/Users/arkievdsouza/Desktop/data/T1brain.nii.gz",
plugin="serial",
)