Skip to content

Commit 5220ea4

Browse files
rciricoesteban
authored andcommitted
(enh) (#1618) pass ICA-AROMA metadata TSV forward
1 parent 84f34a6 commit 5220ea4

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

fmriprep/interfaces/confounds.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class ICAConfoundsOutputSpec(TraitedSpec):
107107
File(exists=True, desc='output confounds file extracted from ICA-AROMA'))
108108
aroma_noise_ics = File(exists=True, desc='ICA-AROMA noise components')
109109
melodic_mix = File(exists=True, desc='melodic mix file')
110+
aroma_metadata = File(exists=True, desc='tabulated ICA-AROMA metadata')
110111

111112

112113
class ICAConfounds(SimpleInterface):
@@ -116,8 +117,10 @@ class ICAConfounds(SimpleInterface):
116117
output_spec = ICAConfoundsOutputSpec
117118

118119
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)
121124

122125
if self.inputs.err_on_aroma_warn and aroma_confounds is None:
123126
raise RuntimeError('ICA-AROMA failed')
@@ -126,6 +129,7 @@ def _run_interface(self, runtime):
126129

127130
self._results['aroma_noise_ics'] = motion_ics_out
128131
self._results['melodic_mix'] = melodic_mix_out
132+
self._results['aroma_metadata'] = aroma_metadata
129133
return runtime
130134

131135

@@ -218,10 +222,12 @@ def _get_ica_confounds(ica_out_dir, skip_vols, newpath=None):
218222
# load the txt files from ICA-AROMA
219223
melodic_mix = os.path.join(ica_out_dir, 'melodic.ica/melodic_mix')
220224
motion_ics = os.path.join(ica_out_dir, 'classified_motion_ICs.txt')
225+
aroma_metadata = os.path.join(ica_out_dir, 'classification_overview.txt')
221226

222227
# Change names of motion_ics and melodic_mix for output
223228
melodic_mix_out = os.path.join(newpath, 'MELODICmix.tsv')
224229
motion_ics_out = os.path.join(newpath, 'AROMAnoiseICs.csv')
230+
aroma_metadata_out = os.path.join(newpath, 'classification_overview.tsv')
225231

226232
# copy metion_ics file to derivatives name
227233
shutil.copyfile(motion_ics, motion_ics_out)
@@ -238,18 +244,27 @@ def _get_ica_confounds(ica_out_dir, skip_vols, newpath=None):
238244
# save melodic_mix_arr
239245
np.savetxt(melodic_mix_out, melodic_mix_arr, delimiter='\t')
240246

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+
241256
# Return dummy list of ones if no noise compnents were found
242257
if motion_ic_indices.size == 0:
243258
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
245260

246261
# the "good" ics, (e.g., not motion related)
247262
good_ic_arr = np.delete(melodic_mix_arr, motion_ic_indices, 1).T
248263

249264
# return dummy lists of zeros if no signal components were found
250265
if good_ic_arr.size == 0:
251266
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
253268

254269
# transpose melodic_mix_arr so x refers to the correct dimension
255270
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):
260275
columns=['aroma_motion_%02d' % (x + 1) for x in motion_ic_indices]).to_csv(
261276
aroma_confounds, sep="\t", index=None)
262277

263-
return aroma_confounds, motion_ics_out, melodic_mix_out
278+
return aroma_confounds, motion_ics_out, melodic_mix_out, aroma_metadata_out
264279

265280

266281
class FMRISummaryInputSpec(BaseInterfaceInputSpec):

0 commit comments

Comments
 (0)