Skip to content

Commit 19848fd

Browse files
committed
WIP: ICA_AROMA.py, responding to 2nd round of edits
1 parent 4c89009 commit 19848fd

File tree

2 files changed

+126
-52
lines changed

2 files changed

+126
-52
lines changed

nipype/interfaces/fsl/ICA_AROMA.py

Lines changed: 58 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,94 +13,100 @@
1313

1414
class ICA_AROMAInputSpec(CommandLineInputSpec):
1515
feat_dir = Directory(exists=True, mandatory=True,
16-
argstr='-feat %s',
17-
xor=['in_file', 'mat_file', 'fnirt_warp_file', 'motion_parameters'],
18-
desc='If a feat directory exists and temporal filtering '
19-
'has not been run yet, ICA_AROMA can use the files in '
20-
'this directory.')
16+
argstr='-feat %s',
17+
xor=['in_file', 'mat_file', 'fnirt_warp_file', 'motion_parameters'],
18+
desc='If a feat directory exists and temporal filtering '
19+
'has not been run yet, ICA_AROMA can use the files in '
20+
'this directory.')
2121
in_file = File(exists=True, mandatory=True,
22-
argstr='-i %s', xor=['feat_dir'],
23-
desc='volume to be denoised')
22+
argstr='-i %s', xor=['feat_dir'],
23+
desc='volume to be denoised')
2424
out_dir = Directory('out', mandatory=True,
25-
argstr='-o %s',
26-
desc='output directory')
25+
argstr='-o %s',
26+
desc='output directory')
2727
mask = File(exists=True, argstr='-m %s', xor=['feat_dir'],
28-
desc='path/name volume mask')
28+
desc='path/name volume mask')
2929
dim = traits.Int(argstr='-dim %d',
30-
desc='Dimensionality reduction when running '
31-
'MELODIC (defualt is automatic estimation)')
30+
desc='Dimensionality reduction when running '
31+
'MELODIC (defualt is automatic estimation)')
3232
TR = traits.Float(argstr='-tr %.3f',
33-
desc='TR in seconds. If this is not specified '
34-
'the TR will be extracted from the '
35-
'header of the fMRI nifti file.')
33+
desc='TR in seconds. If this is not specified '
34+
'the TR will be extracted from the '
35+
'header of the fMRI nifti file.')
3636
melodic_dir = Directory(exists=True, argstr='-meldir %s',
37-
desc='path to MELODIC directory if MELODIC has already been run')
38-
mat_file = File(exists=True, mandatory=True,
39-
argstr='-affmat %s', xor=['feat_dir'],
40-
desc='path/name of the mat-file describing the '
41-
'affine registration (e.g. FSL FLIRT) of the '
42-
'functional data to structural space (.mat file)')
43-
fnirt_warp_file = File(exists=True, mandatory=True,
44-
argstr='-warp %s', xor=['feat_dir'],
45-
desc='File name of the warp-file describing '
46-
'the non-linear registration (e.g. FSL FNIRT) '
47-
'of the structural data to MNI152 space (.nii.gz)')
37+
desc='path to MELODIC directory if MELODIC has already been run')
38+
mat_file = File(exists=True, argstr='-affmat %s', xor=['feat_dir'],
39+
desc='path/name of the mat-file describing the '
40+
'affine registration (e.g. FSL FLIRT) of the '
41+
'functional data to structural space (.mat file)')
42+
fnirt_warp_file = File(exists=True, argstr='-warp %s', xor=['feat_dir'],
43+
desc='File name of the warp-file describing '
44+
'the non-linear registration (e.g. FSL FNIRT) '
45+
'of the structural data to MNI152 space (.nii.gz)')
4846
motion_parameters = File(exists=True, mandatory=True,
49-
argstr='-mc %s', xor=['feat_dir'],
50-
desc='motion parameters file')
47+
argstr='-mc %s', xor=['feat_dir'],
48+
desc='motion parameters file')
5149
denoise_type = traits.Enum('nonaggr', 'aggr', 'both', 'no', usedefault=True,
52-
mandatory=True, argstr='-den %s',
53-
desc='Type of denoising strategy: '
54-
'-none: only classification, no denoising '
55-
'-nonaggr (default): non-aggresssive denoising, i.e. partial component regression '
56-
'-aggr: aggressive denoising, i.e. full component regression '
57-
'-both: both aggressive and non-aggressive denoising (two outputs)')
50+
mandatory=True, argstr='-den %s',
51+
desc='Type of denoising strategy: '
52+
'-none: only classification, no denoising '
53+
'-nonaggr (default): non-aggresssive denoising, i.e. partial component regression '
54+
'-aggr: aggressive denoising, i.e. full component regression '
55+
'-both: both aggressive and non-aggressive denoising (two outputs)')
5856

