16
16
from nipype .utils .filemanip import split_filename
17
17
import re
18
18
19
+
19
20
class Dcm2niiInputSpec (CommandLineInputSpec ):
20
21
source_names = InputMultiPath (File (exists = True ), argstr = "%s" , position = - 1 ,
21
22
copyfile = False , mandatory = True , xor = ['source_dir' ])
@@ -37,13 +38,15 @@ class Dcm2niiInputSpec(CommandLineInputSpec):
37
38
convert_all_pars = traits .Bool (True , argstr = '-v' , usedefault = True )
38
39
reorient_and_crop = traits .Bool (False , argstr = '-x' , usedefault = True )
39
40
41
+
40
42
class Dcm2niiOutputSpec (TraitedSpec ):
41
43
converted_files = OutputMultiPath (File (exists = True ))
42
44
reoriented_files = OutputMultiPath (File (exists = True ))
43
45
reoriented_and_cropped_files = OutputMultiPath (File (exists = True ))
44
46
bvecs = OutputMultiPath (File (exists = True ))
45
47
bvals = OutputMultiPath (File (exists = True ))
46
48
49
+
47
50
class Dcm2nii (CommandLine ):
48
51
"""Uses MRICRON's dcm2nii to convert dicom files
49
52
@@ -60,9 +63,8 @@ class Dcm2nii(CommandLine):
60
63
>>> converter.run() # doctest: +SKIP
61
64
"""
62
65
63
- input_spec = Dcm2niiInputSpec
64
- output_spec = Dcm2niiOutputSpec
65
-
66
+ input_spec = Dcm2niiInputSpec
67
+ output_spec = Dcm2niiOutputSpec
66
68
_cmd = 'dcm2nii'
67
69
68
70
def _format_arg (self , opt , spec , val ):
@@ -81,7 +83,6 @@ def _format_arg(self, opt, spec, val):
81
83
return super (Dcm2nii , self )._format_arg (opt , spec , val )
82
84
83
85
def _run_interface (self , runtime ):
84
-
85
86
new_runtime = super (Dcm2nii , self )._run_interface (runtime )
86
87
(self .output_files ,
87
88
self .reoriented_files ,
@@ -99,22 +100,21 @@ def _parse_stdout(self, stdout):
99
100
last_added_file = None
100
101
for line in stdout .split ("\n " ):
101
102
if not skip :
102
- file = None
103
+ out_file = None
103
104
if line .startswith ("Saving " ):
104
- file = line [len ("Saving " ):]
105
+ out_file = line [len ("Saving " ):]
105
106
elif line .startswith ("GZip..." ):
106
- #for gzipped outpus files are not absolute
107
+ # for gzipped outpus files are not absolute
107
108
if isdefined (self .inputs .output_dir ):
108
109
output_dir = self .inputs .output_dir
109
110
else :
110
111
output_dir = self ._gen_filename ('output_dir' )
111
- file = os .path .abspath (os .path .join (output_dir ,
112
- line [len ("GZip..." ):]))
112
+ out_file = os .path .abspath (os .path .join (output_dir , line [len ("GZip..." ):]))
113
113
elif line .startswith ("Number of diffusion directions " ):
114
114
if last_added_file :
115
115
base , filename , ext = split_filename (last_added_file )
116
- bvecs .append (os .path .join (base ,filename + ".bvec" ))
117
- bvals .append (os .path .join (base ,filename + ".bval" ))
116
+ bvecs .append (os .path .join (base , filename + ".bvec" ))
117
+ bvals .append (os .path .join (base , filename + ".bval" ))
118
118
elif re .search ('.*-->(.*)' , line ):
119
119
val = re .search ('.*-->(.*)' , line )
120
120
val = val .groups ()[0 ]
@@ -123,11 +123,11 @@ def _parse_stdout(self, stdout):
123
123
else :
124
124
output_dir = self ._gen_filename ('output_dir' )
125
125
val = os .path .join (output_dir , val )
126
- file = val
126
+ out_file = val
127
127
128
- if file :
129
- files .append (file )
130
- last_added_file = file
128
+ if out_file :
129
+ files .append (out_file )
130
+ last_added_file = out_file
131
131
continue
132
132
133
133
if line .startswith ("Reorienting as " ):
@@ -163,4 +163,3 @@ def _gen_filename(self, name):
163
163
f .close ()
164
164
return config_file
165
165
return None
166
-
0 commit comments