Skip to content

Commit 312cd57

Browse files
author
bpinsard
committed
add an example
2 parents e2c30ae + ef9122e commit 312cd57

File tree

12 files changed

+318
-79
lines changed

12 files changed

+318
-79
lines changed

CHANGES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Next release
22
============
3-
* ENH: New interfaces: nipy.Trim
3+
* ENH: New interfaces: nipy.Trim, fsl.GLM, fsl.SigLoss
44

55
* ENH: Allow control over terminal output for commandline interfaces
66
* ENH: New workflows for dMRI and fMRI pre-processing: added motion artifact correction

nipype/interfaces/afni/preprocess.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,13 @@ class AutoTcorrelateInputSpec(AFNICommandInputSpec):
320320
mask = File(exists=True, desc="mask of voxels",
321321
argstr="-mask %s")
322322
mask_only_targets = traits.Bool(desc="use mask only on targets voxels",
323-
argstr="-mask_only_targets")
323+
argstr="-mask_only_targets",
324+
xor=['mask_source'])
325+
326+
mask_source = File(exists=True,
327+
desc="mask for source voxels",
328+
argstr="-mask_source %s",
329+
xor=['mask_only_targets'])
324330

325331
out_file = File("%s_similarity_matrix.1D", desc='output image file name',
326332
argstr='-prefix %s', name_source="in_file", usedefault=True)

nipype/interfaces/afni/tests/test_preprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_allineate():
1818
environ = dict(usedefault=True,),
1919
ignore_exception = dict(usedefault=True,),
2020
in_file = dict(argstr='-source %s',mandatory=True,),
21-
matrix = dict(argstr='-1dmatrix_apply %s',),
21+
in_matrix = dict(argstr='-1Dmatrix_apply %s',),
2222
out_file = dict(argstr='-prefix %s'),
2323
outputtype = dict(),
2424
)

nipype/interfaces/fsl/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
SliceTimer, SUSAN, PRELUDE, FUGUE, FIRST)
1212
from .model import (Level1Design, FEAT, FEATModel, FILMGLS, FEATRegister,
1313
FLAMEO, ContrastMgr, MultipleRegressDesign, L2Model, SMM,
14-
MELODIC, SmoothEstimate, Cluster, Randomise)
14+
MELODIC, SmoothEstimate, Cluster, Randomise, GLM)
1515
from .utils import (Smooth, Merge, ExtractROI, Split, ImageMaths, ImageMeants,
1616
ImageStats, FilterRegressor, Overlay, Slicer,
1717
PlotTimeSeries, PlotMotionParams, ConvertXFM,
18-
SwapDimensions, PowerSpectrum, Reorient2Std)
18+
SwapDimensions, PowerSpectrum, SigLoss, Reorient2Std,
19+
Complex)
1920
from .dti import (EddyCorrect, BEDPOSTX, DTIFit, ProbTrackX, VecReg, ProjThresh,
2021
FindTheBiggest, DistanceMap, TractSkeleton, XFibres,
2122
MakeDyadicVectors)

nipype/interfaces/fsl/model.py

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818

1919
import numpy as np
2020

21-
from nipype.interfaces.fsl.base import (FSLCommand, FSLCommandInputSpec)
21+
from nipype.interfaces.fsl.base import (FSLCommand, FSLCommandInputSpec, Info)
2222
from nipype.interfaces.base import (load_template, File, traits, isdefined,
2323
TraitedSpec, BaseInterface, Directory,
2424
InputMultiPath, OutputMultiPath,
2525
BaseInterfaceInputSpec)
26-
from nipype.utils.filemanip import (list_to_filename, filename_to_list)
26+
from nipype.utils.filemanip import (list_to_filename, filename_to_list, split_filename)
2727
from nibabel import load
2828