5957
class ICA_AROMAOutputSpec(TraitedSpec):
6058
aggr_denoised_file=File(exists=True,
6159
desc='if generated: aggressively denoised volume')
6260
nonaggr_denoised_file=File(exists=True,
6361
desc='if generated: non aggressively denoised volume' )
6462
out_dir = Directory(exists=True,
65-
desc='directory contains (in addition to the denoised files): '
66-
'melodic.ica + classified_motion_components + '
67-
'classification_overview + feature_scores + melodic_ic_mni)')
63+
desc='directory contains (in addition to the denoised files): '
64+
'melodic.ica + classified_motion_components + '
65+
'classification_overview + feature_scores + melodic_ic_mni)')
6866

6967
class ICA_AROMA(CommandLine):
7068
"""
69+
Interface for the ICA_AROMA.py script (v0.3 beta).
70+
71+
ICA-AROMA (i.e. 'ICA-based Automatic Removal Of Motion Artifacts') concerns
72+
a data-driven method to identify and remove motion-related independent
73+
components from fMRI data. To that end it exploits a small, but robust
74+
set of theoretically motivated features, preventing the need for classifier
75+
re-training and therefore providing direct and easy applicability.
76+
77+
78+
See link for further documentation: https://github.com/rhr-pruim/ICA-AROMA
79+
80+
7181
7282
Example
7383
-------
7484
7585
>>> from nipype.interfaces.fsl import ICA_AROMA
7686
>>> from nipype.testing import example_data
7787
>>> AROMA_obj = ICA_AROMA.ICA_AROMA()
78-
>>> AROMA_obj.inputs.in_file=example_data('functional.nii')
79-
>>> AROMA_obj.inputs.mat_file=example_data('func_to_struct.mat')
80-
>>> AROMA_obj.inputs.fnirt_warp_file=example_data('warpfield.nii')
81-
>>> AROMA_obj.inputs.motion_parameters=example_data('functional.par')
82-
>>> AROMA_obj.inputs.mask=example_data('mask.nii.gz')
83-
>>> AROMA_obj.inputs.denoise_type='both'
84-
>>> AROMA_obj.inputs.out_dir='ICA_testout'
85-
>>> AROMA_obj.cmdline
86-
u'ICA_AROMA.py -den both -warp /home/travis/build/nipy/nipype/nipype/testing/data/warpfield.nii -i /home/travis/build/nipy/nipype/nipype/testing/data/functional.nii -m /home/travis/build/nipy/nipype/nipype/testing/data/mask.nii.gz -affmat /home/travis/build/nipy/nipype/nipype/testing/data/func_to_struct.mat -mc /home/travis/build/nipy/nipype/nipype/testing/data/functional.par -o ICA_testout'
87-
88+
>>> AROMA_obj.inputs.in_file = 'functional.nii'
89+
>>> AROMA_obj.inputs.mat_file = 'func_to_struct.mat'
90+
>>> AROMA_obj.inputs.fnirt_warp_file = 'warpfield.nii'
91+
>>> AROMA_obj.inputs.motion_parameters = 'functional.par'
92+
>>> AROMA_obj.inputs.mask = 'mask.nii.gz'
93+
>>> AROMA_obj.inputs.denoise_type = 'both'
94+
>>> AROMA_obj.inputs.out_dir = 'ICA_testout'
95+
>>> AROMA_obj.cmdline # doctest: +ALLOW_UNICODE
96+
'ICA_AROMA.py -den both -warp warpfield.nii -i functional.nii -m mask.nii.gz \
97+
-affmat func_to_struct.mat -mc fsl_mcflirt_movpar.txt -o ICA_testout'
8898
"""
8999
_cmd = 'ICA_AROMA.py'
90100
input_spec = ICA_AROMAInputSpec
91101
output_spec = ICA_AROMAOutputSpec
92102

