7
7
8
8
"""
9
9
import os
10
+ import glob
10
11
11
12
from nipype .interfaces .base import (CommandLineInputSpec , CommandLine , traits ,
12
13
TraitedSpec , File , StdOutCommandLine ,
13
- StdOutCommandLineInputSpec , isdefined )
14
+ OutputMultiPath , StdOutCommandLineInputSpec ,
15
+ isdefined )
14
16
from nipype .utils .filemanip import split_filename
15
17
16
18
class Image2VoxelInputSpec (StdOutCommandLineInputSpec ):
@@ -226,16 +228,21 @@ class ProcStreamlinesInputSpec(StdOutCommandLineInputSpec):
226
228
outputtracts = traits .Bool (argstr = '-outputtracts' , desc = "Output streamlines in raw binary format." )
227
229
228
230
outputroot = File (exists = False , argstr = '-outputroot %s' ,
229
- desc = 'root directory for output' )
231
+ desc = 'Prepended onto all output file names. ' )
230
232
231
233
gzip = traits .Bool (argstr = '-gzip' , desc = "save the output image in gzip format" )
232
- outputcp = traits .Bool (argstr = '-outputcp' , desc = "output the connection probability map (Analyze image, float)" )
233
- outputsc = traits .Bool (argstr = '-outputsc' , desc = "output the connection probability map (raw streamlines, int)" )
234
- outputacm = traits .Bool (argstr = '-outputacm' , desc = "output all tracts in a single connection probability map (Analyze image)" )
235
- outputcbs = traits .Bool (argstr = '-outputcbs' , desc = "outputs connectivity-based segmentation maps; requires target outputfile" )
234
+ outputcp = traits .Bool (argstr = '-outputcp' , desc = "output the connection probability map (Analyze image, float)" ,
235
+ requires = ['outputroot' ,'seedfile' ])
236
+ outputsc = traits .Bool (argstr = '-outputsc' , desc = "output the connection probability map (raw streamlines, int)" ,
237
+ requires = ['outputroot' ,'seedfile' ])
238
+ outputacm = traits .Bool (argstr = '-outputacm' , desc = "output all tracts in a single connection probability map (Analyze image)" ,
239
+ requires = ['outputroot' ,'seedfile' ])
240
+ outputcbs = traits .Bool (argstr = '-outputcbs' , desc = "outputs connectivity-based segmentation maps; requires target outputfile" ,
241
+ requires = ['outputroot' ,'targetfile' ,'seedfile' ])
236
242
237
243
class ProcStreamlinesOutputSpec (TraitedSpec ):
238
244
proc = File (exists = True , desc = 'Processed Streamlines' )
245
+ outputroot_files = OutputMultiPath (File (exists = True ))
239
246
240
247
class ProcStreamlines (StdOutCommandLine ):
241
248
"""
@@ -256,9 +263,33 @@ class ProcStreamlines(StdOutCommandLine):
256
263
input_spec = ProcStreamlinesInputSpec
257
264
output_spec = ProcStreamlinesOutputSpec
258
265
266
+ def _format_arg (self , name , spec , value ):
267
+ if name == 'outputroot' :
268
+ return spec .argstr % self ._get_actual_outputroot (value )
269
+ return super (ProcStreamlines , self )._format_arg (name , spec , value )
270
+
271
+ def _run_interface (self , runtime ):
272
+ outputroot = self .inputs .outputroot
273
+ if isdefined (outputroot ):
274
+ actual_outputroot = self ._get_actual_outputroot (outputroot )
275
+ base , filename , ext = split_filename (actual_outputroot )
276
+ if not os .path .exists (base ):
277
+ os .makedirs (base )
278
+ new_runtime = super (ProcStreamlines , self )._run_interface (runtime )
279
+ self .outputroot_files = glob .glob (os .path .join (os .getcwd (),actual_outputroot + '*' ))
280
+ return new_runtime
281
+ else :
282
+ new_runtime = super (ProcStreamlines , self )._run_interface (runtime )
283
+ return new_runtime
284
+
285
+ def _get_actual_outputroot (self , outputroot ):
286
+ actual_outputroot = os .path .join ('procstream_outfiles' , outputroot )
287
+ return actual_outputroot
288
+
259
289
def _list_outputs (self ):
260
290
outputs = self .output_spec ().get ()
261
291
outputs ['proc' ] = os .path .abspath (self ._gen_outfilename ())
292
+ outputs ['outputroot_files' ] = self .outputroot_files
262
293
return outputs
263
294
264
295
def _gen_outfilename (self ):
0 commit comments