Skip to content

Commit 44b6585

Browse files
author
bpinsard
committed
Merge branch 'master' into nitime
* master: (28 commits) fixed applymask output fixed test Fixed some details for the PR nipy#530 Removed accidentally added files (nipy#530) Updated changelog Updated dMRI and fMRI pre-processing Added motion correction pipeline Modified FSL FLIRT interface to provide log support Polished code buildtemplateparallel.sh - issue with input files Update legacy.py - buildtemplateparallel.sh Minor fixes Added MBIS to sub-package configuration list Standardized import to add all utilities at once First implementation for MBIS New EPI dewarp workflow (nipy#525) New EPI dewarping using a workflow api: force users to explicitly define whether to sort files BF: Fix SplitNifti to generate unique filenames for outputs. added mask input for bias field correction ...
2 parents 4bc9e2c + ea909c7 commit 44b6585

File tree

14 files changed

+824
-255
lines changed

14 files changed

+824
-255
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Next release
33
* ENH: New interfaces: nipy.Trim
44

55
* ENH: Allow control over terminal output for commandline interfaces
6+
* ENH: New workflows for dMRI and fMRI pre-processing: added motion artifact correction
7+
with rotation of the B-matrix, and susceptibility correction for EPI imaging using
8+
fieldmaps. Updated eddy_correct pipeline to support both dMRI and fMRI, and new parameters.
9+
* ENH: Minor improvements to FSL's FUGUE and FLIRT interfaces
610

711
Release 0.7.0 (Dec 18, 2012)
812
============================

nipype/interfaces/afni/base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,10 @@ def _gen_filename(self, name):
216216

217217
_, base, _ = split_filename(
218218
getattr(self.inputs, trait_spec.name_source))
219-
return self._gen_fname(basename=base, prefix=prefix, suffix=suffix, cwd='')
219+
return self._gen_fname(basename=base, prefix=prefix, suffix=suffix, cwd=os.getcwd())
220220
else:
221-
return super(AFNICommand, self)._gen_filename(name)
221+
return os.path.join(os.getcwd(),
222+
super(AFNICommand, self)._gen_filename(name))
222223

223224
def _overload_extension(self, value):
224225
path, base, _ = split_filename(value)
@@ -231,7 +232,8 @@ def _list_outputs(self):
231232
outputs = self.output_spec().get()
232233
for name in out_names:
233234
out = self._gen_filename(name)
234-
outputs[name] = os.path.abspath(out)
235+
if isdefined(out):
236+
outputs[name] = os.path.abspath(out)
235237
return outputs
236238

237239

nipype/interfaces/afni/preprocess.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import os
1313
from .base import AFNIBaseCommandInputSpec, AFNIBaseCommand
1414
from ..base import (Directory, CommandLineInputSpec, CommandLine, TraitedSpec,
15-
traits, isdefined, File, InputMultiPath)
15+
traits, isdefined, File, InputMultiPath, Undefined)
1616
from ...utils.filemanip import (load_json, save_json, split_filename)
1717
from nipype.utils.filemanip import fname_presuffix
1818
from nipype.interfaces.afni.base import AFNICommand, AFNICommandInputSpec,\
@@ -280,7 +280,7 @@ class ResampleInputSpec(AFNICommandInputSpec):
280280
argstr='-orient %s')
281281

282282

