3232def init_nibetaseries_participant_wf (
3333 estimator , atlas_img , atlas_lut , bids_dir ,
3434 database_path , derivatives_pipeline_dir , exclude_description_label ,
35- fir_delays , hrf_model , high_pass , norm_betas , output_dir , run_label ,
36- selected_confounds , session_label , signal_scaling , smoothing_kernel ,
35+ fir_delays , hrf_model , high_pass , norm_betas , output_dir , return_residuals ,
36+ run_label , selected_confounds , session_label , signal_scaling , smoothing_kernel ,
3737 space_label , subject_list , task_label , description_label , work_dir ,
3838 ):
3939
@@ -67,6 +67,9 @@ def init_nibetaseries_participant_wf(
6767 If True, beta estimates are divided by the square root of their variance
6868 output_dir : str
6969 Directory where derivatives are saved
70+ return_residuals : bool
71+ Output the residuals from the betaseries model into the
72+ derivatives directory
7073 run_label : str or None
7174 Include bold series containing this run label
7275 selected_confounds : list
@@ -177,6 +180,7 @@ def init_nibetaseries_participant_wf(
177180 norm_betas = norm_betas ,
178181 output_dir = output_dir ,
179182 preproc_img_list = preproc_img_list ,
183+ return_residuals = return_residuals ,
180184 selected_confounds = selected_confounds ,
181185 signal_scaling = signal_scaling ,
182186 smoothing_kernel = smoothing_kernel ,
@@ -197,8 +201,8 @@ def init_nibetaseries_participant_wf(
197201def init_single_subject_wf (
198202 estimator , atlas_img , atlas_lut , bold_metadata_list , brainmask_list ,
199203 confound_tsv_list , events_tsv_list , fir_delays , hrf_model , high_pass ,
200- name , norm_betas , output_dir , preproc_img_list , selected_confounds ,
201- signal_scaling , smoothing_kernel ,
204+ name , norm_betas , output_dir , preproc_img_list , return_residuals ,
205+ selected_confounds , signal_scaling , smoothing_kernel ,
202206 ):
203207 """
204208 This workflow completes the generation of the betaseries files
@@ -257,6 +261,9 @@ def init_single_subject_wf(
257261 Directory where derivatives are saved
258262 preproc_img_list : list
259263 list of preprocessed bold files
264+ return_residuals : bool
265+ Output the residuals from the betaseries model into the
266+ derivatives directory
260267 selected_confounds : list or None
261268 the list of confounds to be included in regression
262269 signal_scaling : False or 0
@@ -311,7 +318,8 @@ def init_single_subject_wf(
311318
312319 output_node = pe .Node (niu .IdentityInterface (fields = ['correlation_matrix' ,
313320 'correlation_fig' ,
314- 'betaseries_file' ]),
321+ 'betaseries_file' ,
322+ 'residual_file' ]),
315323 name = 'output_node' )
316324
317325 # initialize the betaseries workflow
@@ -389,6 +397,20 @@ def init_single_subject_wf(
389397 (output_node , ds_correlation_fig , [('correlation_fig' , 'in_file' )]),
390398 ])
391399
400+ if return_residuals :
401+ ds_residual_file = pe .MapNode (DerivativesDataSink (base_directory = output_dir ),
402+ iterfield = ['in_file' ],
403+ name = 'ds_residual_file' )
404+
405+ workflow .connect ([
406+ (betaseries_wf , output_node ,
407+ [('output_node.residual_file' , 'residual_file' )]),
408+ (output_node , ds_residual_file ,
409+ [('residual_file' , 'in_file' )]),
410+ (input_node , ds_residual_file ,
411+ [('preproc_img' , 'source_file' )]),
412+ ])
413+
392414 return workflow
393415
394416
0 commit comments