Skip to content

Commit 513be36

Browse files
committed
(#1458) sketch CompCor enhancement
1 parent 57c3a55 commit 513be36

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

fmriprep/workflows/bold/confounds.py

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515

1616
from niworkflows.data import get_template
1717
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
18+
from niworkflows.interfaces.confounds import ExpandModel, SpikeRegressors
1819
from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms
1920
from niworkflows.interfaces.images import SignalExtraction
2021
from niworkflows.interfaces.masks import ROIsPlot
2122
from niworkflows.interfaces.patches import (
2223
RobustACompCor as ACompCor,
2324
RobustTCompCor as TCompCor,
2425
)
26+
from niworkflows.interfaces.plotting import (
27+
CompCorVariancePlot, ConfoundsCorrelationPlot
28+
)
2529
from niworkflows.interfaces.segmentation import ICA_AROMARPT
2630
from niworkflows.interfaces.utils import (
2731
TPM2ROI, AddTPMs, AddTSVHeader
@@ -183,12 +187,13 @@ def init_bold_confs_wf(mem_gb, metadata, name="bold_confs_wf"):
183187
# a/t-CompCor
184188
tcompcor = pe.Node(
185189
TCompCor(components_file='tcompcor.tsv', header_prefix='t_comp_cor_', pre_filter='cosine',
186-
save_pre_filter=True, percentile_threshold=.05),
190+
save_pre_filter=True, num_components='all', save_metadata=True,
191+
percentile_threshold=.05),
187192
name="tcompcor", mem_gb=mem_gb)
188193

189194
acompcor = pe.Node(
190195
ACompCor(components_file='acompcor.tsv', header_prefix='a_comp_cor_', pre_filter='cosine',
191-
save_pre_filter=True),
196+
save_pre_filter=True, num_components='all', save_metadata=True),
192197
name="acompcor", mem_gb=mem_gb)
193198

194199
# Set TR if present
@@ -213,7 +218,7 @@ def init_bold_confs_wf(mem_gb, metadata, name="bold_confs_wf"):
213218
name="add_motion_headers", mem_gb=0.01, run_without_submitting=True)
214219
concat = pe.Node(GatherConfounds(), name="concat", mem_gb=0.01, run_without_submitting=True)
215220

216-
# Generate reportlet
221+
# Generate reportlet (ROIs)
217222
mrg_compcor = pe.Node(niu.Merge(2), name='merge_compcor', run_without_submitting=True)
218223
rois_plot = pe.Node(ROIsPlot(colors=['b', 'magenta'], generate_report=True),
219224
name='rois_plot', mem_gb=mem_gb)
@@ -223,6 +228,40 @@ def init_bold_confs_wf(mem_gb, metadata, name="bold_confs_wf"):
223228
name='ds_report_bold_rois', run_without_submitting=True,
224229
mem_gb=DEFAULT_MEMORY_MIN_GB)
225230

231+
# Generate reportlet (CompCor)
232+
mrg_cc_metadata = pe.Node(niu.Merge(2), name='merge_compcor_metadata',
233+
run_without_submitting=True)
234+
compcor_plot = pe.Node(CompCorVariancePlot(
235+
variance_thresholds=(0.5, 0.7, 0.9),
236+
metadata_sources=['tCompCor', 'aCompCor']),
237+
name='compcor_plot')
238+
ds_report_compcor = pe.Node(
239+
DerivativesDataSink(suffix='compcor'),
240+
name='ds_report_compcor', run_without_submitting=True,
241+
mem_gb=DEFAULT_MEMORY_MIN_GB)
242+
243+
# Generate reportlet (Confound correlation)
244+
conf_corr_plot = pe.Node(ConfoundsCorrelationPlot(
245+
reference_column='global_signal'),
246+
name='conf_corr_plot')
247+
ds_report_conf_corr = pe.Node(
248+
DerivativesDataSink(suffix='confounds_correlation'),
249+
name='ds_report_conf_corr', run_without_submitting=True,
250+
mem_gb=DEFAULT_MEMORY_MIN_GB)
251+
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+
226265
def _pick_csf(files):
227266
return files[0]
228267

@@ -295,14 +334,24 @@ def _pick_wm(files):
295334
(add_dvars_header, concat, [('out_file', 'dvars')]),
296335
(add_std_dvars_header, concat, [('out_file', 'std_dvars')]),
297336

337+
# Expand the model with derivatives, quadratics, and spikes
338+
(concat, model_expand, [('confounds_file', 'confounds_file')]),
339+
(model_expand, spike_regress, [('confounds_file', 'confounds_file')]),
340+
298341
# Set outputs
299-
(concat, outputnode, [('confounds_file', 'confounds_file')]),
342+
(spike_regress, outputnode, [('confounds_file', 'confounds_file')]),
300343
(inputnode, rois_plot, [('bold', 'in_file'),
301344
('bold_mask', 'in_mask')]),
302345
(tcompcor, mrg_compcor, [('high_variance_masks', 'in1')]),
303346
(acc_msk, mrg_compcor, [('out', 'in2')]),
304347
(mrg_compcor, rois_plot, [('out', 'in_rois')]),
305348
(rois_plot, ds_report_bold_rois, [('out_report', 'in_file')]),
349+
(tcompcor, mrg_cc_metadata, [('metadata_file', 'in1')]),
350+
(acompcor, mrg_cc_metadata, [('metadata_file', 'in2')]),
351+
(mrg_cc_metadata, compcor_plot, [('out', 'metadata_files')]),
352+
(compcor_plot, ds_report_compcor, [('out_file', 'in_file')]),
353+
(concat, conf_corr_plot, [('confounds_file', 'confounds_file')]),
354+
(conf_corr_plot, ds_report_conf_corr, [('out_file', 'in_file')]),
306355
])
307356

308357
return workflow

0 commit comments

Comments
 (0)