-
Notifications
You must be signed in to change notification settings - Fork 520
/
aroma.py
164 lines (149 loc) · 5.55 KB
/
aroma.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# -*- coding: utf-8 -*-
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""This commandline module provides classes for interfacing with the
`ICA-AROMA.py <https://github.com/maartenmennes/ICA-AROMA>`__ command line tool.
"""
from ..base import (
TraitedSpec,
CommandLineInputSpec,
CommandLine,
File,
Directory,
traits,
isdefined,
)
import os
class ICA_AROMAInputSpec(CommandLineInputSpec):
feat_dir = Directory(
exists=True,
mandatory=True,
argstr="-feat %s",
xor=["in_file", "mat_file", "fnirt_warp_file", "motion_parameters"],
desc="If a feat directory exists and temporal filtering "
"has not been run yet, ICA_AROMA can use the files in "
"this directory.",
)
in_file = File(
exists=True,
mandatory=True,
argstr="-i %s",
xor=["feat_dir"],
desc="volume to be denoised",
)
out_dir = Directory(
"out", usedefault=True, mandatory=True, argstr="-o %s", desc="output directory"
)
mask = File(
exists=True, argstr="-m %s", xor=["feat_dir"], desc="path/name volume mask"
)
dim = traits.Int(
argstr="-dim %d",
desc="Dimensionality reduction when running "
"MELODIC (defualt is automatic estimation)",
)
TR = traits.Float(
argstr="-tr %.3f",
desc="TR in seconds. If this is not specified "
"the TR will be extracted from the "
"header of the fMRI nifti file.",
)
melodic_dir = Directory(
exists=True,
argstr="-meldir %s",
desc="path to MELODIC directory if MELODIC has already been run",
)
mat_file = File(
exists=True,
argstr="-affmat %s",
xor=["feat_dir"],
desc="path/name of the mat-file describing the "
"affine registration (e.g. FSL FLIRT) of the "
"functional data to structural space (.mat file)",
)
fnirt_warp_file = File(
exists=True,
argstr="-warp %s",
xor=["feat_dir"],
desc="File name of the warp-file describing "
"the non-linear registration (e.g. FSL FNIRT) "
"of the structural data to MNI152 space (.nii.gz)",
)
motion_parameters = File(
exists=True,
mandatory=True,
argstr="-mc %s",
xor=["feat_dir"],
desc="motion parameters file",
)
denoise_type = traits.Enum(
"nonaggr",
"aggr",
"both",
"no",
usedefault=True,
mandatory=True,
argstr="-den %s",
desc="Type of denoising strategy:\n"
"-no: only classification, no denoising\n"
"-nonaggr (default): non-aggresssive denoising, i.e. partial component regression\n"
"-aggr: aggressive denoising, i.e. full component regression\n"
"-both: both aggressive and non-aggressive denoising (two outputs)",
)
class ICA_AROMAOutputSpec(TraitedSpec):
aggr_denoised_file = File(
exists=True, desc="if generated: aggressively denoised volume"
)
nonaggr_denoised_file = File(
exists=True, desc="if generated: non aggressively denoised volume"
)
out_dir = Directory(
exists=True,
desc="directory contains (in addition to the denoised files): "
"melodic.ica + classified_motion_components + "
"classification_overview + feature_scores + melodic_ic_mni)",
)
class ICA_AROMA(CommandLine):
"""
Interface for the ICA_AROMA.py script.
ICA-AROMA (i.e. 'ICA-based Automatic Removal Of Motion Artifacts') concerns
a data-driven method to identify and remove motion-related independent
components from fMRI data. To that end it exploits a small, but robust
set of theoretically motivated features, preventing the need for classifier
re-training and therefore providing direct and easy applicability.
See link for further documentation: https://github.com/rhr-pruim/ICA-AROMA
Example
-------
>>> from nipype.interfaces.fsl import ICA_AROMA
>>> from nipype.testing import example_data
>>> AROMA_obj = ICA_AROMA()
>>> AROMA_obj.inputs.in_file = 'functional.nii'
>>> AROMA_obj.inputs.mat_file = 'func_to_struct.mat'
>>> AROMA_obj.inputs.fnirt_warp_file = 'warpfield.nii'
>>> AROMA_obj.inputs.motion_parameters = 'fsl_mcflirt_movpar.txt'
>>> AROMA_obj.inputs.mask = 'mask.nii.gz'
>>> AROMA_obj.inputs.denoise_type = 'both'
>>> AROMA_obj.inputs.out_dir = 'ICA_testout'
>>> AROMA_obj.cmdline # doctest: +ELLIPSIS
'ICA_AROMA.py -den both -warp warpfield.nii -i functional.nii -m mask.nii.gz -affmat func_to_struct.mat -mc fsl_mcflirt_movpar.txt -o .../ICA_testout'
"""
_cmd = "ICA_AROMA.py"
input_spec = ICA_AROMAInputSpec
output_spec = ICA_AROMAOutputSpec
def _format_arg(self, name, trait_spec, value):
if name == "out_dir":
return trait_spec.argstr % os.path.abspath(value)
return super(ICA_AROMA, self)._format_arg(name, trait_spec, value)
def _list_outputs(self):
outputs = self.output_spec().get()
outputs["out_dir"] = os.path.abspath(self.inputs.out_dir)
out_dir = outputs["out_dir"]
if self.inputs.denoise_type in ("aggr", "both"):
outputs["aggr_denoised_file"] = os.path.join(
out_dir, "denoised_func_data_aggr.nii.gz"
)
if self.inputs.denoise_type in ("nonaggr", "both"):
outputs["nonaggr_denoised_file"] = os.path.join(
out_dir, "denoised_func_data_nonaggr.nii.gz"
)
return outputs