1
1
import attr
2
2
import typing as ty
3
3
from pydra import ShellCommandTask
4
- from pydra .engine .specs import Path , File , SpecInfo , ShellOutSpec
4
+ from pydra .engine .specs import SpecInfo , ShellOutSpec
5
5
from .base import MRTrix3BaseSpec
6
6
7
7
11
11
(
12
12
"in_file" ,
13
13
attr .ib (
14
- type = Path ,
14
+ type = str ,
15
15
metadata = {
16
16
"argstr" : "{in_file}" ,
17
17
"position" : 1 ,
25
25
attr .ib (
26
26
type = str ,
27
27
metadata = {
28
- "argstr" : "{out_file}" ,
29
28
"position" : - 1 ,
29
+ "argstr" : "" ,
30
30
"help_string" : "output image" ,
31
+ "output_file_template" : "{in_file}_converted" ,
31
32
},
32
33
),
33
34
),
36
37
attr .ib (
37
38
type = ty .List [float ],
38
39
metadata = {
40
+ "sep" : " " ,
39
41
"argstr" : "-coord" ,
40
42
"help_string" : "extract data at the specific coordinatest" ,
41
43
},
46
48
attr .ib (
47
49
type = ty .List [float ],
48
50
metadata = {
51
+ "sep" : "," ,
49
52
"argstr" : "-vox" ,
50
53
"help_string" : "change the voxel dimensions" ,
51
54
},
56
59
attr .ib (
57
60
type = ty .List [int ],
58
61
metadata = {
62
+ "sep" : "," ,
59
63
"argstr" : "-axes" ,
60
64
"help_string" : "specify the axes that will be used" ,
61
65
},
66
70
attr .ib (
67
71
type = ty .List [float ],
68
72
metadata = {
73
+ "sep" : "," ,
69
74
"argstr" : "-scaling" ,
70
75
"help_string" : "specify the data scaling parameter" ,
71
76
},
76
81
attr .ib (
77
82
type = str ,
78
83
metadata = {
79
- "argstr" : "-export_grad_mrtrix" ,
80
- "help_string" : "export new gradient files in mrtrix3 format" ,
84
+ "argstr" : "-export_grad_mrtrix {export_grad}" ,
85
+ "help_string" : "export gradient encodings in mrtrix3 file format" ,
86
+ "output_file_template" : "{export_grad}" ,
81
87
},
82
88
),
83
89
),
86
92
attr .ib (
87
93
type = str ,
88
94
metadata = {
89
- "argstr" : "-json_export" ,
95
+ "argstr" : "-json_export {export_json} " ,
90
96
"help_string" : "export image headet to JSON file" ,
97
+ "output_file_template" : "{export_json}" ,
91
98
},
92
99
),
93
100
),
101
+ # (
102
+ # "export_grad_fsl",
103
+ # attr.ib(
104
+ # type=ty.Tuple[str, str],
105
+ # metadata={
106
+ # "argstr": "-export_grad_fsl",
107
+ # "help_string": "export gradient encodings in FSL file format",
108
+ # "sep": " ",
109
+ # "output_file_template": "{in_file}_bvec {in_file}_bval",
110
+ # },
111
+ # )
112
+ # )
94
113
],
95
114
bases = (MRTrix3BaseSpec ,),
96
115
)
97
116
98
117
MRConvertOutputSpec = SpecInfo (
99
118
name = "MRConvertOutputs" ,
100
- fields = [
101
- (
102
- "out_file" ,
103
- attr .ib (
104
- type = File ,
105
- metadata = {
106
- "help_string" : "output image" ,
107
- "output_file_template" : "dwi.mif" ,
108
- },
109
- ),
110
- ),
111
- (
112
- "out_bfile" ,
113
- attr .ib (
114
- type = File ,
115
- metadata = {
116
- "help_string" : "output .b gradient file in mrtrix3 format" ,
117
- "output_file_template" : "dwi.b" ,
118
- },
119
- ),
120
- ),
121
- (
122
- "out_json" ,
123
- attr .ib (
124
- type = File ,
125
- metadata = {
126
- "help_string" : "output JSON file of image header" ,
127
- "output_file_template" : "dwi.json" ,
128
- },
129
- ),
130
- ),
131
- ],
119
+ fields = [],
132
120
bases = (ShellOutSpec ,),
133
121
)
134
122
@@ -137,15 +125,45 @@ class MRConvert(ShellCommandTask):
137
125
"""
138
126
Example
139
127
------
128
+
129
+ Convert NIfTI file with FSL-style gradient encoding files to
130
+ MRtrix Image Format with MRtrix-style gradient encoding files
131
+
140
132
>>> task = MRConvert()
141
133
>>> task.inputs.in_file = "test_dwi.nii.gz"
142
134
>>> task.inputs.grad_fsl = ["test.bvec", "test.bval"]
143
135
>>> task.inputs.export_grad = "test.b"
144
136
>>> task.inputs.out_file = "test.mif"
145
137
>>> task.cmdline
146
138
'mrconvert test_dwi.nii.gz -fslgrad test.bvec test.bval -export_grad_mrtrix test.b test.mif'
139
+
140
+ Select the first volume from a diffusion-weighted dataset
141
+
142
+ >>> task = MRConvert()
143
+ >>> task.inputs.in_file = "test_dwi.nii.gz"
144
+ >>> task.inputs.out_file = "vol.nii.gz"
145
+ >>> task.inputs.coord = [3, 0]
146
+ >>> task.cmdline
147
+ 'mrconvert test_dwi.nii.gz -coord 3 0 vol.nii.gz'
148
+
149
+ Extend a 3D image to 4D by adding a singular dimension
150
+
151
+ >>> task = MRConvert()
152
+ >>> task.inputs.in_file = "test_b0.nii.gz"
153
+ >>> task.inputs.out_file = "4d.nii.gz"
154
+ >>> task.inputs.axes = [0, 1, 2, -1]
155
+ >>> task.cmdline
156
+ 'mrconvert test_b0.nii.gz -axes 0,1,2,-1 4d.nii.gz'
157
+
147
158
"""
148
159
149
160
input_spec = MRConvertInputSpec
150
161
output_spec = MRConvertOutputSpec
151
162
executable = "mrconvert"
163
+
164
+ # >>> task = MRConvert()
165
+ # >>> task.inputs.in_file = "test_dwi.mif"
166
+ # >>> task.inputs.export_grad_fsl = ("test.bvec", "test.bval")
167
+ # >>> task.inputs.out_file = "test.mif"
168
+ # >>> task.cmdline
169
+ # 'mrconvert test_dwi.mif -export_grad_fsl test.bvec test.bval test.mif'
0 commit comments