93103
def _list_outputs(self):
94-
95104
out_dir = os.path.abspath(self.inputs.out_dir)
96105
outputs['out_dir'] = out_dir
97-
#outputs = self.output_spec.get()
98-
#outdir = self.input_spec.outdir
99-
#denoising_strategy = input_spec.denoise_type
100106

101107
if self.inputs.denoise_type in ('aggr', 'both'):
102108
outputs['aggr_denoised_file'] = os.path.join(out_dir, 'denoised_func_data_aggr.nii.gz')
103109
if self.inputs.denoise_type in ('nonaggr', 'both'):
104110
outputs['nonaggr_denoised_file'] = os.path.join(out_dir, 'denoised_func_data_nonaggr.nii.gz')
105111

106-
return outputs
112+
return outputs
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..ICA_AROMA import ICA_AROMA
4+
5+
6+
def test_ICA_AROMA_inputs():
7+
input_map = dict(TR=dict(argstr='-tr %.3f',
8+
),
9+
args=dict(argstr='%s',
10+
),
11+
denoise_type=dict(argstr='-den %s',
12+
mandatory=True,
13+
usedefault=True,
14+
),
15+
dim=dict(argstr='-dim %d',
16+
),
17+
environ=dict(nohash=True,
18+
usedefault=True,
19+
),
20+
feat_dir=dict(argstr='-feat %s',
21+
mandatory=True,
22+
xor=['in_file', 'mat_file', 'fnirt_warp_file', 'motion_parameters'],
23+
),
24+
fnirt_warp_file=dict(argstr='-warp %s',
25+
xor=['feat_dir'],
26+
),
27+
ignore_exception=dict(nohash=True,
28+
usedefault=True,
29+
),
30+
in_file=dict(argstr='-i %s',
31+
mandatory=True,
32+
xor=['feat_dir'],
33+
),
34+
mask=dict(argstr='-m %s',
35+
xor=['feat_dir'],
36+
),
37+
mat_file=dict(argstr='-affmat %s',
38+
xor=['feat_dir'],
39+
),
40+
melodic_dir=dict(argstr='-meldir %s',
41+
),
42+
motion_parameters=dict(argstr='-mc %s',
43+
mandatory=True,
44+
xor=['feat_dir'],
45+
),
46+
out_dir=dict(argstr='-o %s',
47+
mandatory=True,
48+
),
49+
terminal_output=dict(nohash=True,
50+
),
51+
)
52+
inputs = ICA_AROMA.input_spec()
53+
54+
for key, metadata in list(input_map.items()):
55+
for metakey, value in list(metadata.items()):
56+
assert getattr(inputs.traits()[key], metakey) == value
57+
58+
59+
def test_ICA_AROMA_outputs():
60+
output_map = dict(aggr_denoised_file=dict(),
61+
nonaggr_denoised_file=dict(),
62+
out_dir=dict(),
63+
)
64+
outputs = ICA_AROMA.output_spec()
65+
66+
for key, metadata in list(output_map.items()):
67+
for metakey, value in list(metadata.items()):
68+
assert getattr(outputs.traits()[key], metakey) == value

0 commit comments

Comments
 (0)