1616from nipype .utils .filemanip import split_filename
1717import re
1818
19+
1920class Dcm2niiInputSpec (CommandLineInputSpec ):
2021 source_names = InputMultiPath (File (exists = True ), argstr = "%s" , position = - 1 ,
2122 copyfile = False , mandatory = True , xor = ['source_dir' ])
@@ -37,13 +38,15 @@ class Dcm2niiInputSpec(CommandLineInputSpec):
3738 convert_all_pars = traits .Bool (True , argstr = '-v' , usedefault = True )
3839 reorient_and_crop = traits .Bool (False , argstr = '-x' , usedefault = True )
3940
41+
4042class Dcm2niiOutputSpec (TraitedSpec ):
4143 converted_files = OutputMultiPath (File (exists = True ))
4244 reoriented_files = OutputMultiPath (File (exists = True ))
4345 reoriented_and_cropped_files = OutputMultiPath (File (exists = True ))
4446 bvecs = OutputMultiPath (File (exists = True ))
4547 bvals = OutputMultiPath (File (exists = True ))
4648
49+
4750class Dcm2nii (CommandLine ):
4851 """Uses MRICRON's dcm2nii to convert dicom files
4952
@@ -60,9 +63,8 @@ class Dcm2nii(CommandLine):
6063 >>> converter.run() # doctest: +SKIP
6164 """
6265
63- input_spec = Dcm2niiInputSpec
64- output_spec = Dcm2niiOutputSpec
65-
66+ input_spec = Dcm2niiInputSpec
67+ output_spec = Dcm2niiOutputSpec
6668 _cmd = 'dcm2nii'
6769
6870 def _format_arg (self , opt , spec , val ):
@@ -81,7 +83,6 @@ def _format_arg(self, opt, spec, val):
8183 return super (Dcm2nii , self )._format_arg (opt , spec , val )
8284
8385 def _run_interface (self , runtime ):
84-
8586 new_runtime = super (Dcm2nii , self )._run_interface (runtime )
8687 (self .output_files ,
8788 self .reoriented_files ,
@@ -99,22 +100,21 @@ def _parse_stdout(self, stdout):
99100 last_added_file = None
100101 for line in stdout .split ("\n " ):
101102 if not skip :
102- file = None
103+ out_file = None
103104 if line .startswith ("Saving " ):
104- file = line [len ("Saving " ):]
105+ out_file = line [len ("Saving " ):]
105106 elif line .startswith ("GZip..." ):
106- #for gzipped outpus files are not absolute
107+ # for gzipped outpus files are not absolute
107108 if isdefined (self .inputs .output_dir ):
108109 output_dir = self .inputs .output_dir
109110 else :
110111 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..." ):]))
113113 elif line .startswith ("Number of diffusion directions " ):
114114 if last_added_file :
115115 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" ))
118118 elif re .search ('.*-->(.*)' , line ):
119119 val = re .search ('.*-->(.*)' , line )
120120 val = val .groups ()[0 ]
@@ -123,11 +123,11 @@ def _parse_stdout(self, stdout):
123123 else :
124124 output_dir = self ._gen_filename ('output_dir' )
125125 val = os .path .join (output_dir , val )
126- file = val
126+ out_file = val
127127
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
131131 continue
132132
133133 if line .startswith ("Reorienting as " ):
@@ -163,4 +163,3 @@ def _gen_filename(self, name):
163163 f .close ()
164164 return config_file
165165 return None
166-
0 commit comments