Skip to content

Commit 6da1996

Browse files
committed
Merge remote-tracking branch 'upstream/master' into enh/vagrant
* upstream/master: (22 commits) Reformated inputs and added tests fix: fixed autotest for applytopup Fixed file extension Fixed test files import. FIX: topup out file and params fixed possible values for -datatype parameter of tracks2prob interface. Previous values were in error. correct values obtained from: http://www.brain.org.au/software/mrtrix/general/formats.html#datatypes fix: construct sparse matrix using topological sort order autogenerated tests added dummy files for testing new mrtrix interfaces updated CHANGES log Updated new mrtrix interfaces to new out_file format Added GenerateDirections, FindShPeaks, Directions2Amplitude interfaces wrapping gendir, find_SH_peaks and dir2amp mrtrix commands. Removed ipdb trace Fixing path issues for CMTK Parcellate dilated ROI files tst: auto test generation for FUGUE fix: warp/unwarp arg parsing for use w/o an in_file fix: typo in fugue parameter add: pycharm .idea/ directory to .gitignore fixed errors from DOCTEST, now OK. fixed pull request issues: wrapping Surface2VolTransform, -moved from preprocess.py to utils.py -improved input descriptions -renamed output suffix ...
2 parents 277f012 + 496ec95 commit 6da1996

24 files changed

+489
-61
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
.project
1313
.settings
1414
.pydevproject
15+
.idea/

CHANGES

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Next release
88
* ENH: Added support for Simple Linux Utility Resource Management (SLURM)
99
* ENH: AFNI interfaces refactor, prefix, suffix are replaced by "flexible_%s_templates"
1010
* ENH: DataGrabber and SelectFiles use human (or natural) sort now
11-
1211
* ENH: Several new interfaces related to Camino were added:
1312
- camino.SFPICOCalibData
1413
- camino.Conmat
@@ -17,6 +16,10 @@ Next release
1716
- camino.SFPeaks
1817
One outdated interface no longer part of Camino was removed:
1918
- camino.Conmap
19+
* ENH: Three new mrtrix interfaces were added:
20+
- mrtrix.GenerateDirections
21+
- mrtrix.FindShPeaks
22+
- mrtrix.Directions2Amplitude
2023

2124
* FIX: Several fixes related to Camino interfaces:
2225
- ProcStreamlines would ignore many arguments silently (target, waypoint, exclusion ROIS, etc.)

