15
15
16
16
from niworkflows .data import get_template
17
17
from niworkflows .engine .workflows import LiterateWorkflow as Workflow
18
+ from niworkflows .interfaces .confounds import ExpandModel , SpikeRegressors
18
19
from niworkflows .interfaces .fixes import FixHeaderApplyTransforms as ApplyTransforms
19
20
from niworkflows .interfaces .images import SignalExtraction
20
21
from niworkflows .interfaces .masks import ROIsPlot
21
22
from niworkflows .interfaces .patches import (
22
23
RobustACompCor as ACompCor ,
23
24
RobustTCompCor as TCompCor ,
24
25
)
26
+ from niworkflows .interfaces .plotting import (
27
+ CompCorVariancePlot , ConfoundsCorrelationPlot
28
+ )
25
29
from niworkflows .interfaces .segmentation import ICA_AROMARPT
26
30
from niworkflows .interfaces .utils import (
27
31
TPM2ROI , AddTPMs , AddTSVHeader
@@ -183,12 +187,13 @@ def init_bold_confs_wf(mem_gb, metadata, name="bold_confs_wf"):
183
187
# a/t-CompCor
184
188
tcompcor = pe .Node (
185
189
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 ),
187
192
name = "tcompcor" , mem_gb = mem_gb )
188
193
189
194
acompcor = pe .Node (
190
195
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 ),
192
197
name = "acompcor" , mem_gb = mem_gb )
193
198
194
199
# Set TR if present
@@ -213,7 +218,7 @@ def init_bold_confs_wf(mem_gb, metadata, name="bold_confs_wf"):
213
218
name = "add_motion_headers" , mem_gb = 0.01 , run_without_submitting = True )
214
219
concat = pe .Node (GatherConfounds (), name = "concat" , mem_gb = 0.01 , run_without_submitting = True )
215
220
216
- # Generate reportlet
221
+ # Generate reportlet (ROIs)
217
222
mrg_compcor = pe .Node (niu .Merge (2 ), name = 'merge_compcor' , run_without_submitting = True )
218
223
rois_plot = pe .Node (ROIsPlot (colors = ['b' , 'magenta' ], generate_report = True ),
219
224
name = 'rois_plot' , mem_gb = mem_gb )
@@ -223,6 +228,40 @@ def init_bold_confs_wf(mem_gb, metadata, name="bold_confs_wf"):
223
228
name = 'ds_report_bold_rois' , run_without_submitting = True ,
224
229
mem_gb = DEFAULT_MEMORY_MIN_GB )
225
230
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
+
226
265
def _pick_csf (files ):
227
266
return files [0 ]
228
267
@@ -295,14 +334,24 @@ def _pick_wm(files):
295
334
(add_dvars_header , concat , [('out_file' , 'dvars' )]),
296
335
(add_std_dvars_header , concat , [('out_file' , 'std_dvars' )]),
297
336
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
+
298
341
# Set outputs
299
- (concat , outputnode , [('confounds_file' , 'confounds_file' )]),
342
+ (spike_regress , outputnode , [('confounds_file' , 'confounds_file' )]),
300
343
(inputnode , rois_plot , [('bold' , 'in_file' ),
301
344
('bold_mask' , 'in_mask' )]),
302
345
(tcompcor , mrg_compcor , [('high_variance_masks' , 'in1' )]),
303
346
(acc_msk , mrg_compcor , [('out' , 'in2' )]),
304
347
(mrg_compcor , rois_plot , [('out' , 'in_rois' )]),
305
348
(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' )]),
306
355
])
307
356
308
357
return workflow
0 commit comments