Skip to content

Commit b84fb2f

Browse files
committed
Merge pull request #691 from beOn/spm_preproc
spm preproc fixes and adds
2 parents 80e46d3 + d03ea56 commit b84fb2f

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

nipype/interfaces/spm/preprocess.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ class SliceTimingInputSpec(SPMCommandInputSpec):
5555

5656

5757
class SliceTimingOutputSpec(TraitedSpec):
58-
timecorrected_files = OutputMultiPath(File(exist=True,
59-
desc='slice time corrected files'))
58+
timecorrected_files = OutputMultiPath(traits.Either(traits.List(File(exists=True)),
59+
File(exists=True)),
60+
desc='slice time corrected files')
6061

6162

6263
class SliceTiming(SPMCommand):
@@ -100,15 +101,11 @@ def _list_outputs(self):
100101

101102
filelist = filename_to_list(self.inputs.in_files)
102103
for f in filelist:
103-
run = []
104104
if isinstance(f, list):
105-
for inner_f in filename_to_list(f):
106-
run.append(fname_presuffix(inner_f,
107-
prefix=self.inputs.out_prefix))
105+
run = [fname_presuffix(in_f, prefix=self.inputs.out_prefix) for in_f in f]
108106
else:
109-
realigned_run = fname_presuffix(f,
110-
prefix=self.inputs.out_prefix)
111-
outputs['timecorrected_files'].append(realigned_run)
107+
run = fname_presuffix(f, prefix=self.inputs.out_prefix)
108+
outputs['timecorrected_files'].append(run)
112109
return outputs
113110

114111

@@ -152,9 +149,18 @@ class RealignInputSpec(SPMCommandInputSpec):
152149

153150
class RealignOutputSpec(TraitedSpec):
154151
mean_image = File(exists=True, desc='Mean image file from the realignment')
152+
modified_in_files = OutputMultiPath(traits.Either(traits.List(File(exists=True)),
153+
File(exists=True)),
154+
desc='Copies of all files passed to in_files.\
155+
Headers will have been modified to align all\
156+
images with the first, or optionally to first\
157+
do that, extract a mean image, and re-align to\
158+
that mean image.')
155159
realigned_files = OutputMultiPath(traits.Either(traits.List(File(exists=True)),
156160
File(exists=True)),
157-
desc='Realigned files')
161+
desc='If jobtype is write or estwrite, these will be the\
162+
resliced files. Otherwise, they will be copies of\
163+
in_files that have had their headers rewritten.')
158164
realignment_parameters = OutputMultiPath(File(exists=True),
159165
desc='Estimated translation and rotation parameters')
160166

@@ -213,6 +219,10 @@ def _list_outputs(self):
213219
use_ext=False))
214220
if not isinstance(imgf, list) and func_is_3d(imgf):
215221
break
222+
if self.inputs.jobtype == "estimate":
223+
outputs['realigned_files'] = self.inputs.in_files
224+
if self.inputs.jobtype == "estimate" or self.inputs.jobtype == "estwrite":
225+
outputs['modified_in_files'] = self.inputs.in_files
216226
if self.inputs.jobtype == "write" or self.inputs.jobtype == "estwrite":
217227
if isinstance(self.inputs.in_files[0], list):
218228
first_image = self.inputs.in_files[0][0]
@@ -367,8 +377,11 @@ class NormalizeInputSpec(SPMCommandInputSpec):
367377
jobtype = traits.Enum('estwrite', 'est', 'write',
368378
desc='one of: est, write, estwrite (opt, estwrite)',
369379
usedefault=True)
370-
apply_to_files = InputMultiPath(File(exists=True), field='subj.resample',
371-
desc='files to apply transformation to (opt)', copyfile=True)
380+
apply_to_files = InputMultiPath(traits.Either(File(exists=True),
381+
traits.List(File(exists=True))),
382+
field='subj.resample',
383+
desc='files to apply transformation to (opt)',
384+
copyfile=True)
372385
parameter_file = File(field='subj.matname', mandatory=True,
373386
xor=['source', 'template'],
374387
desc='normalization parameter file*_sn.mat', copyfile=False)
@@ -481,9 +494,13 @@ def _list_outputs(self):
481494
elif 'write' in self.inputs.jobtype:
482495
outputs['normalized_files'] = []
483496
if isdefined(self.inputs.apply_to_files):
484-
for imgf in filename_to_list(self.inputs.apply_to_files):
485-
outputs['normalized_files'].append(fname_presuffix(imgf, prefix=self.inputs.out_prefix))
486-
497+
filelist = filename_to_list(self.inputs.apply_to_files)
498+
for f in filelist:
499+
if isinstance(f, list):
500+
run = [fname_presuffix(in_f, prefix=self.inputs.out_prefix) for in_f in f]
501+
else:
502+
run = [fname_presuffix(f, prefix=self.inputs.out_prefix)]
503+
outputs['normalized_files'].extend(run)
487504
if isdefined(self.inputs.source):
488505
outputs['normalized_source'] = []
489506
for imgf in filename_to_list(self.inputs.source):

0 commit comments

Comments
 (0)