Skip to content

Commit ce4d130

Browse files
committed
jsonise and return CompCor metadata
1 parent 6abb4da commit ce4d130

File tree

1 file changed

+43
-22
lines changed

1 file changed

+43
-22
lines changed

fmriprep/workflows/bold/confounds.py

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
)
2929
from niworkflows.interfaces.segmentation import ICA_AROMARPT
3030
from niworkflows.interfaces.utils import (
31-
TPM2ROI, AddTPMs, AddTSVHeader
31+
TPM2ROI, AddTPMs, AddTSVHeader, TSV2JSON
3232
)
3333

3434
from ...interfaces import (
@@ -131,23 +131,28 @@ def init_bold_confs_wf(mem_gb, metadata, name="bold_confs_wf"):
131131
*preprocessed BOLD* time-series (using a discrete cosine filter with
132132
128s cut-off) for the two *CompCor* variants: temporal (tCompCor)
133133
and anatomical (aCompCor).
134-
Six tCompCor components are then calculated from the top 5% variable
134+
tCompCor components are then calculated from the top 5% variable
135135
voxels within a mask covering the subcortical regions.
136136
This subcortical mask is obtained by heavily eroding the brain mask,
137137
which ensures it does not include cortical GM regions.
138-
For aCompCor, six components are calculated within the intersection of
138+
For aCompCor, components are calculated within the intersection of
139139
the aforementioned mask and the union of CSF and WM masks calculated
140140
in T1w space, after their projection to the native space of each
141141
functional run (using the inverse BOLD-to-T1w transformation).
142142
The head-motion estimates calculated in the correction step were also
143143
placed within the corresponding confounds file.
144+
The confound time series derived from head motion estimates and global
145+
signals were expanded with the inclusion of temporal derivatives and
146+
quadratic terms for each [@satterthwaite].
147+
Frames that exceeded a threshold of 0.2 mm FD or 20 DVARS were classified
148+
as motion outliers [following @power_fd_dvars].
144149
"""
145150
inputnode = pe.Node(niu.IdentityInterface(
146151
fields=['bold', 'bold_mask', 'movpar_file', 'skip_vols',
147152
't1_mask', 't1_tpms', 't1_bold_xform']),
148153
name='inputnode')
149154
outputnode = pe.Node(niu.IdentityInterface(
150-
fields=['confounds_file']),
155+
fields=['confounds_file', 'tcompcor_metadata', 'acompcor_metadata']),
151156
name='outputnode')
152157

153158
# Get masks ready in T1w space
@@ -218,6 +223,29 @@ def init_bold_confs_wf(mem_gb, metadata, name="bold_confs_wf"):
218223
name="add_motion_headers", mem_gb=0.01, run_without_submitting=True)
219224
concat = pe.Node(GatherConfounds(), name="concat", mem_gb=0.01, run_without_submitting=True)
220225

226+
# CompCor metadata
227+
tcc_metadata_fmt = pe.Node(
228+
TSV2JSON(index_column='component', drop_columns=['mask'],
229+
additional_metadata={'Method': 'tCompCor'}, enforce_case=True),
230+
name='tcc_metadata_fmt')
231+
acc_metadata_fmt = pe.Node(
232+
TSV2JSON(index_column='component', drop_columns=['mask'],
233+
additional_metadata={'Method': 'aCompCor'}, enforce_case=True),
234+
name='acc_metadata_fmt')
235+
236+
# Expand model to include derivatives and quadratics
237+
model_expand = pe.Node(ExpandModel(
238+
model_formula='(dd1(rps + wm + csf + gsr))^^2 + others'),
239+
name='model_expansion')
240+
241+
# Add spike regressors
242+
spike_regress = pe.Node(SpikeRegressors(
243+
criteria={
244+
'framewise_displacement': ('>', 0.2),
245+
'dvars': ('>', 20)
246+
}),
247+
name='spike_regressors')
248+
221249
# Generate reportlet (ROIs)
222250
mrg_compcor = pe.Node(niu.Merge(2), name='merge_compcor', run_without_submitting=True)
223251
rois_plot = pe.Node(ROIsPlot(colors=['b', 'magenta'], generate_report=True),
@@ -231,37 +259,24 @@ def init_bold_confs_wf(mem_gb, metadata, name="bold_confs_wf"):
231259
# Generate reportlet (CompCor)
232260
mrg_cc_metadata = pe.Node(niu.Merge(2), name='merge_compcor_metadata',
233261
run_without_submitting=True)
234-
compcor_plot = pe.Node(CompCorVariancePlot(
235-
variance_thresholds=(0.5, 0.7, 0.9),
236-
metadata_sources=['tCompCor', 'aCompCor']),
262+
compcor_plot = pe.Node(
263+
CompCorVariancePlot(variance_thresholds=(0.5, 0.7, 0.9),
264+
metadata_sources=['tCompCor', 'aCompCor']),
237265
name='compcor_plot')
238266
ds_report_compcor = pe.Node(
239267
DerivativesDataSink(suffix='compcor'),
240268
name='ds_report_compcor', run_without_submitting=True,
241269
mem_gb=DEFAULT_MEMORY_MIN_GB)
242270

243271
# Generate reportlet (Confound correlation)
244-
conf_corr_plot = pe.Node(ConfoundsCorrelationPlot(
245-
reference_column='global_signal'),
272+
conf_corr_plot = pe.Node(
273+
ConfoundsCorrelationPlot(reference_column='global_signal', max_dim=70),
246274
name='conf_corr_plot')
247275
ds_report_conf_corr = pe.Node(
248276
DerivativesDataSink(suffix='confounds_correlation'),
249277
name='ds_report_conf_corr', run_without_submitting=True,
250278
mem_gb=DEFAULT_MEMORY_MIN_GB)
251279

252-
# Expand model to include derivatives and quadratics
253-
model_expand = pe.Node(ExpandModel(
254-
model_formula='(dd1(rps + wm + csf + gsr))^^2 + others'),
255-
name='model_expansion')
256-
257-
# Add spike regressors
258-
spike_regress = pe.Node(SpikeRegressors(
259-
criteria={
260-
'framewise_displacement': ('>', 0.2),
261-
'dvars': ('>', 20)
262-
}),
263-
name='spike_regressors')
264-
265280
def _pick_csf(files):
266281
return files[0]
267282

@@ -334,12 +349,18 @@ def _pick_wm(files):
334349
(add_dvars_header, concat, [('out_file', 'dvars')]),
335350
(add_std_dvars_header, concat, [('out_file', 'std_dvars')]),
336351

352+
# Confounds metadata
353+
(tcompcor, tcc_metadata_fmt, [('metadata_file', 'in_file')]),
354+
(acompcor, acc_metadata_fmt, [('metadata_file', 'in_file')]),
355+
337356
# Expand the model with derivatives, quadratics, and spikes
338357
(concat, model_expand, [('confounds_file', 'confounds_file')]),
339358
(model_expand, spike_regress, [('confounds_file', 'confounds_file')]),
340359

341360
# Set outputs
342361
(spike_regress, outputnode, [('confounds_file', 'confounds_file')]),
362+
(tcc_metadata_fmt, outputnode, [('out_file', 'tcompcor_metadata')]),
363+
(acc_metadata_fmt, outputnode, [('out_file', 'acompcor_metadata')]),
343364
(inputnode, rois_plot, [('bold', 'in_file'),
344365
('bold_mask', 'in_mask')]),
345366
(tcompcor, mrg_compcor, [('high_variance_masks', 'in1')]),

0 commit comments

Comments
 (0)