77
88"""
99import os
10+ import glob
1011
1112from nipype .interfaces .base import (CommandLineInputSpec , CommandLine , traits ,
1213 TraitedSpec , File , StdOutCommandLine ,
13- StdOutCommandLineInputSpec , isdefined )
14+ OutputMultiPath , StdOutCommandLineInputSpec ,
15+ isdefined )
1416from nipype .utils .filemanip import split_filename
1517
1618class Image2VoxelInputSpec (StdOutCommandLineInputSpec ):
@@ -226,16 +228,21 @@ class ProcStreamlinesInputSpec(StdOutCommandLineInputSpec):
226228 outputtracts = traits .Bool (argstr = '-outputtracts' , desc = "Output streamlines in raw binary format." )
227229
228230 outputroot = File (exists = False , argstr = '-outputroot %s' ,
229- desc = 'root directory for output' )
231+ desc = 'Prepended onto all output file names. ' )
230232
231233 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' ])
236242
237243class ProcStreamlinesOutputSpec (TraitedSpec ):
238244 proc = File (exists = True , desc = 'Processed Streamlines' )
245+ outputroot_files = OutputMultiPath (File (exists = True ))
239246
240247class ProcStreamlines (StdOutCommandLine ):
241248 """
@@ -256,9 +263,33 @@ class ProcStreamlines(StdOutCommandLine):
256263 input_spec = ProcStreamlinesInputSpec
257264 output_spec = ProcStreamlinesOutputSpec
258265
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+
259289 def _list_outputs (self ):
260290 outputs = self .output_spec ().get ()
261291 outputs ['proc' ] = os .path .abspath (self ._gen_outfilename ())
292+ outputs ['outputroot_files' ] = self .outputroot_files
262293 return outputs
263294
264295 def _gen_outfilename (self ):
0 commit comments