Skip to content

Commit 5a32ce5

Browse files
authored
Merge pull request #14 from tclose/separator-fix
Fixes for MRConvert
2 parents 2479c2b + a4bd19a commit 5a32ce5

File tree

5 files changed

+67
-45
lines changed

5 files changed

+67
-45
lines changed

pydra/tasks/mrtrix3/tests/data/test_b0.gz

Whitespace-only changes.

pydra/tasks/mrtrix3/tests/data/test_dwi.mif

Whitespace-only changes.

pydra/tasks/mrtrix3/utils.py

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import attr
22
import typing as ty
33
from pydra import ShellCommandTask
4-
from pydra.engine.specs import Path, File, SpecInfo, ShellOutSpec
4+
from pydra.engine.specs import SpecInfo, ShellOutSpec
55
from .base import MRTrix3BaseSpec
66

77

@@ -11,7 +11,7 @@
1111
(
1212
"in_file",
1313
attr.ib(
14-
type=Path,
14+
type=str,
1515
metadata={
1616
"argstr": "{in_file}",
1717
"position": 1,
@@ -25,9 +25,10 @@
2525
attr.ib(
2626
type=str,
2727
metadata={
28-
"argstr": "{out_file}",
2928
"position": -1,
29+
"argstr": "",
3030
"help_string": "output image",
31+
"output_file_template": "{in_file}_converted",
3132
},
3233
),
3334
),
@@ -36,6 +37,7 @@
3637
attr.ib(
3738
type=ty.List[float],
3839
metadata={
40+
"sep": " ",
3941
"argstr": "-coord",
4042
"help_string": "extract data at the specific coordinatest",
4143
},
@@ -46,6 +48,7 @@
4648
attr.ib(
4749
type=ty.List[float],
4850
metadata={
51+
"sep": ",",
4952
"argstr": "-vox",
5053
"help_string": "change the voxel dimensions",
5154
},
@@ -56,6 +59,7 @@
5659
attr.ib(
5760
type=ty.List[int],
5861
metadata={
62+
"sep": ",",
5963
"argstr": "-axes",
6064
"help_string": "specify the axes that will be used",
6165
},
@@ -66,6 +70,7 @@
6670
attr.ib(
6771
type=ty.List[float],
6872
metadata={
73+
"sep": ",",
6974
"argstr": "-scaling",
7075
"help_string": "specify the data scaling parameter",
7176
},
@@ -76,8 +81,9 @@
7681
attr.ib(
7782
type=str,
7883
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}",
8187
},
8288
),
8389
),
@@ -86,49 +92,31 @@
8692
attr.ib(
8793
type=str,
8894
metadata={
89-
"argstr": "-json_export",
95+
"argstr": "-json_export {export_json}",
9096
"help_string": "export image headet to JSON file",
97+
"output_file_template": "{export_json}",
9198
},
9299
),
93100
),
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+
# )
94113
],
95114
bases=(MRTrix3BaseSpec,),
96115
)
97116

98117
MRConvertOutputSpec = SpecInfo(
99118
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=[],
132120
bases=(ShellOutSpec,),
133121
)
134122

@@ -137,15 +125,45 @@ class MRConvert(ShellCommandTask):
137125
"""
138126
Example
139127
------
128+
129+
Convert NIfTI file with FSL-style gradient encoding files to
130+
MRtrix Image Format with MRtrix-style gradient encoding files
131+
140132
>>> task = MRConvert()
141133
>>> task.inputs.in_file = "test_dwi.nii.gz"
142134
>>> task.inputs.grad_fsl = ["test.bvec", "test.bval"]
143135
>>> task.inputs.export_grad = "test.b"
144136
>>> task.inputs.out_file = "test.mif"
145137
>>> task.cmdline
146138
'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+
147158
"""
148159

149160
input_spec = MRConvertInputSpec
150161
output_spec = MRConvertOutputSpec
151162
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'

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build-system]
2+
requires = ["setuptools==62", "wheel"]

setup.cfg

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[DEFAULT]
2-
subpackage = mrtrix3
3-
41
[metadata]
52
author = Nipype developers
63
author_email = [email protected]
@@ -28,8 +25,8 @@ packages = find_namespace:
2825

2926
[options.packages.find]
3027
include =
31-
pydra.tasks.%(subpackage)s
32-
pydra.tasks.%(subpackage)s.*
28+
pydra.tasks.mrtrix3
29+
pydra.tasks.mrtrix3.*
3330

3431
[options.extras_require]
3532
doc =
@@ -61,7 +58,12 @@ all =
6158
[versioneer]
6259
VCS = git
6360
style = pep440
64-
versionfile_source = pydra/tasks/%(subpackage)s/_version.py
65-
versionfile_build = pydra/tasks/%(subpackage)s/_version.py
61+
versionfile_source = pydra/tasks/mrtrix3/_version.py
62+
versionfile_build = pydra/tasks/mrtrix3/_version.py
6663
tag_prefix =
6764
parentdir_prefix =
65+
66+
67+
[tool:pytest]
68+
addopts = --doctest-modules --doctest-report ndiff
69+
doctest_optionflags= NORMALIZE_WHITESPACE ELLIPSIS

0 commit comments

Comments
 (0)