Skip to content

Commit fafdf22

Browse files
committed
adding python wrapper for ICA AROMA
1 parent f286f52 commit fafdf22

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

nipype/interfaces/fsl/ICA_AROMA.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#ICA_AROMA pulled from: https://github.com/rhr-pruim/ICA-AROMA
2+
#This assumes ICA_AROMA.py is already installed and callable via $PATH
3+
from nipype.interfaces.base import (
4+
TraitedSpec,
5+
CommandLineInputSpec,
6+
CommandLine,
7+
File,
8+
Directory,
9+
traits,
10+
OutputMultiPath
11+
)
12+
import os
13+
14+
class ICA_AROMAInputSpec(CommandLineInputSpec):
15+
featDir = Directory(exists=True,
16+
desc='If a feat directory exists and temporal filtering '
17+
'has not been run yet, ICA_AROMA can use the files in '
18+
'this directory.',mandatory=False,xor=['infile','mask','affmat','warp','mc'])
19+
infile = File(exists=True,
20+
desc='volume to be denoised',
21+
argstr='-i %s',mandatory=False,xor=['featDir'])
22+
outdir = Directory(desc='path to output directory',
23+
argstr='-o %s',mandatory=True)
24+
mask = File(exists=True,
25+
desc='path/name volume mask',
26+
argstr='-m %s',mandatory=False,xor=['featDir'])
27+
dim = traits.Int(desc='Dimensionality reduction when running '
28+
'MELODIC (defualt is automatic estimation)',
29+
argstr='-dim %d')
30+
TR = traits.Float(desc='TR in seconds. If this is not specified '
31+
'the TR will be extracted from the header of the fMRI nifti file.',
32+
argstr='%.2f')
33+
melodic_dir = Directory(exists=True,
34+
desc='path to MELODIC directory if MELODIC has already been ran',
35+
argstr='-meldir %s')
36+
affmat = File(exists=True,
37+
desc='path/name of the mat-file describing the '
38+
'affine registration (e.g. FSL FLIRT) of the '
39+
'functional data to structural space (.mat file)',
40+
argstr='-affmat %s',mandatory=False,xor=['featDir'])
41+
warp = File(exists=True,
42+
desc='File name of the warp-file describing '
43+
'the non-linear registration (e.g. FSL FNIRT) '
44+
'of the structural data to MNI152 space (.nii.gz)',
45+
argstr='-warp %s',mandatory=False,xor=['featDir'])
46+
mc = File(exists=True,
47+
desc='motion parameters file',
48+
argstr='-mc %s',mandatory=False,xor=['featDir'])
49+
denoise_type = traits.Str(argstr='-den %s',
50+
desc='Type of denoising strategy: '
51+
'-none: only classification, no denoising '
52+
'-nonaggr (default): non-aggresssive denoising, i.e. partial component regression '
53+
'-aggr: aggressive denoising, i.e. full component regression '
54+
'-both: both aggressive and non-aggressive denoising (two outputs)',
55+
mandatory=True)
56+
57+
class ICA_AROMAOutputSpec(TraitedSpec):
58+
out_file = OutputMultiPath(File(exists=True),
59+
desc='if generated: 1-(non aggressive denoised volume),'
60+
'2-(aggressive denoised volume)')
61+
62+
class ICA_AROMA(CommandLine):
63+
"""
64+
65+
Example
66+
-------
67+
68+
>>> from nipype.interfaces.fsl import ICA_AROMA
69+
>>> AROMA_obj=ICA_AROMA.ICA_AROMA()
70+
>>> outDir=os.path.join(os.getcwd(),'ICA_AROMA_testout')
71+
>>> func='/path/to/mcImg_brain.nii.gz'
72+
>>> affmat='/path/to/functoT1.mat'
73+
>>> warp='/path/to/T1toMNI_warp.nii.gz'
74+
>>> mc='/path/to/mcImg.par'
75+
>>> mask='/path/to/mcImg_mask.nii.gz'
76+
>>> denoise_type='both'
77+
>>> AROMA_obj.inputs.infile=func
78+
>>> AROMA_obj.inputs.affmat=affmat
79+
>>> AROMA_obj.inputs.warp=warp
80+
>>> AROMA_obj.inputs.mc=mc
81+
>>> AROMA_obj.inputs.mask=mask
82+
>>> AROMA_obj.inputs.denoise_type=denoise_type
83+
>>> AROMA_obj.inputs.outdir=outDir
84+
>>> AROMA_obj.cmdline
85+
'ICA_AROMA.py -affmat /path/to/functoT1.mat -den both
86+
-i /path/to/mcImg_brain.nii.gz
87+
-m /path/to/mcImg_mask.nii.gz
88+
-mc /path/to/mcImg.par
89+
-o /path/to/ICA_AROMA_testout
90+
-warp /path/to/T1toMNI_warp.nii.gz'
91+
>>> AROMA_obj.run()
92+
93+
"""
94+
_cmd = 'ICA_AROMA.py'
95+
input_spec = ICA_AROMAInputSpec
96+
output_spec = ICA_AROMAOutputSpec
97+
98+
def _list_outputs(self):
99+
outputs = self.output_spec.get()
100+
outdir = self.input_spec.outdir
101+
denoising_strategy = input_spec.denoise_type
102+
103+
if denoising_strategy is "noaggr":
104+
outputs['out_file'] = os.path.join(outdir,'denoised_func_data_nonaggr.nii.gz')
105+
elif denoising_strategy is "aggr":
106+
outputs['out_file'] = os.path.join(outdir,'denoised_func_data_aggr.nii.gz')
107+
elif denoising_strategy is "both":
108+
outputs['out_file'] = (os.path.join(outdir,'denoised_func_data_nonaggr.nii.gz'), os.path.join(outdir,'denoised_func_data_aggr.nii.gz'))
109+
elif denoising_strategy is "none":
110+
print "No denoising selected"
111+
else:
112+
raise RuntimeError('denoise_type must be specified as one of'
113+
' noaggr,aggr,both, or none')
114+
115+
return outputs

0 commit comments

Comments
 (0)