@@ -21,15 +21,15 @@ grouped into separate classes (usually suffixed with InputSpec and OutputSpec).
2121For 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+
3333For the Traits (and Nipype) to work correctly output and input spec has to be
3434inherited from TraitedSpec (however, this does not have to be direct
3535inheritance).
@@ -39,7 +39,7 @@ above example we have used the ``desc`` metadata which holds human readable
3939description of the input. The ``mandatory `` flag forces Nipype to throw an
4040exception if the input was not set. ``exists `` is a special flag that works only
4141for ``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
4444The input and output specifications have to be connected to the our example
4545interface class:
@@ -49,13 +49,13 @@ interface class:
4949 class Example(Interface):
5050 input_spec = ExampleInputSpec
5151 output_spec = ExampleOutputSpec
52-
52+
5353Where the names of the classes grouping inputs and outputs were arbitrary the
5454names of the fields within the interface they are assigned are not (it always
5555has to be input_spec and output_spec). Of course this interface does not do much
5656because we have not specified how to process the inputs and create the outputs.
5757This can be done in many ways.
58-
58+
5959Command line executable
6060=======================
6161
@@ -67,32 +67,32 @@ between the inputs and the generated command line. To achieve this we have
6767added two metadata: ``argstr `` (string defining how the argument should be
6868formated) and ``position `` (number defining the order of the arguments).
6969For 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+
7878As you probably noticed the ``argstr `` is a printf type string with formatting
7979symbols. For an input defined in InputSpec to be included into the executed
8080commandline ``argstr `` has to be included. Additionally inside the main
8181interface class you need to specify the name of the executable by assigning it
8282to the ``_cmd `` field. Also the main interface class needs to inherit from
83- ` CommandLine `_ :
83+ :class: ` nipype.interfaces.base. CommandLine `:
8484
8585.. testcode ::
8686
8787 class Example(CommandLine):
8888 _cmd = 'my_command'
8989 input_spec = ExampleInputSpec
9090 output_spec = ExampleOutputSpec
91-
91+
9292There is one more thing we need to take care of. When the executable finishes
9393processing it will presumably create some output files. We need to know which
9494files 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
9696main interface class. Basically what it does is assigning the expected output
9797files 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+
106106Sometimes the inputs need extra parsing before turning into command line
107107parameters. 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
122122in 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+
131131Here 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
194194name_template (optional)
195195 overrides the default ``_generated `` suffix
196-
196+
197197output_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
201201keep_extension (optional - not used)
0 commit comments