nipype/interfaces/afni/preprocess.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ class AutoTcorrelateInputSpec(AFNICommandInputSpec):
330330
mask_only_targets = traits.Bool(desc="use mask only on targets voxels",
331331
argstr="-mask_only_targets",
332332
xor=['mask_source'])
333-
334333
mask_source = File(exists=True,
335334
desc="mask for source voxels",
336335
argstr="-mask_source %s",

nipype/interfaces/cmtk/parcellation.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def create_roi(subject_id, subjects_dir, fs_dir, parcellation_name, dilation):
258258
rois[idx] = int(brv['dn_correspondence_id'])
259259

260260
# store volume eg in ROI_scale33.nii.gz
261-
out_roi = op.join(output_dir, 'ROI_%s.nii.gz' % parcellation_name)
261+
out_roi = op.abspath('ROI_%s.nii.gz' % parcellation_name)
262262

263263
# update the header
264264
hdr = aseg.get_header()
@@ -290,7 +290,7 @@ def create_roi(subject_id, subjects_dir, fs_dir, parcellation_name, dilation):
290290
rois[xx[j], yy[j], zz[j]] = value
291291

292292
# store volume eg in ROIv_scale33.nii.gz
293-
out_roi = op.join(output_dir, 'ROIv_%s.nii.gz' % parcellation_name)
293+
out_roi = op.abspath('ROIv_%s.nii.gz' % parcellation_name)
294294
iflogger.info("Save output image to %s" % out_roi)
295295
img = nb.Nifti1Image(rois, aseg.get_affine(), hdr2)
296296
nb.save(img, out_roi)
@@ -303,7 +303,6 @@ def create_wm_mask(subject_id, subjects_dir, fs_dir, parcellation_name):
303303
fs_dir = op.join(subjects_dir, subject_id)
304304
cmp_config = cmp.configuration.PipelineConfiguration()
305305
cmp_config.parcellation_scheme = "Lausanne2008"
306-
log = cmp_config.get_logger()
307306
pgpath = cmp_config._get_lausanne_parcellation(
308307
'Lausanne2008')[parcellation_name]['node_information_graphml']
309308
# load ribbon as basis for white matter mask
@@ -422,8 +421,6 @@ def create_wm_mask(subject_id, subjects_dir, fs_dir, parcellation_name):
422421
wmmask[idx] = 1
423422

424423
# check if we should subtract the cortical rois from this parcellation
425-
parval = cmp_config._get_lausanne_parcellation(
426-
'Lausanne2008')[parcellation_name]
427424
iflogger.info("Loading %s to subtract cortical ROIs from white matter mask" % ('ROI_%s.nii.gz' % parcellation_name))
428425
roi = nb.load(op.join(op.curdir, 'ROI_%s.nii.gz' % parcellation_name))
429426
roid = roi.get_data()
@@ -448,28 +445,25 @@ def crop_and_move_datasets(subject_id, subjects_dir, fs_dir, parcellation_name,
448445
cmp_config = cmp.configuration.PipelineConfiguration()
449446
cmp_config.parcellation_scheme = "Lausanne2008"
450447
log = cmp_config.get_logger()
451-
pgpath = cmp_config._get_lausanne_parcellation(
452-
'Lausanne2008')[parcellation_name]['node_information_graphml']
453-
reg_path = out_roi_file
454448
output_dir = op.abspath(op.curdir)
455449

456450
iflogger.info("Cropping and moving datasets to %s" % output_dir)
457451
ds = [
458-
(op.join(fs_dir, 'mri', 'aseg.nii.gz'), op.join(
459-
output_dir, 'aseg.nii.gz')),
460-
(op.join(fs_dir, 'mri', 'ribbon.nii.gz'), op.join(
461-
output_dir, 'ribbon.nii.gz')),
462-
(op.join(fs_dir, 'mri', 'fsmask_1mm.nii.gz'), op.join(
463-
output_dir, 'fsmask_1mm.nii.gz')),
452+
(op.join(fs_dir, 'mri', 'aseg.nii.gz'),
453+
op.abspath('aseg.nii.gz')),
454+
(op.join(fs_dir, 'mri', 'ribbon.nii.gz'),
455+
op.abspath('ribbon.nii.gz')),
456+
(op.join(fs_dir, 'mri', 'fsmask_1mm.nii.gz'),
457+
op.abspath('fsmask_1mm.nii.gz')),
464458
(op.join(fs_dir, 'label', 'cc_unknown.nii.gz'),
465-
op.join(output_dir, 'cc_unknown.nii.gz'))
459+
op.abspath('cc_unknown.nii.gz'))
466460
]
467461

468-
ds.append((op.join(op.curdir, 'ROI_%s.nii.gz' % parcellation_name),
469-
op.join(op.curdir, 'ROI_HR_th.nii.gz')))
462+
ds.append((op.abspath('ROI_%s.nii.gz' % parcellation_name),
463+
op.abspath('ROI_HR_th.nii.gz')))
470464
if(dilation==True):
471-
ds.append((op.join(op.curdir, 'ROIv_%s.nii.gz' %
472-
parcellation_name), op.join(op.curdir, 'ROIv_HR_th.nii.gz')))
465+
ds.append((op.abspath('ROIv_%s.nii.gz' % parcellation_name),
466+
op.abspath('ROIv_HR_th.nii.gz')))
473467
orig = op.join(fs_dir, 'mri', 'orig', '001.mgz')
474468
for d in ds:
475469
iflogger.info("Processing %s:" % d[0])

nipype/interfaces/freesurfer/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
from .base import Info, FSCommand
66
from .preprocess import (ParseDICOMDir, UnpackSDICOMDir, MRIConvert, Resample,
7-
ReconAll, BBRegister, ApplyVolTransform, Smooth,
7+
ReconAll, BBRegister, ApplyVolTransform,Smooth,
88
DICOMConvert, RobustRegister, FitMSParams,
99
SynthesizeFLASH)
1010
from .model import (MRISPreproc, GLMFit, OneSampleTTest, Binarize, Concatenate,
1111
SegStats, Label2Vol, MS_LDA)
12-
from .utils import (SampleToSurface, SurfaceSmooth, SurfaceTransform,
12+
from .utils import (SampleToSurface, SurfaceSmooth, SurfaceTransform, Surface2VolTransform,
1313
SurfaceSnapshots,ApplyMask, MRIsConvert, MRITessellate,
1414
MRIMarchingCubes, SmoothTessellation, MakeAverageSubject,
1515
ExtractMainComponent)

nipype/interfaces/freesurfer/preprocess.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,6 @@ class ApplyVolTransformInputSpec(FSTraitedSpec):
970970
'non-linear morph to resample the input '
971971
'volume. To be used by --m3z.'))
972972

973-
974973
class ApplyVolTransformOutputSpec(TraitedSpec):
975974
transformed_file = File(exists=True, desc='Path to output file if used normally')
976975

@@ -1021,7 +1020,6 @@ def _gen_filename(self, name):
10211020
return self._get_outfile()
10221021
return None
10231022

