@@ -107,6 +107,7 @@ class ICAConfoundsOutputSpec(TraitedSpec):
107
107
File (exists = True , desc = 'output confounds file extracted from ICA-AROMA' ))
108
108
aroma_noise_ics = File (exists = True , desc = 'ICA-AROMA noise components' )
109
109
melodic_mix = File (exists = True , desc = 'melodic mix file' )
110
+ aroma_metadata = File (exists = True , desc = 'tabulated ICA-AROMA metadata' )
110
111
111
112
112
113
class ICAConfounds (SimpleInterface ):
@@ -116,8 +117,10 @@ class ICAConfounds(SimpleInterface):
116
117
output_spec = ICAConfoundsOutputSpec
117
118
118
119
def _run_interface (self , runtime ):
119
- aroma_confounds , motion_ics_out , melodic_mix_out = _get_ica_confounds (
120
- self .inputs .in_directory , self .inputs .skip_vols , newpath = runtime .cwd )
120
+ (aroma_confounds , motion_ics_out , melodic_mix_out , aroma_metadata
121
+ ) = _get_ica_confounds (self .inputs .in_directory ,
122
+ self .inputs .skip_vols ,
123
+ newpath = runtime .cwd )
121
124
122
125
if self .inputs .err_on_aroma_warn and aroma_confounds is None :
123
126
raise RuntimeError ('ICA-AROMA failed' )
@@ -126,6 +129,7 @@ def _run_interface(self, runtime):
126
129
127
130
self ._results ['aroma_noise_ics' ] = motion_ics_out
128
131
self ._results ['melodic_mix' ] = melodic_mix_out
132
+ self ._results ['aroma_metadata' ] = aroma_metadata
129
133
return runtime
130
134
131
135
@@ -218,10 +222,12 @@ def _get_ica_confounds(ica_out_dir, skip_vols, newpath=None):
218
222
# load the txt files from ICA-AROMA
219
223
melodic_mix = os .path .join (ica_out_dir , 'melodic.ica/melodic_mix' )
220
224
motion_ics = os .path .join (ica_out_dir , 'classified_motion_ICs.txt' )
225
+ aroma_metadata = os .path .join (ica_out_dir , 'classification_overview.txt' )
221
226
222
227
# Change names of motion_ics and melodic_mix for output
223
228
melodic_mix_out = os .path .join (newpath , 'MELODICmix.tsv' )
224
229
motion_ics_out = os .path .join (newpath , 'AROMAnoiseICs.csv' )
230
+ aroma_metadata_out = os .path .join (newpath , 'classification_overview.tsv' )
225
231
226
232
# copy metion_ics file to derivatives name
227
233
shutil .copyfile (motion_ics , motion_ics_out )
@@ -238,18 +244,27 @@ def _get_ica_confounds(ica_out_dir, skip_vols, newpath=None):
238
244
# save melodic_mix_arr
239
245
np .savetxt (melodic_mix_out , melodic_mix_arr , delimiter = '\t ' )
240
246
247
+ # process the metadata so that the IC column entries match the BIDS name of
248
+ # the regressor
249
+ aroma_metadata = pd .read_csv (aroma_metadata , sep = '\t ' )
250
+ aroma_metadata ['IC' ] = [
251
+ 'aroma_motion_{}' .format (name ) for name in aroma_metadata ['IC' ]]
252
+ aroma_metadata .columns = [
253
+ re .sub ('[ |\-|\/]' , '_' , c ) for c in aroma_metadata .columns ]
254
+ aroma_metadata .to_csv (aroma_metadata_out , sep = '\t ' , index = False )
255
+
241
256
# Return dummy list of ones if no noise compnents were found
242
257
if motion_ic_indices .size == 0 :
243
258
LOGGER .warning ('No noise components were classified' )
244
- return None , motion_ics_out , melodic_mix_out
259
+ return None , motion_ics_out , melodic_mix_out , aroma_metadata_out
245
260
246
261
# the "good" ics, (e.g., not motion related)
247
262
good_ic_arr = np .delete (melodic_mix_arr , motion_ic_indices , 1 ).T
248
263
249
264
# return dummy lists of zeros if no signal components were found
250
265
if good_ic_arr .size == 0 :
251
266
LOGGER .warning ('No signal components were classified' )
252
- return None , motion_ics_out , melodic_mix_out
267
+ return None , motion_ics_out , melodic_mix_out , aroma_metadata_out
253
268
254
269
# transpose melodic_mix_arr so x refers to the correct dimension
255
270
aggr_confounds = np .asarray ([melodic_mix_arr .T [x ] for x in motion_ic_indices ])
@@ -260,7 +275,7 @@ def _get_ica_confounds(ica_out_dir, skip_vols, newpath=None):
260
275
columns = ['aroma_motion_%02d' % (x + 1 ) for x in motion_ic_indices ]).to_csv (
261
276
aroma_confounds , sep = "\t " , index = None )
262
277
263
- return aroma_confounds , motion_ics_out , melodic_mix_out
278
+ return aroma_confounds , motion_ics_out , melodic_mix_out , aroma_metadata_out
264
279
265
280
266
281
class FMRISummaryInputSpec (BaseInterfaceInputSpec ):
0 commit comments