We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Error creating gradient_matrix.txt in DTIRecon (Diffusion Toolkit)
### Summary
When the gradient_matrix.txt file is created from bvecs, the lines are [read](https://github.com/nipy/nipype/blob/db267032616ba05b5fd465491da6134e46041276/nipype/interfaces/diffusion_toolkit/dti.py#L106) in order y, z, x; instead of x, y, z swapping all the directions in the resulting gradient_matrix.txt file 

### Actual behavior
The columns of the actual gradient_matrix.txt are y, z, x, b-value.

### Expected behavior
The columns of the expected gradient_matrix.txt must be x, y ,z, b-value.

### How to replicate the behavior
Just run the example in the documentation of nipype interface for Diffusion Toolkit. My data comes from a Philips Scanner.

### Platform details:
{'scipy_version': '1.0.0', 'sys_executable': '/Users/miguel/anaconda/bin/python', 'sys_platform': 'darwin', 'commit_hash': '%h', 'traits_version': '4.6.0', 'nipype_version': '1.0.0', 'pkg_path': '/Users/miguel/anaconda/lib/python3.5/site-packages/nipype', 'commit_source': 'archive substitution', 'nibabel_version': '2.2.1', 'numpy_version': '1.14.0', 'sys_version': '3.5.4 | packaged by conda-forge | (default, Dec 18 2017, 06:40:48) \n[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]', 'networkx_version': '2.1'}
1.0.0

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `nipype/interfaces/diffusion_toolkit/dti.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
3 # vi: set ft=python sts=4 ts=4 sw=4 et:
4 """Provides interfaces to various commands provided by diffusion toolkit
5 
6    Change directory to provide relative paths for doctests
7    >>> import os
8    >>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
9    >>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data'))
10    >>> os.chdir(datadir)
11 
12 """
13 from __future__ import (print_function, division, unicode_literals,
14                         absolute_import)
15 from builtins import range, open
16 
17 import os
18 import re
19 
20 from ...utils.filemanip import fname_presuffix, split_filename, copyfile
21 from ..base import (TraitedSpec, File, traits, CommandLine,
22                     CommandLineInputSpec, isdefined)
23 
24 __docformat__ = 'restructuredtext'
25 
26 
27 class DTIReconInputSpec(CommandLineInputSpec):
28     DWI = File(
29         desc='Input diffusion volume',
30         argstr='%s',
31         exists=True,
32         mandatory=True,
33         position=1)
34     out_prefix = traits.Str(
35         "dti",
36         desc='Output file prefix',
37         argstr='%s',
38         usedefault=True,
39         position=2)
40     output_type = traits.Enum(
41         'nii',
42         'analyze',
43         'ni1',
44         'nii.gz',
45         argstr='-ot %s',
46         desc='output file type',
47         usedefault=True)
48     bvecs = File(
49         exists=True, desc='b vectors file', argstr='-gm %s', mandatory=True)
50     bvals = File(exists=True, desc='b values file', mandatory=True)
51     n_averages = traits.Int(desc='Number of averages', argstr='-nex %s')
52     image_orientation_vectors = traits.List(
53         traits.Float(),
54         minlen=6,
55         maxlen=6,
56         desc="""specify image orientation vectors. if just one argument given,
57         will treat it as filename and read the orientation vectors from
58         the file. if 6 arguments are given, will treat them as 6 float
59         numbers and construct the 1st and 2nd vector and calculate the 3rd
60         one automatically.
61         this information will be used to determine image orientation,
62         as well as to adjust gradient vectors with oblique angle when""",
63         argstr="-iop %f")
64     oblique_correction = traits.Bool(
65         desc="""when oblique angle(s) applied, some SIEMENS dti protocols do not
66         adjust gradient accordingly, thus it requires adjustment for correct
67         diffusion tensor calculation""",
68         argstr="-oc")
69     b0_threshold = traits.Float(
70         desc=
71         """program will use b0 image with the given threshold to mask out high
72         background of fa/adc maps. by default it will calculate threshold
73         automatically. but if it failed, you need to set it manually.""",
74         argstr="-b0_th")
75 
76 
77 class DTIReconOutputSpec(TraitedSpec):
78     ADC = File(exists=True)
79     B0 = File(exists=True)
80     L1 = File(exists=True)
81     L2 = File(exists=True)
82     L3 = File(exists=True)
83     exp = File(exists=True)
84     FA = File(exists=True)
85     FA_color = File(exists=True)
86     tensor = File(exists=True)
87     V1 = File(exists=True)
88     V2 = File(exists=True)
89     V3 = File(exists=True)
90 
91 
92 class DTIRecon(CommandLine):
93     """Use dti_recon to generate tensors and other maps
94     """
95 
96     input_spec = DTIReconInputSpec
97     output_spec = DTIReconOutputSpec
98 
99     _cmd = 'dti_recon'
100 
101     def _create_gradient_matrix(self, bvecs_file, bvals_file):
102         _gradient_matrix_file = 'gradient_matrix.txt'
103         with open(bvals_file) as fbvals:
104             bvals = [val for val in re.split('\s+', fbvals.readline().strip())]
105         with open(bvecs_file) as fbvecs:
106             bvecs_y = [
107                 val for val in re.split('\s+',
108                                         fbvecs.readline().strip())
109             ]
110             bvecs_z = [
111                 val for val in re.split('\s+',
112                                         fbvecs.readline().strip())
113             ]
114             bvecs_x = [
115                 val for val in re.split('\s+',
116                                         fbvecs.readline().strip())
117             ]
118 
119         with open(_gradient_matrix_file, 'w') as gradient_matrix_f:
120             for i in range(len(bvals)):
121                 gradient_matrix_f.write("%s, %s, %s, %s\n" %
122                                         (bvecs_x[i], bvecs_y[i], bvecs_z[i],
123                                          bvals[i]))
124         return _gradient_matrix_file
125 
126     def _format_arg(self, name, spec, value):
127         if name == "bvecs":
128             new_val = self._create_gradient_matrix(self.inputs.bvecs,
129                                                    self.inputs.bvals)
130             return super(DTIRecon, self)._format_arg("bvecs", spec, new_val)
131         return super(DTIRecon, self)._format_arg(name, spec, value)
132 
133     def _list_outputs(self):
134         out_prefix = self.inputs.out_prefix
135         output_type = self.inputs.output_type
136 
137         outputs = self.output_spec().get()
138         outputs['ADC'] = os.path.abspath(
139             fname_presuffix(
140                 "", prefix=out_prefix, suffix='_adc.' + output_type))
141         outputs['B0'] = os.path.abspath(
142             fname_presuffix(
143                 "", prefix=out_prefix, suffix='_b0.' + output_type))
144         outputs['L1'] = os.path.abspath(
145             fname_presuffix(
146                 "", prefix=out_prefix, suffix='_e1.' + output_type))
147         outputs['L2'] = os.path.abspath(
148             fname_presuffix(
149                 "", prefix=out_prefix, suffix='_e2.' + output_type))
150         outputs['L3'] = os.path.abspath(
151             fname_presuffix(
152                 "", prefix=out_prefix, suffix='_e3.' + output_type))
153         outputs['exp'] = os.path.abspath(
154             fname_presuffix(
155                 "", prefix=out_prefix, suffix='_exp.' + output_type))
156         outputs['FA'] = os.path.abspath(
157             fname_presuffix(
158                 "", prefix=out_prefix, suffix='_fa.' + output_type))
159         outputs['FA_color'] = os.path.abspath(
160             fname_presuffix(
161                 "", prefix=out_prefix, suffix='_fa_color.' + output_type))
162         outputs['tensor'] = os.path.abspath(
163             fname_presuffix(
164                 "", prefix=out_prefix, suffix='_tensor.' + output_type))
165         outputs['V1'] = os.path.abspath(
166             fname_presuffix(
167                 "", prefix=out_prefix, suffix='_v1.' + output_type))
168         outputs['V2'] = os.path.abspath(
169             fname_presuffix(
170                 "", prefix=out_prefix, suffix='_v2.' + output_type))
171         outputs['V3'] = os.path.abspath(
172             fname_presuffix(
173                 "", prefix=out_prefix, suffix='_v3.' + output_type))
174 
175         return outputs
176 
177 
178 class DTITrackerInputSpec(CommandLineInputSpec):
179     tensor_file = File(exists=True, desc="reconstructed tensor file")
180     input_type = traits.Enum(
181         'nii',
182         'analyze',
183         'ni1',
184         'nii.gz',
185         desc="""input and output file type. accepted values are:
186         analyze -> analyze format 7.5
187         ni1     -> nifti format saved in seperate .hdr and .img file
188         nii     -> nifti format with one .nii file
189         nii.gz  -> nifti format with compression
190         default type is 'nii'""",
191         argstr="-it %s")
192     tracking_method = traits.Enum(
193         'fact',
194         'rk2',
195         'tl',
196         'sl',
197         desc="""fact -> use FACT method for tracking. this is the default method.
198         rk2  -> use 2nd order runge-kutta method for tracking.
199         tl   -> use tensorline method for tracking.
200         sl   -> use interpolated streamline method with fixed step-length""",
201         argstr="-%s")
202     step_length = traits.Float(
203         desc="""set step length, in the unit of minimum voxel size.
204         default value is 0.5 for interpolated streamline method
205         and 0.1 for other methods""",
206         argstr="-l %f")
207     angle_threshold = traits.Float(
208         desc="set angle threshold. default value is 35 degree",
209         argstr="-at %f")
210     angle_threshold_weight = traits.Float(
211         desc=
212         "set angle threshold weighting factor. weighting will be be applied \
213         on top of the angle_threshold",
214         argstr="-atw %f")
215     random_seed = traits.Int(
216         desc="use random location in a voxel instead of the center of the voxel \
217           to seed. can also define number of seed per voxel. default is 1",
218         argstr="-rseed %d")
219     invert_x = traits.Bool(
220         desc="invert x component of the vector", argstr="-ix")
221     invert_y = traits.Bool(
222         desc="invert y component of the vector", argstr="-iy")
223     invert_z = traits.Bool(
224         desc="invert z component of the vector", argstr="-iz")
225     swap_xy = traits.Bool(
226         desc="swap x & y vectors while tracking", argstr="-sxy")
227     swap_yz = traits.Bool(
228         desc="swap y & z vectors while tracking", argstr="-syz")
229     swap_zx = traits.Bool(
230         desc="swap x & z vectors while tracking", argstr="-szx")
231     mask1_file = File(
232         desc="first mask image", mandatory=True, argstr="-m %s", position=2)
233     mask1_threshold = traits.Float(
234         desc=
235         "threshold value for the first mask image, if not given, the program will \
236         try automatically find the threshold",
237         position=3)
238     mask2_file = File(desc="second mask image", argstr="-m2 %s", position=4)
239     mask2_threshold = traits.Float(
240         desc=
241         "threshold value for the second mask image, if not given, the program will \
242         try automatically find the threshold",
243         position=5)
244     input_data_prefix = traits.Str(
245         "dti",
246         desc="for internal naming use only",
247         position=0,
248         argstr="%s",
249         usedefault=True)
250     output_file = File(
251         "tracks.trk",
252         "file containing tracks",
253         argstr="%s",
254         position=1,
255         usedefault=True)
256     output_mask = File(
257         desc="output a binary mask file in analyze format", argstr="-om %s")
258     primary_vector = traits.Enum(
259         'v2',
260         'v3',
261         desc=
262         "which vector to use for fibre tracking: v2 or v3. If not set use v1",
263         argstr="-%s")
264 
265 
266 class DTITrackerOutputSpec(TraitedSpec):
267     track_file = File(exists=True)
268     mask_file = File(exists=True)
269 
270 
271 class DTITracker(CommandLine):
272     input_spec = DTITrackerInputSpec
273     output_spec = DTITrackerOutputSpec
274 
275     _cmd = 'dti_tracker'
276 
277     def _run_interface(self, runtime):
278         _, _, ext = split_filename(self.inputs.tensor_file)
279         copyfile(
280             self.inputs.tensor_file,
281             os.path.abspath(self.inputs.input_data_prefix + "_tensor" + ext),
282             copy=False)
283 
284         return super(DTITracker, self)._run_interface(runtime)
285 
286     def _list_outputs(self):
287         outputs = self.output_spec().get()
288         outputs['track_file'] = os.path.abspath(self.inputs.output_file)
289         if isdefined(self.inputs.output_mask) and self.inputs.output_mask:
290             outputs['mask_file'] = os.path.abspath(self.inputs.output_mask)
291 
292         return outputs
293
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/nipype/interfaces/diffusion_toolkit/dti.py b/nipype/interfaces/diffusion_toolkit/dti.py
--- a/nipype/interfaces/diffusion_toolkit/dti.py
+++ b/nipype/interfaces/diffusion_toolkit/dti.py
@@ -103,18 +103,9 @@
         with open(bvals_file) as fbvals:
             bvals = [val for val in re.split('\s+', fbvals.readline().strip())]
         with open(bvecs_file) as fbvecs:
-            bvecs_y = [
-                val for val in re.split('\s+',
-                                        fbvecs.readline().strip())
-            ]
-            bvecs_z = [
-                val for val in re.split('\s+',
-                                        fbvecs.readline().strip())
-            ]
-            bvecs_x = [
-                val for val in re.split('\s+',
-                                        fbvecs.readline().strip())
-            ]
+          bvecs_x = fbvecs.readline().split()
+          bvecs_y = fbvecs.readline().split()
+          bvecs_z = fbvecs.readline().split()
 
         with open(_gradient_matrix_file, 'w') as gradient_matrix_f:
             for i in range(len(bvals)):

{"golden_diff": "diff --git a/nipype/interfaces/diffusion_toolkit/dti.py b/nipype/interfaces/diffusion_toolkit/dti.py\n--- a/nipype/interfaces/diffusion_toolkit/dti.py\n+++ b/nipype/interfaces/diffusion_toolkit/dti.py\n@@ -103,18 +103,9 @@\n         with open(bvals_file) as fbvals:\n             bvals = [val for val in re.split('\\s+', fbvals.readline().strip())]\n         with open(bvecs_file) as fbvecs:\n-            bvecs_y = [\n-                val for val in re.split('\\s+',\n-                                        fbvecs.readline().strip())\n-            ]\n-            bvecs_z = [\n-                val for val in re.split('\\s+',\n-                                        fbvecs.readline().strip())\n-            ]\n-            bvecs_x = [\n-                val for val in re.split('\\s+',\n-                                        fbvecs.readline().strip())\n-            ]\n+          bvecs_x = fbvecs.readline().split()\n+          bvecs_y = fbvecs.readline().split()\n+          bvecs_z = fbvecs.readline().split()\n \n         with open(_gradient_matrix_file, 'w') as gradient_matrix_f:\n             for i in range(len(bvals)):\n", "issue": "Error creating gradient_matrix.txt in DTIRecon (Diffusion Toolkit)\n### Summary\r\nWhen the gradient_matrix.txt file is created from bvecs, the lines are [read](https://github.com/nipy/nipype/blob/db267032616ba05b5fd465491da6134e46041276/nipype/interfaces/diffusion_toolkit/dti.py#L106) in order y, z, x; instead of x, y, z swapping all the directions in the resulting gradient_matrix.txt file \r\n\r\n### Actual behavior\r\nThe columns of the actual gradient_matrix.txt are y, z, x, b-value.\r\n\r\n### Expected behavior\r\nThe columns of the expected gradient_matrix.txt must be x, y ,z, b-value.\r\n\r\n### How to replicate the behavior\r\nJust run the example in the documentation of nipype interface for Diffusion Toolkit. My data comes from a Philips Scanner.\r\n\r\n### Platform details:\r\n{'scipy_version': '1.0.0', 'sys_executable': '/Users/miguel/anaconda/bin/python', 'sys_platform': 'darwin', 'commit_hash': '%h', 'traits_version': '4.6.0', 'nipype_version': '1.0.0', 'pkg_path': '/Users/miguel/anaconda/lib/python3.5/site-packages/nipype', 'commit_source': 'archive substitution', 'nibabel_version': '2.2.1', 'numpy_version': '1.14.0', 'sys_version': '3.5.4 | packaged by conda-forge | (default, Dec 18 2017, 06:40:48) \\n[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]', 'networkx_version': '2.1'}\r\n1.0.0\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-\n# vi: set ft=python sts=4 ts=4 sw=4 et:\n\"\"\"Provides interfaces to various commands provided by diffusion toolkit\n\n   Change directory to provide relative paths for doctests\n   >>> import os\n   >>> filepath = os.path.dirname( os.path.realpath( __file__ ) )\n   >>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data'))\n   >>> os.chdir(datadir)\n\n\"\"\"\nfrom __future__ import (print_function, division, unicode_literals,\n                        absolute_import)\nfrom builtins import range, open\n\nimport os\nimport re\n\nfrom ...utils.filemanip import fname_presuffix, split_filename, copyfile\nfrom ..base import (TraitedSpec, File, traits, CommandLine,\n                    CommandLineInputSpec, isdefined)\n\n__docformat__ = 'restructuredtext'\n\n\nclass DTIReconInputSpec(CommandLineInputSpec):\n    DWI = File(\n        desc='Input diffusion volume',\n        argstr='%s',\n        exists=True,\n        mandatory=True,\n        position=1)\n    out_prefix = traits.Str(\n        \"dti\",\n        desc='Output file prefix',\n        argstr='%s',\n        usedefault=True,\n        position=2)\n    output_type = traits.Enum(\n        'nii',\n        'analyze',\n        'ni1',\n        'nii.gz',\n        argstr='-ot %s',\n        desc='output file type',\n        usedefault=True)\n    bvecs = File(\n        exists=True, desc='b vectors file', argstr='-gm %s', mandatory=True)\n    bvals = File(exists=True, desc='b values file', mandatory=True)\n    n_averages = traits.Int(desc='Number of averages', argstr='-nex %s')\n    image_orientation_vectors = traits.List(\n        traits.Float(),\n        minlen=6,\n        maxlen=6,\n        desc=\"\"\"specify image orientation vectors. if just one argument given,\n        will treat it as filename and read the orientation vectors from\n        the file. if 6 arguments are given, will treat them as 6 float\n        numbers and construct the 1st and 2nd vector and calculate the 3rd\n        one automatically.\n        this information will be used to determine image orientation,\n        as well as to adjust gradient vectors with oblique angle when\"\"\",\n        argstr=\"-iop %f\")\n    oblique_correction = traits.Bool(\n        desc=\"\"\"when oblique angle(s) applied, some SIEMENS dti protocols do not\n        adjust gradient accordingly, thus it requires adjustment for correct\n        diffusion tensor calculation\"\"\",\n        argstr=\"-oc\")\n    b0_threshold = traits.Float(\n        desc=\n        \"\"\"program will use b0 image with the given threshold to mask out high\n        background of fa/adc maps. by default it will calculate threshold\n        automatically. but if it failed, you need to set it manually.\"\"\",\n        argstr=\"-b0_th\")\n\n\nclass DTIReconOutputSpec(TraitedSpec):\n    ADC = File(exists=True)\n    B0 = File(exists=True)\n    L1 = File(exists=True)\n    L2 = File(exists=True)\n    L3 = File(exists=True)\n    exp = File(exists=True)\n    FA = File(exists=True)\n    FA_color = File(exists=True)\n    tensor = File(exists=True)\n    V1 = File(exists=True)\n    V2 = File(exists=True)\n    V3 = File(exists=True)\n\n\nclass DTIRecon(CommandLine):\n    \"\"\"Use dti_recon to generate tensors and other maps\n    \"\"\"\n\n    input_spec = DTIReconInputSpec\n    output_spec = DTIReconOutputSpec\n\n    _cmd = 'dti_recon'\n\n    def _create_gradient_matrix(self, bvecs_file, bvals_file):\n        _gradient_matrix_file = 'gradient_matrix.txt'\n        with open(bvals_file) as fbvals:\n            bvals = [val for val in re.split('\\s+', fbvals.readline().strip())]\n        with open(bvecs_file) as fbvecs:\n            bvecs_y = [\n                val for val in re.split('\\s+',\n                                        fbvecs.readline().strip())\n            ]\n            bvecs_z = [\n                val for val in re.split('\\s+',\n                                        fbvecs.readline().strip())\n            ]\n            bvecs_x = [\n                val for val in re.split('\\s+',\n                                        fbvecs.readline().strip())\n            ]\n\n        with open(_gradient_matrix_file, 'w') as gradient_matrix_f:\n            for i in range(len(bvals)):\n                gradient_matrix_f.write(\"%s, %s, %s, %s\\n\" %\n                                        (bvecs_x[i], bvecs_y[i], bvecs_z[i],\n                                         bvals[i]))\n        return _gradient_matrix_file\n\n    def _format_arg(self, name, spec, value):\n        if name == \"bvecs\":\n            new_val = self._create_gradient_matrix(self.inputs.bvecs,\n                                                   self.inputs.bvals)\n            return super(DTIRecon, self)._format_arg(\"bvecs\", spec, new_val)\n        return super(DTIRecon, self)._format_arg(name, spec, value)\n\n    def _list_outputs(self):\n        out_prefix = self.inputs.out_prefix\n        output_type = self.inputs.output_type\n\n        outputs = self.output_spec().get()\n        outputs['ADC'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_adc.' + output_type))\n        outputs['B0'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_b0.' + output_type))\n        outputs['L1'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_e1.' + output_type))\n        outputs['L2'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_e2.' + output_type))\n        outputs['L3'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_e3.' + output_type))\n        outputs['exp'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_exp.' + output_type))\n        outputs['FA'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_fa.' + output_type))\n        outputs['FA_color'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_fa_color.' + output_type))\n        outputs['tensor'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_tensor.' + output_type))\n        outputs['V1'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_v1.' + output_type))\n        outputs['V2'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_v2.' + output_type))\n        outputs['V3'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_v3.' + output_type))\n\n        return outputs\n\n\nclass DTITrackerInputSpec(CommandLineInputSpec):\n    tensor_file = File(exists=True, desc=\"reconstructed tensor file\")\n    input_type = traits.Enum(\n        'nii',\n        'analyze',\n        'ni1',\n        'nii.gz',\n        desc=\"\"\"input and output file type. accepted values are:\n        analyze -> analyze format 7.5\n        ni1     -> nifti format saved in seperate .hdr and .img file\n        nii     -> nifti format with one .nii file\n        nii.gz  -> nifti format with compression\n        default type is 'nii'\"\"\",\n        argstr=\"-it %s\")\n    tracking_method = traits.Enum(\n        'fact',\n        'rk2',\n        'tl',\n        'sl',\n        desc=\"\"\"fact -> use FACT method for tracking. this is the default method.\n        rk2  -> use 2nd order runge-kutta method for tracking.\n        tl   -> use tensorline method for tracking.\n        sl   -> use interpolated streamline method with fixed step-length\"\"\",\n        argstr=\"-%s\")\n    step_length = traits.Float(\n        desc=\"\"\"set step length, in the unit of minimum voxel size.\n        default value is 0.5 for interpolated streamline method\n        and 0.1 for other methods\"\"\",\n        argstr=\"-l %f\")\n    angle_threshold = traits.Float(\n        desc=\"set angle threshold. default value is 35 degree\",\n        argstr=\"-at %f\")\n    angle_threshold_weight = traits.Float(\n        desc=\n        \"set angle threshold weighting factor. weighting will be be applied \\\n        on top of the angle_threshold\",\n        argstr=\"-atw %f\")\n    random_seed = traits.Int(\n        desc=\"use random location in a voxel instead of the center of the voxel \\\n          to seed. can also define number of seed per voxel. default is 1\",\n        argstr=\"-rseed %d\")\n    invert_x = traits.Bool(\n        desc=\"invert x component of the vector\", argstr=\"-ix\")\n    invert_y = traits.Bool(\n        desc=\"invert y component of the vector\", argstr=\"-iy\")\n    invert_z = traits.Bool(\n        desc=\"invert z component of the vector\", argstr=\"-iz\")\n    swap_xy = traits.Bool(\n        desc=\"swap x & y vectors while tracking\", argstr=\"-sxy\")\n    swap_yz = traits.Bool(\n        desc=\"swap y & z vectors while tracking\", argstr=\"-syz\")\n    swap_zx = traits.Bool(\n        desc=\"swap x & z vectors while tracking\", argstr=\"-szx\")\n    mask1_file = File(\n        desc=\"first mask image\", mandatory=True, argstr=\"-m %s\", position=2)\n    mask1_threshold = traits.Float(\n        desc=\n        \"threshold value for the first mask image, if not given, the program will \\\n        try automatically find the threshold\",\n        position=3)\n    mask2_file = File(desc=\"second mask image\", argstr=\"-m2 %s\", position=4)\n    mask2_threshold = traits.Float(\n        desc=\n        \"threshold value for the second mask image, if not given, the program will \\\n        try automatically find the threshold\",\n        position=5)\n    input_data_prefix = traits.Str(\n        \"dti\",\n        desc=\"for internal naming use only\",\n        position=0,\n        argstr=\"%s\",\n        usedefault=True)\n    output_file = File(\n        \"tracks.trk\",\n        \"file containing tracks\",\n        argstr=\"%s\",\n        position=1,\n        usedefault=True)\n    output_mask = File(\n        desc=\"output a binary mask file in analyze format\", argstr=\"-om %s\")\n    primary_vector = traits.Enum(\n        'v2',\n        'v3',\n        desc=\n        \"which vector to use for fibre tracking: v2 or v3. If not set use v1\",\n        argstr=\"-%s\")\n\n\nclass DTITrackerOutputSpec(TraitedSpec):\n    track_file = File(exists=True)\n    mask_file = File(exists=True)\n\n\nclass DTITracker(CommandLine):\n    input_spec = DTITrackerInputSpec\n    output_spec = DTITrackerOutputSpec\n\n    _cmd = 'dti_tracker'\n\n    def _run_interface(self, runtime):\n        _, _, ext = split_filename(self.inputs.tensor_file)\n        copyfile(\n            self.inputs.tensor_file,\n            os.path.abspath(self.inputs.input_data_prefix + \"_tensor\" + ext),\n            copy=False)\n\n        return super(DTITracker, self)._run_interface(runtime)\n\n    def _list_outputs(self):\n        outputs = self.output_spec().get()\n        outputs['track_file'] = os.path.abspath(self.inputs.output_file)\n        if isdefined(self.inputs.output_mask) and self.inputs.output_mask:\n            outputs['mask_file'] = os.path.abspath(self.inputs.output_mask)\n\n        return outputs\n", "path": "nipype/interfaces/diffusion_toolkit/dti.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-\n# vi: set ft=python sts=4 ts=4 sw=4 et:\n\"\"\"Provides interfaces to various commands provided by diffusion toolkit\n\n   Change directory to provide relative paths for doctests\n   >>> import os\n   >>> filepath = os.path.dirname( os.path.realpath( __file__ ) )\n   >>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data'))\n   >>> os.chdir(datadir)\n\n\"\"\"\nfrom __future__ import (print_function, division, unicode_literals,\n                        absolute_import)\nfrom builtins import range, open\n\nimport os\nimport re\n\nfrom ...utils.filemanip import fname_presuffix, split_filename, copyfile\nfrom ..base import (TraitedSpec, File, traits, CommandLine,\n                    CommandLineInputSpec, isdefined)\n\n__docformat__ = 'restructuredtext'\n\n\nclass DTIReconInputSpec(CommandLineInputSpec):\n    DWI = File(\n        desc='Input diffusion volume',\n        argstr='%s',\n        exists=True,\n        mandatory=True,\n        position=1)\n    out_prefix = traits.Str(\n        \"dti\",\n        desc='Output file prefix',\n        argstr='%s',\n        usedefault=True,\n        position=2)\n    output_type = traits.Enum(\n        'nii',\n        'analyze',\n        'ni1',\n        'nii.gz',\n        argstr='-ot %s',\n        desc='output file type',\n        usedefault=True)\n    bvecs = File(\n        exists=True, desc='b vectors file', argstr='-gm %s', mandatory=True)\n    bvals = File(exists=True, desc='b values file', mandatory=True)\n    n_averages = traits.Int(desc='Number of averages', argstr='-nex %s')\n    image_orientation_vectors = traits.List(\n        traits.Float(),\n        minlen=6,\n        maxlen=6,\n        desc=\"\"\"specify image orientation vectors. if just one argument given,\n        will treat it as filename and read the orientation vectors from\n        the file. if 6 arguments are given, will treat them as 6 float\n        numbers and construct the 1st and 2nd vector and calculate the 3rd\n        one automatically.\n        this information will be used to determine image orientation,\n        as well as to adjust gradient vectors with oblique angle when\"\"\",\n        argstr=\"-iop %f\")\n    oblique_correction = traits.Bool(\n        desc=\"\"\"when oblique angle(s) applied, some SIEMENS dti protocols do not\n        adjust gradient accordingly, thus it requires adjustment for correct\n        diffusion tensor calculation\"\"\",\n        argstr=\"-oc\")\n    b0_threshold = traits.Float(\n        desc=\n        \"\"\"program will use b0 image with the given threshold to mask out high\n        background of fa/adc maps. by default it will calculate threshold\n        automatically. but if it failed, you need to set it manually.\"\"\",\n        argstr=\"-b0_th\")\n\n\nclass DTIReconOutputSpec(TraitedSpec):\n    ADC = File(exists=True)\n    B0 = File(exists=True)\n    L1 = File(exists=True)\n    L2 = File(exists=True)\n    L3 = File(exists=True)\n    exp = File(exists=True)\n    FA = File(exists=True)\n    FA_color = File(exists=True)\n    tensor = File(exists=True)\n    V1 = File(exists=True)\n    V2 = File(exists=True)\n    V3 = File(exists=True)\n\n\nclass DTIRecon(CommandLine):\n    \"\"\"Use dti_recon to generate tensors and other maps\n    \"\"\"\n\n    input_spec = DTIReconInputSpec\n    output_spec = DTIReconOutputSpec\n\n    _cmd = 'dti_recon'\n\n    def _create_gradient_matrix(self, bvecs_file, bvals_file):\n        _gradient_matrix_file = 'gradient_matrix.txt'\n        with open(bvals_file) as fbvals:\n            bvals = [val for val in re.split('\\s+', fbvals.readline().strip())]\n        with open(bvecs_file) as fbvecs:\n          bvecs_x = fbvecs.readline().split()\n          bvecs_y = fbvecs.readline().split()\n          bvecs_z = fbvecs.readline().split()\n\n        with open(_gradient_matrix_file, 'w') as gradient_matrix_f:\n            for i in range(len(bvals)):\n                gradient_matrix_f.write(\"%s, %s, %s, %s\\n\" %\n                                        (bvecs_x[i], bvecs_y[i], bvecs_z[i],\n                                         bvals[i]))\n        return _gradient_matrix_file\n\n    def _format_arg(self, name, spec, value):\n        if name == \"bvecs\":\n            new_val = self._create_gradient_matrix(self.inputs.bvecs,\n                                                   self.inputs.bvals)\n            return super(DTIRecon, self)._format_arg(\"bvecs\", spec, new_val)\n        return super(DTIRecon, self)._format_arg(name, spec, value)\n\n    def _list_outputs(self):\n        out_prefix = self.inputs.out_prefix\n        output_type = self.inputs.output_type\n\n        outputs = self.output_spec().get()\n        outputs['ADC'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_adc.' + output_type))\n        outputs['B0'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_b0.' + output_type))\n        outputs['L1'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_e1.' + output_type))\n        outputs['L2'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_e2.' + output_type))\n        outputs['L3'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_e3.' + output_type))\n        outputs['exp'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_exp.' + output_type))\n        outputs['FA'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_fa.' + output_type))\n        outputs['FA_color'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_fa_color.' + output_type))\n        outputs['tensor'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_tensor.' + output_type))\n        outputs['V1'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_v1.' + output_type))\n        outputs['V2'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_v2.' + output_type))\n        outputs['V3'] = os.path.abspath(\n            fname_presuffix(\n                \"\", prefix=out_prefix, suffix='_v3.' + output_type))\n\n        return outputs\n\n\nclass DTITrackerInputSpec(CommandLineInputSpec):\n    tensor_file = File(exists=True, desc=\"reconstructed tensor file\")\n    input_type = traits.Enum(\n        'nii',\n        'analyze',\n        'ni1',\n        'nii.gz',\n        desc=\"\"\"input and output file type. accepted values are:\n        analyze -> analyze format 7.5\n        ni1     -> nifti format saved in seperate .hdr and .img file\n        nii     -> nifti format with one .nii file\n        nii.gz  -> nifti format with compression\n        default type is 'nii'\"\"\",\n        argstr=\"-it %s\")\n    tracking_method = traits.Enum(\n        'fact',\n        'rk2',\n        'tl',\n        'sl',\n        desc=\"\"\"fact -> use FACT method for tracking. this is the default method.\n        rk2  -> use 2nd order runge-kutta method for tracking.\n        tl   -> use tensorline method for tracking.\n        sl   -> use interpolated streamline method with fixed step-length\"\"\",\n        argstr=\"-%s\")\n    step_length = traits.Float(\n        desc=\"\"\"set step length, in the unit of minimum voxel size.\n        default value is 0.5 for interpolated streamline method\n        and 0.1 for other methods\"\"\",\n        argstr=\"-l %f\")\n    angle_threshold = traits.Float(\n        desc=\"set angle threshold. default value is 35 degree\",\n        argstr=\"-at %f\")\n    angle_threshold_weight = traits.Float(\n        desc=\n        \"set angle threshold weighting factor. weighting will be be applied \\\n        on top of the angle_threshold\",\n        argstr=\"-atw %f\")\n    random_seed = traits.Int(\n        desc=\"use random location in a voxel instead of the center of the voxel \\\n          to seed. can also define number of seed per voxel. default is 1\",\n        argstr=\"-rseed %d\")\n    invert_x = traits.Bool(\n        desc=\"invert x component of the vector\", argstr=\"-ix\")\n    invert_y = traits.Bool(\n        desc=\"invert y component of the vector\", argstr=\"-iy\")\n    invert_z = traits.Bool(\n        desc=\"invert z component of the vector\", argstr=\"-iz\")\n    swap_xy = traits.Bool(\n        desc=\"swap x & y vectors while tracking\", argstr=\"-sxy\")\n    swap_yz = traits.Bool(\n        desc=\"swap y & z vectors while tracking\", argstr=\"-syz\")\n    swap_zx = traits.Bool(\n        desc=\"swap x & z vectors while tracking\", argstr=\"-szx\")\n    mask1_file = File(\n        desc=\"first mask image\", mandatory=True, argstr=\"-m %s\", position=2)\n    mask1_threshold = traits.Float(\n        desc=\n        \"threshold value for the first mask image, if not given, the program will \\\n        try automatically find the threshold\",\n        position=3)\n    mask2_file = File(desc=\"second mask image\", argstr=\"-m2 %s\", position=4)\n    mask2_threshold = traits.Float(\n        desc=\n        \"threshold value for the second mask image, if not given, the program will \\\n        try automatically find the threshold\",\n        position=5)\n    input_data_prefix = traits.Str(\n        \"dti\",\n        desc=\"for internal naming use only\",\n        position=0,\n        argstr=\"%s\",\n        usedefault=True)\n    output_file = File(\n        \"tracks.trk\",\n        \"file containing tracks\",\n        argstr=\"%s\",\n        position=1,\n        usedefault=True)\n    output_mask = File(\n        desc=\"output a binary mask file in analyze format\", argstr=\"-om %s\")\n    primary_vector = traits.Enum(\n        'v2',\n        'v3',\n        desc=\n        \"which vector to use for fibre tracking: v2 or v3. If not set use v1\",\n        argstr=\"-%s\")\n\n\nclass DTITrackerOutputSpec(TraitedSpec):\n    track_file = File(exists=True)\n    mask_file = File(exists=True)\n\n\nclass DTITracker(CommandLine):\n    input_spec = DTITrackerInputSpec\n    output_spec = DTITrackerOutputSpec\n\n    _cmd = 'dti_tracker'\n\n    def _run_interface(self, runtime):\n        _, _, ext = split_filename(self.inputs.tensor_file)\n        copyfile(\n            self.inputs.tensor_file,\n            os.path.abspath(self.inputs.input_data_prefix + \"_tensor\" + ext),\n            copy=False)\n\n        return super(DTITracker, self)._run_interface(runtime)\n\n    def _list_outputs(self):\n        outputs = self.output_spec().get()\n        outputs['track_file'] = os.path.abspath(self.inputs.output_file)\n        if isdefined(self.inputs.output_mask) and self.inputs.output_mask:\n            outputs['mask_file'] = os.path.abspath(self.inputs.output_mask)\n\n        return outputs\n", "path": "nipype/interfaces/diffusion_toolkit/dti.py"}]}