From 0258fda1bc6738f874412b3035b2dad8d9528436 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Sun, 4 Mar 2018 12:02:22 +0000
Subject: [PATCH] fsl.utils.run.dryrun() calls will now return the command
 line.  Useful for testing. Tweaks to various wrapper functions. fslmaths
 returns results dict, rather than file name (for testing).

---
 fsl/utils/run.py         |  4 +++-
 fsl/wrappers/fslmaths.py |  2 +-
 fsl/wrappers/fugue.py    | 13 ++++++++++--
 fsl/wrappers/melodic.py  |  4 ++--
 fsl/wrappers/misc.py     | 44 +++++++++++++---------------------------
 5 files changed, 31 insertions(+), 36 deletions(-)

diff --git a/fsl/utils/run.py b/fsl/utils/run.py
index b4b46f24d..f3a07b38f 100644
--- a/fsl/utils/run.py
+++ b/fsl/utils/run.py
@@ -45,6 +45,8 @@ class FSLNotPresent(Exception):
 def dryrun(*args):
     """Context manager which causes all calls to :func:`run` to be logged but
     not executed. See the :data:`DRY_RUN` flag.
+
+    The returned standard output will be equal to ``' '.join(args)``.
     """
     global DRY_RUN
 
@@ -106,7 +108,7 @@ def run(*args, **kwargs):
         log.debug('run: {}'.format(' '.join(args)))
 
     if DRY_RUN:
-        stdout = '<dryrun>'
+        stdout = ' '.join(args)
         stderr = ''
     else:
         proc           = sp.Popen(args, stdout=sp.PIPE, stderr=sp.PIPE)
diff --git a/fsl/wrappers/fslmaths.py b/fsl/wrappers/fslmaths.py
index db5858f04..5fa790ab4 100644
--- a/fsl/wrappers/fslmaths.py
+++ b/fsl/wrappers/fslmaths.py
@@ -151,7 +151,7 @@ class fslmaths(object):
         # will only be one entry in
         # the result dict.
         if output is None: return list(result.values())[0]
-        else:              return output
+        else:              return result
 
     @wutils.fileOrImage()
     @wutils.fslwrapper
diff --git a/fsl/wrappers/fugue.py b/fsl/wrappers/fugue.py
index 19fdcf94b..ced52f226 100644
--- a/fsl/wrappers/fugue.py
+++ b/fsl/wrappers/fugue.py
@@ -17,9 +17,13 @@ from . import wrapperutils as wutils
 @wutils.fileOrImage('in', 'unwarp', 'warp', 'phasemap', 'savefmap',
                     'loadfmap', 'saveshift', 'loadshift', 'mask')
 @wutils.fslwrapper
-def fugue(**kwargs):
+def fugue(input=None, **kwargs):
     """Wrapper for the ``fugue`` command."""
 
+    argmap = {
+        'input' : 'in'
+    }
+
     valmap = {
         'dwelltoasym' : wutils.SHOW_IF_TRUE,
         'median'      : wutils.SHOW_IF_TRUE,
@@ -37,7 +41,12 @@ def fugue(**kwargs):
         'verbose'     : wutils.SHOW_IF_TRUE,
     }
 
-    cmd = ['fugue'] + wutils.applyArgStyle('--=',  valmap=valmap, **kwargs)
+    kwargs.update({'input' : input})
+
+    cmd = ['fugue'] + wutils.applyArgStyle('--=',
+                                           argmap=argmap,
+                                           valmap=valmap,
+                                           **kwargs)
 
     return cmd
 
diff --git a/fsl/wrappers/melodic.py b/fsl/wrappers/melodic.py
index d95b33fa5..e5ceb738b 100644
--- a/fsl/wrappers/melodic.py
+++ b/fsl/wrappers/melodic.py
@@ -52,7 +52,7 @@ def melodic(input, **kwargs):
 
     asrt.assertIsNifti(input)
 
-    cmd  = ['melodic', '--in', input]
+    cmd  = ['melodic', '--in={}'.format(input)]
     cmd += wutils.applyArgStyle('--=', valmap=valmap, **kwargs)
 
     return cmd
@@ -77,6 +77,6 @@ def fsl_regfilt(input, out, design, **kwargs):
             '--in={}'.format(input),
             '--out={}'.format(out),
             '--design={}'.format(design)]
-    cmd += wutils.applyArgStyle('--=', valmap=valmap, **kwargs)
+    cmd += wutils.applyArgStyle('--=', valsep=',', valmap=valmap, **kwargs)
 
     return cmd
diff --git a/fsl/wrappers/misc.py b/fsl/wrappers/misc.py
index 3b7a0615e..9c2188828 100644
--- a/fsl/wrappers/misc.py
+++ b/fsl/wrappers/misc.py
@@ -31,49 +31,33 @@ def fslreorient2std(input, output=None):
 
 @wutils.fileOrImage('input', 'output')
 @wutils.fslwrapper
-def fslroi(input, output, xmin=None, xsize=None, ymin=None, ysize=None,
-           zmin=None, zsize=None, tmin=None, tsize=None):
+def fslroi(input, output, *args):
     """Wrapper for the ``fslroi`` tool."""
-    assert ((tmin is not None and tsize is not None) or
-            (xmin is not None and xsize is not None and
-             ymin is not None and ysize is not None and
-             zmin is not None and zsize is not None)), \
-        "either time min/size or x/y/z min/size must be provided"
 
-    cmd = ['fslroi', input, output]
+    asrt.assertIsNifti(input)
 
-    if xmin is not None:
-        cmd += [str(v) for v in [xmin, xsize, ymin, ysize, zmin, zsize]]
-    if tmin is not None:
-        cmd += [str(tmin), str(tsize)]
+    cmd = ['fslroi', input, output] + [str(a) for a in args]
 
     return cmd
 
 
 @wutils.fileOrImage('input', 'input2')
 @wutils.fslwrapper
-def slicer(input, input2=None, label=None, lut=None, intensity=None,
-           edgethreshold=None, x=None, y=None, z=None):
+def slicer(input, input2=None, **kwargs):
     """Wrapper for the ``slicer`` command. """
 
-    cmd = "slicer {0}".format(input)
+    cmd = ['slicer', input]
 
     if input2 is not None:
-        cmd += " {0}".format(input2)
-    if label is not None:
-        cmd += " -L {0}".format(label)
-    if lut is not None:
-        cmd += " -l {0}".format(lut)
-    if intensity is not None:
-        cmd += " -i {0} {1}".format(intensity[0], intensity[1])
-    if edgethreshold is not None:
-        cmd += " -e {0}".format(edgethreshold)
-    if x is not None:
-        cmd += " -x {0} {1}".format(x[0], x[1])
-    if y is not None:
-        cmd += " -y {0} {1}".format(y[0], y[1])
-    if z is not None:
-        cmd += " -z {0} {1}".format(z[0], z[1])
+        cmd.append(input2)
+
+    # slicer output options must be
+    # applied after other options
+    outopts = ['x', 'y', 'z', 'a', 'A', 'S']
+    outargs = { k : kwargs.pop(k) for k in outopts if k in kwargs}
+
+    cmd = cmd + wutils.applyArgStyle('-', **kwargs) + \
+                wutils.applyArgStyle('-', **outargs)
 
     return cmd
 
-- 
GitLab