Warning: This document is for an old version of niworkflows. The main version is master.

niworkflows.interfaces.utility module

Interfaces under evaluation before upstreaming to nipype.interfaces.utility.

class niworkflows.interfaces.utility.AddTSVHeader(from_file=None, resource_monitor=None, **inputs)[source]

Bases: nipype.interfaces.base.core.SimpleInterface

Add a header row to a TSV file

Examples

An example TSV:

>>> np.savetxt('data.tsv', np.arange(30).reshape((6, 5)), delimiter='\t')

Add headers:

>>> addheader = AddTSVHeader()
>>> addheader.inputs.in_file = 'data.tsv'
>>> addheader.inputs.columns = ['a', 'b', 'c', 'd', 'e']
>>> res = addheader.run()
>>> df = pd.read_csv(res.outputs.out_file, delim_whitespace=True,
...                  index_col=None)
>>> df.columns.ravel().tolist()
['a', 'b', 'c', 'd', 'e']
>>> np.all(df.values == np.arange(30).reshape((6, 5)))
True
input_spec

alias of niworkflows.interfaces.utility._AddTSVHeaderInputSpec

output_spec

alias of niworkflows.interfaces.utility._AddTSVHeaderOutputSpec

class niworkflows.interfaces.utility.DictMerge(from_file=None, resource_monitor=None, **inputs)[source]

Bases: nipype.interfaces.base.core.SimpleInterface

Merge (ordered) dictionaries.

input_spec

alias of niworkflows.interfaces.utility._DictMergeInputSpec

output_spec

alias of niworkflows.interfaces.utility._DictMergeOutputSpec

class niworkflows.interfaces.utility.JoinTSVColumns(from_file=None, resource_monitor=None, **inputs)[source]

Bases: nipype.interfaces.base.core.SimpleInterface

Add a header row to a TSV file

Examples

An example TSV:

>>> data = np.arange(30).reshape((6, 5))
>>> np.savetxt('data.tsv', data[:, :3], delimiter='\t')
>>> np.savetxt('add.tsv', data[:, 3:], delimiter='\t')

Join without naming headers:

>>> join = JoinTSVColumns()
>>> join.inputs.in_file = 'data.tsv'
>>> join.inputs.join_file = 'add.tsv'
>>> res = join.run()
>>> df = pd.read_csv(res.outputs.out_file, delim_whitespace=True,
...                  index_col=None, dtype=float, header=None)
>>> df.columns.ravel().tolist() == list(range(5))
True
>>> np.all(df.values.astype(int) == data)
True

Adding column names:

>>> join = JoinTSVColumns()
>>> join.inputs.in_file = 'data.tsv'
>>> join.inputs.join_file = 'add.tsv'
>>> join.inputs.columns = ['a', 'b', 'c', 'd', 'e']
>>> res = join.run()
>>> res.outputs.out_file  
'...data_joined.tsv'
>>> df = pd.read_csv(res.outputs.out_file, delim_whitespace=True,
...                  index_col=None)
>>> df.columns.ravel().tolist()
['a', 'b', 'c', 'd', 'e']
>>> np.all(df.values == np.arange(30).reshape((6, 5)))
True
>>> join = JoinTSVColumns()
>>> join.inputs.in_file = 'data.tsv'
>>> join.inputs.join_file = 'add.tsv'
>>> join.inputs.side = 'left'
>>> join.inputs.columns = ['a', 'b', 'c', 'd', 'e']
>>> res = join.run()
>>> df = pd.read_csv(res.outputs.out_file, delim_whitespace=True,
...                  index_col=None)
>>> df.columns.ravel().tolist()
['a', 'b', 'c', 'd', 'e']
>>> np.all(df.values == np.hstack((data[:, 3:], data[:, :3])))
True
input_spec

alias of niworkflows.interfaces.utility._JoinTSVColumnsInputSpec

output_spec

alias of niworkflows.interfaces.utility._JoinTSVColumnsOutputSpec

class niworkflows.interfaces.utility.KeySelect(keys=None, fields=None, **inputs)[source]

Bases: nipype.interfaces.base.core.BaseInterface

An interface that operates similarly to an OrderedDict.

>>> ks = KeySelect(keys=['MNI152NLin6Asym', 'MNI152Lin', 'fsaverage'],
...                fields=['field1', 'field2', 'field3'])
>>> ks.inputs.field1 = ['fsl', 'mni', 'freesurfer']
>>> ks.inputs.field2 = ['volume', 'volume', 'surface']
>>> ks.inputs.field3 = [True, False, False]
>>> ks.inputs.key = 'MNI152Lin'
>>> ks.run().outputs

field1 = mni
field2 = volume
field3 = False
key = MNI152Lin
>>> ks = KeySelect(fields=['field1', 'field2', 'field3'])
>>> ks.inputs.keys=['MNI152NLin6Asym', 'MNI152Lin', 'fsaverage']
>>> ks.inputs.field1 = ['fsl', 'mni', 'freesurfer']
>>> ks.inputs.field2 = ['volume', 'volume', 'surface']
>>> ks.inputs.field3 = [True, False, False]
>>> ks.inputs.key = 'MNI152Lin'
>>> ks.run().outputs

field1 = mni
field2 = volume
field3 = False
key = MNI152Lin
>>> ks.inputs.field1 = ['fsl', 'mni', 'freesurfer']
>>> ks.inputs.field2 = ['volume', 'volume', 'surface']
>>> ks.inputs.field3 = [True, False, False]
>>> ks.inputs.key = 'fsaverage'
>>> ks.run().outputs

field1 = freesurfer
field2 = surface
field3 = False
key = fsaverage
>>> ks.inputs.field1 = ['fsl', 'mni', 'freesurfer']
>>> ks.inputs.field2 = ['volume', 'volume', 'surface']
>>> ks.inputs.field3 = [True, False]  
Traceback (most recent call last):
ValueError: Trying to set an invalid value
>>> ks.inputs.key = 'MNINLin2009cAsym'
Traceback (most recent call last):
ValueError: Selected key "MNINLin2009cAsym" not found in the index
>>> ks = KeySelect(fields=['field1', 'field2', 'field3'])
>>> ks.inputs.keys=['MNI152NLin6Asym']
>>> ks.inputs.field1 = ['fsl']
>>> ks.inputs.field2 = ['volume']
>>> ks.inputs.field3 = [True]
>>> ks.inputs.key = 'MNI152NLin6Asym'
>>> ks.run().outputs

field1 = fsl
field2 = volume
field3 = True
key = MNI152NLin6Asym
input_spec

alias of niworkflows.interfaces.utility._KeySelectInputSpec

output_spec

alias of niworkflows.interfaces.utility._KeySelectOutputSpec

class niworkflows.interfaces.utility.TSV2JSON(from_file=None, resource_monitor=None, **inputs)[source]

Bases: nipype.interfaces.base.core.SimpleInterface

Convert metadata from TSV format to JSON format.

input_spec

alias of niworkflows.interfaces.utility._TSV2JSONInputSpec

output_spec

alias of niworkflows.interfaces.utility._TSV2JSONOutputSpec