283-
class Resample(AFNIBaseCommand):
283+
class Resample(AFNICommand):
284284
"""Resample or reorient an image using AFNI 3dresample command
285285
286286
For complete details, see the `3dresample Documentation.
@@ -534,7 +534,7 @@ def _gen_filename(self, name):
534534

535535
_, base, _ = split_filename(
536536
getattr(self.inputs, trait_spec.name_source))
537-
return self._gen_fname(basename=base, prefix=prefix, suffix=suffix, cwd='')
537+
return self._gen_fname(basename=base, prefix=prefix, suffix=suffix, cwd=os.getcwd())
538538
elif name == "brain_file" and isdefined(self.inputs.apply_suffix):
539539
suffix = ''
540540
prefix = ''
@@ -543,7 +543,7 @@ def _gen_filename(self, name):
543543

544544
_, base, _ = split_filename(
545545
getattr(self.inputs, trait_spec.name_source))
546-
return self._gen_fname(basename=base, prefix=prefix, suffix=suffix, cwd='')
546+
return self._gen_fname(basename=base, prefix=prefix, suffix=suffix, cwd=os.getcwd())
547547
elif name == "apply_mask" and isdefined(self.inputs.apply_suffix):
548548
suffix = ''
549549
prefix = ''
@@ -552,9 +552,10 @@ def _gen_filename(self, name):
552552

553553
_, base, _ = split_filename(
554554
getattr(self.inputs, trait_spec.name_source))
555-
return self._gen_fname(basename=base, prefix=prefix, suffix=suffix, cwd='')
556-
else:
557-
return super(AFNICommand, self)._gen_filename(name)
555+
return self._gen_fname(basename=base, prefix=prefix, suffix=suffix, cwd=os.getcwd())
556+
elif hasattr(self.inputs,name) and isdefined(getattr(self.inputs,name)):
557+
return super(Automask, self)._gen_filename(name)
558+
return Undefined
558559

559560
def _list_outputs(self):
560561
outputs = super(Automask, self)._list_outputs()

nipype/interfaces/ants/legacy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,15 @@ class buildtemplateparallel(ANTSCommand):
205205
def _format_arg(self, opt, spec, val):
206206
if opt == 'num_cores':
207207
if self.inputs.parallelization == 2:
208-
return '-j ' + val
208+
return '-j ' + str(val)
209209
else:
210210
return ''
211211
if opt == 'in_files':
212212
if self.inputs.use_first_as_target:
213213
start = '-z '
214214
else:
215215
start = ''
216-
return start + ' '.join([os.path.split(name)[1] for name in val])
216+
return start + ' '.join(name for name in val)
217217
return super(buildtemplateparallel, self)._format_arg(opt, spec, val)
218218

219219
def _list_outputs(self):

nipype/interfaces/ants/registration.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,16 @@ class RegistrationInputSpec(ANTSCommandInputSpec):
264264

265265
class RegistrationOutputSpec(TraitedSpec):
266266
forward_transforms = traits.List(
267-
File(), desc='List of output transforms for forward registration')
267+
File(exists=True), desc='List of output transforms for forward registration')
268268
reverse_transforms = traits.List(
269-
File(), desc='List of output transforms for reverse registration')
269+
File(exists=True), desc='List of output transforms for reverse registration')
270270
forward_invert_flags = traits.List(traits.Bool(
271271
), desc='List of flags corresponding to the forward transforms')
272272
reverse_invert_flags = traits.List(traits.Bool(
273273
), desc='List of flags corresponding to the reverse transforms')
274-
composite_transform = traits.List(File(), desc='Composite transform file')
274+
composite_transform = traits.List(File(exists=True), desc='Composite transform file')
275275
inverse_composite_transform = traits.List(
276-
File(), desc='Inverse composite transform file')
276+
File(exists=True), desc='Inverse composite transform file')
277277

278278

279279
class Registration(ANTSCommand):
@@ -336,7 +336,6 @@ class Registration(ANTSCommand):
336336
_cmd = 'antsRegistration'
337337
input_spec = RegistrationInputSpec
338338
output_spec = RegistrationOutputSpec
339-
_numberOfOutputTransforms = 0
340339
_quantilesDone = False
341340

342341
def _optionalMetricParameters(self, index):
@@ -419,10 +418,6 @@ def _format_arg(self, opt, spec, val):
419418
if opt == 'moving_image_mask':
420419
return '--masks [ %s, %s ]' % (self.inputs.fixed_image_mask, self.inputs.moving_image_mask)
421420
elif opt == 'transforms':
422-
if self.inputs.collapse_output_transforms:
423-
self._numberOfOutputTransforms = 2 # Affine and displacement
424-
else:
425-
self._numberOfOutputTransforms = len(self.inputs.transforms)
426421
return self._formatRegistration()
427422
elif opt == 'initial_moving_transform':
428423
if self.inputs.invert_initial_moving_transform:
@@ -449,7 +444,8 @@ def _format_arg(self, opt, spec, val):
449444

450445
def _outputFileNames(self, prefix, count, transform, inverse=False):
451446
self.lowDimensionalTransformMap = {'Rigid': 'Rigid.mat',
452-
'Affine': 'Affine.mat',
447+
#seems counterontuitive, but his is how ANTS is calling it
448+
'Affine': 'GenericAffine.mat',
453449
'GenericAffine': 'GenericAffine.mat',
454450
'CompositeAffine': 'Affine.mat',
455451
'Similarity': 'Similarity.mat',
@@ -473,6 +469,7 @@ def _list_outputs(self):
473469
outputs['reverse_transforms'] = []
474470
outputs['reverse_invert_flags'] = []
475471
if not self.inputs.collapse_output_transforms:
472+
transformCount = 0
476473
if isdefined(self.inputs.initial_moving_transform):
477474
outputs['forward_transforms'].append(
478475
self.inputs.initial_moving_transform)
@@ -481,20 +478,21 @@ def _list_outputs(self):
481478
outputs['reverse_transforms'].insert(
482479
0, self.inputs.initial_moving_transform)
483480
outputs['reverse_invert_flags'].insert(0, not self.inputs.invert_initial_moving_transform) # Prepend
484-
transformCount = 1
485-
for count in range(self._numberOfOutputTransforms):
486-
forwardFileName, forwardInverseMode = self._outputFileNames(self.inputs.output_transform_prefix, transformCount,
487-
self.inputs.transforms[count])
488-
reverseFileName, reverseInverseMode = self._outputFileNames(self.inputs.output_transform_prefix, transformCount,
489-
self.inputs.transforms[count], True)
490-
outputs['forward_transforms'].append(
491-
os.path.abspath(forwardFileName))
492-
outputs['forward_invert_flags'].append(forwardInverseMode)
493-
outputs['reverse_transforms'].insert(
494-
0, os.path.abspath(reverseFileName))
495-
outputs[
496-
'reverse_invert_flags'].insert(0, reverseInverseMode)
497-
transformCount += 1
481+
transformCount += 1
482+
483+
for count in range(len(self.inputs.transforms)):
484+
forwardFileName, forwardInverseMode = self._outputFileNames(self.inputs.output_transform_prefix, transformCount,
485+
self.inputs.transforms[count])
486+
reverseFileName, reverseInverseMode = self._outputFileNames(self.inputs.output_transform_prefix, transformCount,
487+
self.inputs.transforms[count], True)
488+
outputs['forward_transforms'].append(
489+
os.path.abspath(forwardFileName))
490+
outputs['forward_invert_flags'].append(forwardInverseMode)
491+
outputs['reverse_transforms'].insert(
492+
0, os.path.abspath(reverseFileName))
493+
outputs[
494+
'reverse_invert_flags'].insert(0, reverseInverseMode)
495+
transformCount += 1
498496
else:
499497
transformCount = 0
500498
for transform in ['GenericAffine', 'SyN']: # Only files returned by collapse_output_transforms

nipype/interfaces/ants/segmentation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class N4BiasFieldCorrectionInputSpec(ANTSCommandInputSpec):
162162
input_image = File(argstr='--input-image %s', mandatory=True,
163163
desc=('image to apply transformation to (generally a '
164164
'coregistered functional)'))
165+
mask_image = File(argstr='--mask-image %s')
165166
output_image = traits.Str(argstr='--output %s',
166167
desc=('output file name'), genfile=True,
167168
hash_file=False)

nipype/interfaces/dcmstack.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,16 @@ class NiftiGeneratorBaseInputSpec(TraitedSpec):
5050
class NiftiGeneratorBase(BaseInterface):
5151
'''Base class for interfaces that produce Nifti files, potentially with
5252
embeded meta data.'''
53-
def _get_out_path(self, meta):
53+
def _get_out_path(self, meta, idx=None):
5454
'''Return the output path for the gernerated Nifti.'''
5555
if self.inputs.out_format:
5656
out_fmt = self.inputs.out_format
5757
else:
5858
#If no out_format is specified, use a sane default that will work
5959
#with the provided meta data.
6060
out_fmt = []
61+
if not idx is None:
62+
out_fmt.append('%03d' % idx)
6163
if 'SeriesNumber' in meta:
6264
out_fmt.append('%(SeriesNumber)03d')
6365
if 'ProtocolName' in meta:
@@ -259,7 +261,8 @@ class CopyMeta(BaseInterface):
259261
output_spec = CopyMetaOutputSpec
260262

261263
def _run_interface(self, runtime):
262-
src = NiftiWrapper.from_filename(self.inputs.src_file)
264+
src_nii = nb.load(self.inputs.src_file)
265+
src = NiftiWrapper(src_nii, make_empty=True)
263266
dest_nii = nb.load(self.inputs.dest_file)
264267
dest = NiftiWrapper(dest_nii, make_empty=True)
265268
classes = src.meta_ext.get_valid_classes()
@@ -371,9 +374,9 @@ def _run_interface(self, runtime):
371374
split_dim = None
372375
else:
373376
split_dim = self.inputs.split_dim
374-
for split_nw in nw.split(split_dim):
377+
for split_idx, split_nw in enumerate(nw.split(split_dim)):
375378
const_meta = split_nw.meta_ext.get_class_dict(('global', 'const'))
376-
out_path = self._get_out_path(const_meta)
379+
out_path = self._get_out_path(const_meta, idx=split_idx)
377380
nb.save(split_nw.nii_img, out_path)
378381
self.out_list.append(out_path)
379382

nipype/interfaces/freesurfer/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ def _list_outputs(self):
417417
suffix="_masked",
418418
newpath=os.getcwd(),
419419
use_ext=True)
420+
else:
421+
outputs["out_file"] = os.path.abspath(outputs["out_file"])
420422
return outputs
421423

422424
def _gen_filename(self, name):

0 commit comments

Comments
 (0)