1024-
10251023
class SmoothInputSpec(FSTraitedSpec):
10261024
in_file = File(exists=True, desc='source volume',
10271025
argstr='--i %s', mandatory=True)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from nipype.testing import assert_equal
3+
from nipype.interfaces.freesurfer.utils import Surface2VolTransform
4+
def test_Surface2VolTransform_inputs():
5+
input_map = dict(ignore_exception=dict(nohash=True,
6+
usedefault=True,
7+
),
8+
transformed_file=dict(name_source=['source_file'],
9+
hash_files=False,
10+
name_template='%s_asVol.nii',
11+
argstr='--outvol %s',
12+
),
13+
hemi=dict(mandatory=True,
14+
argstr='--hemi %s',
15+
),
16+
template_file=dict(argstr='--template %s',
17+
),
18+
subject_id=dict(xor=['reg_file'],
19+
argstr='--identity %s',
20+
),
21+
args=dict(argstr='%s',
22+
),
23+
surf_name=dict(argstr='--surf %s',
24+
exists=True,
25+
),
26+
vertexvol_file=dict(name_source=['source_file'],
27+
hash_files=False,
28+
name_template='%s_asVol_vertex.nii',
29+
argstr='--vtxvol %s',
30+
),
31+
reg_file=dict(mandatory=True,
32+
argstr='--volreg %s',
33+
xor=['subject_id'],
34+
),
35+
environ=dict(nohash=True,
36+
usedefault=True,
37+
),
38+
subjects_dir=dict(argstr='--sd %s',
39+
),
40+
source_file=dict(copyfile=False,
41+
mandatory=True,
42+
argstr='--surfval %s',
43+
),
44+
projfrac=dict(argstr='--projfrac %s',
45+
exists=True,
46+
),
47+
mkmask=dict(argstr='--mkmask',
48+
),
49+
terminal_output=dict(mandatory=True,
50+
nohash=True,
51+
),
52+
)
53+
inputs = Surface2VolTransform.input_spec()
54+
55+
for key, metadata in input_map.items():
56+
for metakey, value in metadata.items():
57+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
58+
def test_Surface2VolTransform_outputs():
59+
output_map = dict(transformed_file=dict(),
60+
vertexvol_file=dict(),
61+
)
62+
outputs = Surface2VolTransform.output_spec()
63+
64+
for key, metadata in output_map.items():
65+
for metakey, value in metadata.items():
66+
yield assert_equal, getattr(outputs.traits()[key], metakey), value

nipype/interfaces/freesurfer/utils.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,55 @@ def _gen_filename(self, name):
382382
return self._list_outputs()[name]
383383
return None
384384

385+
class Surface2VolTransformInputSpec(FSTraitedSpec):
386+
source_file = File(exists=True, argstr='--surfval %s',
387+
copyfile=False, mandatory=True,
388+
desc='This is the source of the surface values')
389+
hemi = traits.Str(argstr='--hemi %s', mandatory=True, desc='hemisphere of data')
390+
transformed_file = File(name_template="%s_asVol.nii", desc='Output volume', argstr='--outvol %s',
391+
name_source=['source_file'], hash_files=False)
392+
reg_file = File(exists=True, argstr='--volreg %s',
393+
mandatory=True,
394+
desc='tkRAS-to-tkRAS matrix (tkregister2 format)',
395+
xor=['subject_id'])
396+
template_file = File(exists=True, argstr='--template %s',
397+
desc='Output template volume')
398+
mkmask = traits.Bool(desc='make a mask instead of loading surface values', argstr='--mkmask')
399+
vertexvol_file = File(name_template="%s_asVol_vertex.nii", desc='Path name of the vertex output '
400+
'volume, which is the same as output volume except that the value of each '
401+
'voxel is the vertex-id that is mapped to that voxel.',
402+
argstr='--vtxvol %s', name_source=['source_file'], hash_files=False)
403+
surf_name = traits.Str(exists=True, argstr='--surf %s',desc='surfname (default is white)')
404+
projfrac = traits.Float(exists=True, argstr='--projfrac %s',desc='thickness fraction')
405+
subjects_dir = traits.Str(argstr='--sd %s',desc='freesurfer subjects directory defaults to $SUBJECTS_DIR')
406+
subject_id = traits.Str(argstr='--identity %s',desc='subject id', xor=['reg_file'])
407+
408+
class Surface2VolTransformOutputSpec(TraitedSpec):
409+
transformed_file = File(exists=True, desc='Path to output file if used normally')
410+
vertexvol_file = File(desc='vertex map volume path id. Optional')
411+
412+
class Surface2VolTransform(FSCommand):
413+
"""Use FreeSurfer mri_surf2vol to apply a transform.
414+
415+
Examples
416+
--------
417+
418+
>>> from nipype.interfaces.freesurfer import Surface2VolTransform
419+
>>> xfm2vol = Surface2VolTransform()
420+
>>> xfm2vol.inputs.source_file = 'lh.cope1.mgz'
421+
>>> xfm2vol.inputs.reg_file = 'register.mat'
422+
>>> xfm2vol.inputs.hemi = 'lh'
423+
>>> xfm2vol.inputs.template_file = 'cope1.nii.gz'
424+
>>> xfm2vol.inputs.subjects_dir = '.'
425+
>>> xfm2vol.cmdline
426+
'mri_surf2vol --hemi lh --volreg register.mat --surfval lh.cope1.mgz --sd . --template cope1.nii.gz --outvol lh.cope1_asVol.nii --vtxvol lh.cope1_asVol_vertex.nii'
427+
>>> res = xfm2vol.run()# doctest: +SKIP
428+
429+
"""
430+
431+
_cmd = 'mri_surf2vol'
432+
input_spec = Surface2VolTransformInputSpec
433+
output_spec = Surface2VolTransformOutputSpec
385434