2929
warn = warnings.warn
@@ -1511,3 +1511,66 @@ def _list_outputs(self):
15111511
outputs['f_corrected_p_files'] = glob(self._gen_fname(\
15121512
'%s_%s_corrp_fstat*.nii' % (self.inputs.base_name, prefix)))
15131513
return outputs
1514+
1515+
1516+
class GLMInputSpec(FSLCommandInputSpec):
1517+
in_file = File(
1518+
exists=True,mandatory=True,
1519+
argstr='-i %s',
1520+
desc='input 3d+t file',)
1521+
design = File(
1522+
exists=True, mandatory=True,
1523+
argstr='-d %s',
1524+
desc='design file or image file')
1525+
out_file = File(
1526+
genfile=True, argstr="-o %s",
1527+
desc="file or image output")
1528+
mask = File(
1529+
exists=True,
1530+
argstr='-m %s',
1531+
desc='mask file')
1532+
contrasts = File(
1533+
exists=True,
1534+
argstr='-c %s',
1535+
desc='t-contrasts file')
1536+
options = traits.String(
1537+
argstr='%s',
1538+
desc = 'fsl_glm options')
1539+
class GLMOutputSpec(TraitedSpec):
1540+
out_file = File(
1541+
exists=True,
1542+
desc = 'file or image output')
1543+
1544+
class GLM(FSLCommand):
1545+
"""
1546+
FSL GLM:
1547+
1548+
Example
1549+
-------
1550+
>>> import nipype.interfaces.fsl as fsl
1551+
>>> glm = fsl.GLM(in_file='functional.nii', design = 'maps.nii')
1552+
>>> glm.cmdline
1553+
"""
1554+
_cmd = 'fsl_glm'
1555+
input_spec = GLMInputSpec
1556+
output_spec = GLMOutputSpec
1557+
1558+
def _list_outputs(self):
1559+
outputs = self.output_spec().get()
1560+
outputs['out_file'] = self.inputs.out_file
1561+
# Generate an out_file if one is not provided
1562+
if not isdefined(outputs['out_file']) and isdefined(self.inputs.in_file):
1563+
ext = Info.output_type_to_ext(self.inputs.output_type)
1564+
if split_filename(self.inputs.in_file)[-1] in Info.ftypes.values():
1565+
ext = '.txt'
1566+
outputs['out_file'] = self._gen_fname(self.inputs.in_file,
1567+
suffix='_glm',
1568+
ext=ext)
1569+
1570+
return outputs
1571+
1572+
def _gen_filename(self, name):
1573+
if name in ('out_file'):
1574+
return self._list_outputs()[name]
1575+
else:
1576+
return None

