Skip to content

Commit e0754aa

Browse files
committed
Merge pull request #817 from mick-d/camino
Now possible with camino ProcStreamlines (convert.py) to collect created...
2 parents 99b354a + a8506b8 commit e0754aa

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

nipype/interfaces/camino/convert.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
88
"""
99
import os
10+
import glob
1011

1112
from nipype.interfaces.base import (CommandLineInputSpec, CommandLine, traits,
1213
TraitedSpec, File, StdOutCommandLine,
13-
StdOutCommandLineInputSpec, isdefined)
14+
OutputMultiPath, StdOutCommandLineInputSpec,
15+
isdefined)
1416
from nipype.utils.filemanip import split_filename
1517

1618
class 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

237243
class ProcStreamlinesOutputSpec(TraitedSpec):
238244
proc = File(exists=True, desc='Processed Streamlines')
245+
outputroot_files = OutputMultiPath(File(exists=True))
239246

240247
class 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):

nipype/interfaces/camino/tests/test_auto_ProcStreamlines.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ def test_ProcStreamlines_inputs():
5656
position=-1,
5757
),
5858
outputacm=dict(argstr='-outputacm',
59+
requires=['outputroot', 'seedfile'],
5960
),
6061
outputcbs=dict(argstr='-outputcbs',
62+
requires=['outputroot', 'targetfile', 'seedfile'],
6163
),
6264
outputcp=dict(argstr='-outputcp',
65+
requires=['outputroot', 'seedfile'],
6366
),
6467
outputroot=dict(argstr='-outputroot %s',
6568
),
6669
outputsc=dict(argstr='-outputsc',
70+
requires=['outputroot', 'seedfile'],
6771
),
6872
outputtracts=dict(argstr='-outputtracts',
6973
),
@@ -103,7 +107,8 @@ def test_ProcStreamlines_inputs():
103107
yield assert_equal, getattr(inputs.traits()[key], metakey), value
104108

105109
def test_ProcStreamlines_outputs():
106-
output_map = dict(proc=dict(),
110+
output_map = dict(outputroot_files=dict(),
111+
proc=dict(),
107112
)
108113
outputs = ProcStreamlines.output_spec()
109114

0 commit comments

Comments
 (0)