name: inverse layout: true class: center, middle, inverse --- # Nipype # Advanced Concepts ## Complex workflows and custom interfaces ### ~60min --- name: content class: left layout: false name: intro .left-column[ ## Iteration ### ~30min ] .right-column[ Once you have a grasp on the Nipype basics you can create (nearly) arbitrarily iteration patterns through your dataset Please go through the following notebooks * [`Iteration/Iterables`](../../notebooks/notebooks/basic_iteration.ipynb) * [`Map Nodes`](../../notebooks/notebooks/basic_mapnodes.ipynb) * [`Join Nodes`](../../notebooks/notebooks/basic_joinnodes.ipynb) ] --- ## Recap of Iteration - Part 1 * **Iterables** (left): Allows to iterate over a specific parameter, e.g. subject name, smoothing kernel ```python isosmooth = Node(IsotropicSmooth(), name='iso_smooth') isosmooth.iterables = ("fwhm", [4, 8, 16]) ``` * **MapNode** (right): Allows to iterate over a specific parameter, e.g. subject name, smoothing kernel ```python from nipype import MapNode gunzip = MapNode(Gunzip(), name='gunzip', iterfield=['in_file']) gunzip.inputs.in_file = ['func01.nii.gz', 'func02.nii.gz', 'func03.nii.gz'] ```
--- ## Recap of Iteration - Part 2 * **JoinNode** (left): Like a MapNode that units again a previous `iterable` conjunction * **Synchronize** (middle): Iterate over a list of parameters in `zipped` way * **Itersource** (right): Allows you to expand a downstream iterable based on a mapping of an upstream iterable
--- name: content class: left layout: false name: intro .left-column[ ## Custom Interfaces ### ~30min ] .right-column[ Although there are existing interfaces for many of the popular (and less-used) NeuroImaging toolboxes, there are times where you will want/need to write your own Please go through the following notebooks * [`Function Interfaces`](../../notebooks/notebooks/basic_function_interface.ipynb) * [`Writing Your Own Interfaces`](../../notebooks/notebooks/advanced_create_interfaces.ipynb) ] --- ## Recap of Custom Interfaces - Part 1 * **Function Interface**: Shortcut to create your own interface ```python def write_parameter_to_txt(my_parameter): import numpy as np out_file = 'new_parameter.txt' np.savetxt(out_file, [my_parameter], fmt='%d') return out_file write_parameter = Node(Function(input_names=['my_parameter'], output_names=['out_file'], function=write_parameter_to_txt), name='write_parameter') ``` -- * ** Command Line Interfaces**: Extend the `CommandLine` interface base class ```python from nipype.interfaces.base import CommandLineInputSpec, File class TransformInfoInputSpec(CommandLineInputSpec): in_file = File(exists=True, mandatory=True, argstr='%s', position=0, desc='the input transform file') class TransformInfo(CommandLine): _cmd = 'antsTransformInfo' input_spec = TransformInfoInputSpec ``` --- ## Recap of Custom Interfaces - Part 2 * ** Python Interfaces**: Use `Function` interface for simple cases, extend `BaseInterface` and implement `_run_interface` and `_list_outputs` for complex ```python class TranslateImage(BaseInterface): input_spec = TranslateImageInputSpec output_spec = TranslateImageOutputSpec def _run_interface(self, runtime): # Call our python code here: translate_image( self.inputs.in_file, self.inputs.translation, self.inputs.out_file) # And we are done return runtime def _list_outputs(self): return {'out_file': self.inputs.out_file} ``` --- ## Recap of Custom Interfaces - Part 3 * ** Matlab Interfaces**: Either extend `MatlabCommand` or `BaseInterface` and explicitly call matlab command --- layout: true class: center, middle, inverse --- name: questions # Questions?