nipype/interfaces/fsl/preprocess.py

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,14 +1188,15 @@ def _gen_filename(self, name):
11881188
class FUGUEInputSpec(FSLCommandInputSpec):
11891189
in_file = File(exists=True, argstr='--in=%s',
11901190
desc='filename of input volume')
1191-
unwarped_file = File(argstr='--unwarp=%s', genfile=True,
1192-
desc='apply unwarping and save as filename', hash_files=False)
1193-
1194-
save_warped = traits.Bool(desc='apply forward warp and save')
1195-
1196-
warped_file = File(argstr='--warp=%s', genfile=True,
1197-
desc='apply forward warp and save as filename', hash_files=False)
1198-
1191+
unwarped_file = File(
1192+
argstr='--unwarp=%s', genfile=True,
1193+
desc='apply unwarping and save as filename', hash_files=False)
1194+
forward_warping = traits.Bool(
1195+
False, usedefault=True,
1196+
desc='apply forward warping instead of unwarping')
1197+
warped_file = File(argstr='--warp=%s',
1198+
desc='apply forward warping and save as filename',
1199+
hash_files=False)
11991200
phasemap_file = File(exists=True, argstr='--phasemap=%s',
12001201
desc='filename for input phase image')
12011202
dwell_to_asym_ratio = traits.Float(argstr='--dwelltoasym=%.10f',
@@ -1211,7 +1212,7 @@ class FUGUEInputSpec(FSLCommandInputSpec):
12111212

12121213
save_shift = traits.Bool(desc='output pixel shift volume')
12131214

1214-
shift_out_file = traits.File(argstr='--saveshift=%s', genfile=True,
1215+
shift_out_file = traits.File(argstr='--saveshift=%s',
12151216
desc='filename for saving pixel shift volume', hash_files=False)
12161217

12171218
shift_in_file = File(exists=True, argstr='--loadshift=%s',
@@ -1247,25 +1248,20 @@ class FUGUEInputSpec(FSLCommandInputSpec):
12471248
desc='apply intensity correction only')
12481249
mask_file = File(exists=True, argstr='--mask=%s',
12491250
desc='filename for loading valid mask')
1250-
save_unmasked_fmap = traits.Either(traits.Bool,
1251-
traits.File,
1252-
argstr='--unmaskfmap=%s',
1253-
requires=['fmap_out_file'],
1254-
desc='saves the unmasked fieldmap when using --savefmap', hash_files=False)
1255-
save_unmasked_shift = traits.Either(traits.Bool,
1256-
traits.File,
1257-
argstr='--unmaskshift=%s',
1258-
requires=['shift_out_file'],
1259-
desc='saves the unmasked shiftmap when using --saveshift', hash_files=False)
1260-
nokspace = traits.Bool(
1261-
argstr='--nokspace', desc='do not use k-space forward warping')
1251+
save_unmasked_fmap = traits.Bool(argstr='--unmaskfmap',
1252+
requires=['fmap_out_file'],
1253+
desc='saves the unmasked fieldmap when using --savefmap')
1254+
save_unmasked_shift = traits.Bool(argstr='--unmaskshift',
1255+
requires=['shift_out_file'],
1256+
desc='saves the unmasked shiftmap when using --saveshift')
1257+
nokspace = traits.Bool(argstr='--nokspace', desc='do not use k-space forward warping')
12621258

12631259

12641260
class FUGUEOutputSpec(TraitedSpec):
1265-
unwarped_file = File(exists=True, desc='unwarped file')
1261+
unwarped_file = File(desc='unwarped file')
1262+
warped_file = File(desc='forward warped file')
12661263
shift_out_file = File(desc='voxel shift map file')
1267-
warped_file = File(desc='warped file')
1268-
1264+
fmap_out_file = File(desc='fieldmap file')
12691265

12701266
class FUGUE(FSLCommand):
12711267
"""Use FSL FUGUE to unwarp epi's with fieldmaps
@@ -1299,43 +1295,40 @@ def _parse_inputs(self, skip=None):
12991295

13001296
def _list_outputs(self):
13011297
outputs = self._outputs().get()
1302-
out_file = self.inputs.unwarped_file
1303-
if not isdefined(out_file):
1304-
out_file = self._gen_fname(self.inputs.in_file,
1305-
suffix='_unwarped')
1306-
outputs['unwarped_file'] = os.path.abspath(out_file)
1307-
1308-
if isdefined(self.inputs.save_shift) and self.inputs.save_shift:
1309-
shift_out = self.inputs.shift_out_file
1310-
if not isdefined(shift_out):
1311-
shift_out = self._gen_fname(
1312-
self.inputs.in_file, suffix='_shift')
1298+
if self.inputs.forward_warping:
1299+
out_field = 'warped_file'
1300+
else:
1301+
out_field = 'unwarped_file'
13131302

1314-
outputs['shift_out_file'] = os.path.abspath(shift_out)
1315-
1316-
if isdefined(self.inputs.save_warped) and self.inputs.save_warped:
1317-
warped_out = self.inputs.warped_file
1318-
if not isdefined(warped_out):
1319-
warped_out = self._gen_fname(
1320-
self.inputs.in_file, suffix='_fwdwarp')
1321-
1322-
outputs['warped_file'] = os.path.abspath(warped_out)
1323-
del outputs['unwarped_file']
1303+
out_file = getattr(self.inputs,out_field)
1304+
if not isdefined(out_file):
1305+
if isdefined(self.inputs.in_file):
1306+
out_file = self._gen_fname(self.inputs.in_file,
1307+
suffix='_'+out_field[:-5])
1308+
if isdefined(out_file):
1309+
outputs[out_field] = os.path.abspath(out_file)
1310+
if isdefined(self.inputs.fmap_out_file):
1311+
outputs['fmap_out_file'] = os.path.abspath(self.inputs.fmap_out_file)
1312+
if isdefined(self.inputs.shift_out_file):
1313+
outputs['shift_out_file'] = os.path.abspath(self.inputs.shift_out_file)
13241314

13251315
return outputs
13261316

13271317
def _gen_filename(self, name):
1328-
if name == 'unwarped_file':
1318+
if name == 'unwarped_file' and not self.inputs.forward_warping:
13291319
return self._list_outputs()['unwarped_file']
1330-
1331-
if name == 'warped_file':
1320+
if name == 'warped_file' and self.inputs.forward_warping:
13321321
return self._list_outputs()['warped_file']
1333-
1334-
if name == 'shift_out_file':
1335-
return self._list_outputs()['shift_out_file']
1336-
13371322
return None
13381323

1324+
def _parse_inputs(self,skip=None):
1325+
if skip==None:
1326+
skip=[]
1327+
if self.inputs.forward_warping or not isdefined(self.inputs.in_file):
1328+
skip+=['unwarped_file']
1329+
if not self.inputs.forward_warping or not isdefined(self.inputs.in_file):
1330+
skip+=['warped_file']
1331+
return super(FUGUE,self)._parse_inputs(skip=skip)
13391332

13401333
class PRELUDEInputSpec(FSLCommandInputSpec):
13411334
complex_phase_file = File(exists=True, argstr='--complex=%s',

nipype/interfaces/fsl/tests/test_preprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,8 @@ def test_fugue():
503503
phase_conjugate = dict(argstr='--phaseconj',),
504504
phasemap_file = dict(argstr='--phasemap=%s',),
505505
poly_order = dict(argstr='--poly=%d',),
506-
save_unmasked_fmap = dict(requires=['fmap_out_file'],argstr='--unmaskfmap=%s',),
507-
save_unmasked_shift = dict(requires=['shift_out_file'],argstr='--unmaskshift=%s',),
506+
save_unmasked_fmap = dict(requires=['fmap_out_file'],argstr='--unmaskfmap',),
507+
save_unmasked_shift = dict(requires=['shift_out_file'],argstr='--unmaskshift',),
508508
shift_in_file = dict(argstr='--loadshift=%s',),
509509
shift_out_file = dict(argstr='--saveshift=%s',),
510510
smooth2d = dict(argstr='--smooth2=%.2f',),

0 commit comments

Comments
 (0)