Skip to content

Commit 65a6249

Browse files
committed
fixed cmd_interface docs
1 parent 5464084 commit 65a6249

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

doc/devel/cmd_interface_devel.rst

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ grouped into separate classes (usually suffixed with InputSpec and OutputSpec).
2121
For example:
2222

2323
.. testcode::
24-
24+
2525
class ExampleInputSpec(TraitedSpec):
2626
input_volume = File(desc = "Input volume", exists = True,
2727
mandatory = True)
2828
parameter = traits.Int(desc = "some parameter")
29-
29+
3030
class ExampleOutputSpec(TraitedSpec):
3131
output_volume = File(desc = "Output volume", exists = True)
32-
32+
3333
For the Traits (and Nipype) to work correctly output and input spec has to be
3434
inherited from TraitedSpec (however, this does not have to be direct
3535
inheritance).
@@ -39,7 +39,7 @@ above example we have used the ``desc`` metadata which holds human readable
3939
description of the input. The ``mandatory`` flag forces Nipype to throw an
4040
exception if the input was not set. ``exists`` is a special flag that works only
4141
for ``File traits`` and checks if the provided file exists. More details can be
42-
found at `interface_specs`_.
42+
found at :doc:`interface_specs`.
4343

4444
The input and output specifications have to be connected to the our example
4545
interface class:
@@ -49,13 +49,13 @@ interface class:
4949
class Example(Interface):
5050
input_spec = ExampleInputSpec
5151
output_spec = ExampleOutputSpec
52-
52+
5353
Where the names of the classes grouping inputs and outputs were arbitrary the
5454
names of the fields within the interface they are assigned are not (it always
5555
has to be input_spec and output_spec). Of course this interface does not do much
5656
because we have not specified how to process the inputs and create the outputs.
5757
This can be done in many ways.
58-
58+
5959
Command line executable
6060
=======================
6161

@@ -67,14 +67,14 @@ between the inputs and the generated command line. To achieve this we have
6767
added two metadata: ``argstr`` (string defining how the argument should be
6868
formated) and ``position`` (number defining the order of the arguments).
6969
For example
70-
70+
7171
.. testcode::
7272

7373
class ExampleInputSpec(CommandLineSpec):
7474
input_volume = File(desc = "Input volume", exists = True,
7575
mandatory = True, position = 0, argstr="%s")
7676
parameter = traits.Int(desc = "some parameter", argstr = "--param %d")
77-
77+
7878
As you probably noticed the ``argstr`` is a printf type string with formatting
7979
symbols. For an input defined in InputSpec to be included into the executed
8080
commandline ``argstr`` has to be included. Additionally inside the main
@@ -88,11 +88,11 @@ to the ``_cmd`` field. Also the main interface class needs to inherit from
8888
_cmd = 'my_command'
8989
input_spec = ExampleInputSpec
9090
output_spec = ExampleOutputSpec
91-
91+
9292
There is one more thing we need to take care of. When the executable finishes
9393
processing it will presumably create some output files. We need to know which
9494
files to look for, check if they exist and expose them to whatever node would
95-
like to use them. This is done by implementing `_list_outputs`_ method in the
95+
like to use them. This is done by implementing ``_list_outputs`` method in the
9696
main interface class. Basically what it does is assigning the expected output
9797
files to the fields of our output spec:
9898

@@ -102,7 +102,7 @@ files to the fields of our output spec:
102102
outputs = self.output_spec().get()
103103
outputs['output_volume'] = os.path.abspath('name_of_the_file_this_cmd_made.nii')
104104
return outputs
105-
105+
106106
Sometimes the inputs need extra parsing before turning into command line
107107
parameters. For example imagine a parameter selecting between three methods:
108108
"old", "standard" and "new". Imagine also that the command line accept this as
@@ -122,42 +122,42 @@ numbers. We need to do additional parsing by overloading the following method
122122
in the main interface class:
123123

124124
.. testcode::
125-
125+
126126
def _format_arg(self, name, spec, value):
127127
if name == 'method':
128128
return spec.argstr%{"old":0, "standard":1, "new":2}[value]
129129
return super(Example, self)._format_arg(name, spec, value)
130-
130+
131131
Here is a minimalistic interface for the gzip command:
132132

133133
.. testcode::
134-
134+
135135
from nipype.interfaces.base import (
136-
TraitedSpec,
136+
TraitedSpec,
137137
CommandLineInputSpec,
138-
CommandLine,
138+
CommandLine,
139139
File
140140
)
141141
import os
142-
142+
143143
class GZipInputSpec(CommandLineInputSpec):
144144
input_file = File(desc="File", exists=True, mandatory=True, argstr="%s")
145-
145+
146146
class GZipOutputSpec(TraitedSpec):
147147
output_file = File(desc = "Zip file", exists = True)
148-
148+
149149
class GZipTask(CommandLine):
150150
input_spec = GZipInputSpec
151151
output_spec = GZipOutputSpec
152152
cmd = 'gzip'
153-
153+
154154
def _list_outputs(self):
155155
outputs = self.output_spec().get()
156156
outputs['output_file'] = os.path.abspath(self.inputs.input_file + ".gz")
157157
return outputs
158-
158+
159159
if __name__ == '__main__':
160-
160+
161161
zipper = GZipTask(input_file='an_existing_file')
162162
print zipper.cmdline
163163
zipper.run()
@@ -193,9 +193,9 @@ hash_files
193193

194194
name_template (optional)
195195
overrides the default ``_generated`` suffix
196-
196+
197197
output_name (optional)
198-
name of the output (if this is not set same name as the input will be
198+
name of the output (if this is not set same name as the input will be
199199
assumed)
200200

201201
keep_extension (optional - not used)

0 commit comments

Comments
 (0)