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,29 @@ class ProcStreamlines(StdOutCommandLine):
256
263
input_spec = ProcStreamlinesInputSpec
257
264
output_spec = ProcStreamlinesOutputSpec
258
265
266
+ def _run_interface (self , runtime ):
267
+ outputroot = self .inputs .outputroot
268
+ if isdefined (outputroot ):
269
+ outputroot = os .path .join ('procstream_outfiles' , outputroot )
270
+ base , filename , ext = split_filename (outputroot )
271
+ if not os .path .exists (base ):
272
+ os .makedirs (base )
273
+ self .inputs .outputroot = outputroot
274
+ new_runtime = super (ProcStreamlines , self )._run_interface (runtime )
275
+ self .outputroot_files = self ._get_ouputroot_files (outputroot )
276
+ return new_runtime
277
+ else :
278
+ new_runtime = super (ProcStreamlines , self )._run_interface (runtime )
279
+ return new_runtime
280
+
281
+ def _get_ouputroot_files (self , outputroot ):
282
+ outputroot_files = glob .glob (os .path .join (os .getcwd (),outputroot + '*' ))
283
+ return outputroot_files
284
+
259
285
def _list_outputs (self ):
260
286
outputs = self .output_spec ().get ()
261
287
outputs ['proc' ] = os .path .abspath (self ._gen_outfilename ())
288
+ outputs ['outputroot_files' ] = self .outputroot_files
262
289
return outputs
263
290
264
291
def _gen_outfilename (self ):
0 commit comments