386435
class ApplyMaskInputSpec(FSTraitedSpec):
387436

nipype/interfaces/fsl/epi.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ def _parse_inputs( self, skip=None ):
169169
skip = []
170170

171171
if not isdefined(self.inputs.out_base ):
172-
self.inputs.out_base = os.path.abspath( './nipypetu' )
172+
self.inputs.out_base = './nipypetu'
173+
174+
self.inputs.out_base = os.path.abspath(self.inputs.out_base)
173175

174176
if isdefined( self.inputs.encoding_file ):
175177
skip.append( 'encoding_direction' )
@@ -238,8 +240,8 @@ class ApplyTOPUPInputSpec( FSLCommandInputSpec ):
238240
in_topup = File( mandatory=True, desc='basename of field/movements (from topup)', argstr='--topup=%s' )
239241

240242
out_base = File( desc='basename for output (warped) image', argstr='--out=%s' )
241-
method = traits.Enum( ('jac','lsr'), argstr='-m=%s', desc='use jacobian modulation (jac) or least-squares resampling (lsr)' )
242-
interp = traits.Enum( ('trilinear','spline'), argstr='-n=%s', desc='interpolation method' )
243+
method = traits.Enum( ('jac','lsr'), argstr='--method=%s', desc='use jacobian modulation (jac) or least-squares resampling (lsr)' )
244+
interp = traits.Enum( ('trilinear','spline'), argstr='--interp=%s', desc='interpolation method' )
243245
datatype = traits.Enum( ('char', 'short', 'int', 'float', 'double' ), argstr='-d=%s', desc='force output data type' )
244246

245247

@@ -289,7 +291,9 @@ def _parse_inputs( self, skip=None ):
289291
skip = []
290292

291293
if not isdefined(self.inputs.out_base ):
292-
self.inputs.out_base = os.path.abspath( './nipypeatu' )
294+
self.inputs.out_base = './nipypeatu'
295+
296+
self.inputs.out_base = os.path.abspath(self.inputs.out_base)
293297
return super(ApplyTOPUP, self)._parse_inputs(skip=skip)
294298

295299

nipype/interfaces/fsl/preprocess.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ class FUGUEInputSpec(FSLCommandInputSpec):
11971197
desc='apply Fourier (sinusoidal) fitting of order N')
11981198
pava = traits.Bool(argstr='--pava',
11991199
desc='apply monotonic enforcement via PAVA')
1200-
despike_theshold = traits.Float(argstr='--despikethreshold=%s',
1200+
despike_threshold = traits.Float(argstr='--despikethreshold=%s',
12011201
desc='specify the threshold for de-spiking (default=3.0)')
12021202
unwarp_direction = traits.Enum('x', 'y', 'z', 'x-', 'y-', 'z-',
12031203
argstr='--unwarpdir=%s',
@@ -1287,13 +1287,13 @@ def _parse_inputs(self, skip=None):
12871287
self.inputs.shift_out_file = self._gen_fname(
12881288
self.inputs.in_file, suffix='_vsm')
12891289

1290-
if self.inputs.forward_warping or not isdefined(self.inputs.in_file):
1291-
skip += ['unwarped_file']
1290+
if not isdefined(self.inputs.in_file):
1291+
skip += ['unwarped_file', 'warped_file']
1292+
elif self.inputs.forward_warping:
12921293
if not isdefined(self.inputs.warped_file):
12931294
self.inputs.warped_file = self._gen_fname(
12941295
self.inputs.in_file, suffix='_warped')
1295-
if not self.inputs.forward_warping or not isdefined(self.inputs.in_file):
1296-
skip += ['warped_file']
1296+
elif not self.inputs.forward_warping:
12971297
if not isdefined(self.inputs.unwarped_file):
12981298
self.inputs.unwarped_file = self._gen_fname(
12991299
self.inputs.in_file, suffix='_unwarped')

0 commit comments

Comments
 (0)