|
13 | 13 | import nipype.interfaces.base as nib
|
14 | 14 | import nipype.pipeline.engine as pe
|
15 | 15 | from nipype.interfaces.utility import IdentityInterface
|
| 16 | +from nipype.interfaces.base import traits, File |
| 17 | + |
| 18 | +class PickFirstSpec(nib.TraitedSpec): |
| 19 | + in_files = traits.List(File(exists=True), argstr="%s", position=2, |
| 20 | + mandatory=True) |
| 21 | + |
| 22 | +class PickFirstOutSpec(nib.TraitedSpec): |
| 23 | + output1 = File(exists=True) |
| 24 | + |
| 25 | +class PickFirst(nib.BaseInterface): |
| 26 | + input_spec = PickFirstSpec |
| 27 | + output_spec = PickFirstOutSpec |
| 28 | + |
| 29 | + def _run_interface(self, runtime): |
| 30 | + runtime.returncode = 0 |
| 31 | + return runtime |
| 32 | + |
| 33 | + def _list_outputs(self): |
| 34 | + outputs = self._outputs().get() |
| 35 | + outputs['output1'] = self.inputs.in_files[0] |
| 36 | + return outputs |
16 | 37 |
|
17 | 38 |
|
18 | 39 | class IncrementInputSpec(nib.TraitedSpec):
|
@@ -528,6 +549,32 @@ def test_itersource_two_join_nodes():
|
528 | 549 |
|
529 | 550 | os.chdir(cwd)
|
530 | 551 | rmtree(wd)
|
| 552 | + |
| 553 | +def test_set_join_node_file_input(): |
| 554 | + """Test collecting join inputs to a set.""" |
| 555 | + cwd = os.getcwd() |
| 556 | + wd = mkdtemp() |
| 557 | + os.chdir(wd) |
| 558 | + open('test.nii', 'w+').close() |
| 559 | + open('test2.nii', 'w+').close() |
| 560 | + |
| 561 | + # Make the workflow. |
| 562 | + wf = pe.Workflow(name='test') |
| 563 | + # the iterated input node |
| 564 | + inputspec = pe.Node(IdentityInterface(fields=['n']), name='inputspec') |
| 565 | + inputspec.iterables = [('n', [os.path.join(wd, 'test.nii'), os.path.join(wd, 'test2.nii')])] |
| 566 | + # a pre-join node in the iterated path |
| 567 | + pre_join1 = pe.Node(IdentityInterface(fields=['n']), name='pre_join1') |
| 568 | + wf.connect(inputspec, 'n', pre_join1, 'n') |
| 569 | + # the set join node |
| 570 | + join = pe.JoinNode(PickFirst(), joinsource='inputspec', |
| 571 | + joinfield='in_files', name='join') |
| 572 | + wf.connect(pre_join1, 'n', join, 'in_files') |
| 573 | + |
| 574 | + wf.run() |
| 575 | + |
| 576 | + os.chdir(cwd) |
| 577 | + rmtree(wd) |
531 | 578 |
|
532 | 579 |
|
533 | 580 | if __name__ == "__main__":
|
|
0 commit comments