Skip to content

Commit db5cd76

Browse files
committed
reordered spm conn preprocessing
1 parent 7c0f4d6 commit db5cd76

File tree

1 file changed

+23
-41
lines changed

1 file changed

+23
-41
lines changed

examples/rsfmri_conn_spm_preprocessing.py

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,8 @@ def create_workflow(files,
361361
(segment, normalize_func, [('transformation_mat', 'parameter_file')]),
362362
(realign, slice_timing, [('realigned_files', 'in_files')]),
363363
(slice_timing, normalize_func, [('timecorrected_files', 'apply_to_files')]),
364-
(normalize_func, smooth, [('normalized_files', 'in_files')]),
364+
(normalize_func, art, [('normalized_files', 'realigned_files')]),
365365
(realign, art, [('realignment_parameters', 'realignment_parameters')]),
366-
(smooth, art, [('smoothed_files', 'realigned_files')]),
367366
])
368367

369368
def selectN(files, N=1):
@@ -428,7 +427,7 @@ def merge_files(in1, in2):
428427
wf.connect(art, 'norm_files', createfilter1, 'comp_norm')
429428
wf.connect(art, 'outlier_files', createfilter1, 'outliers')
430429

431-
# Filter the motion and art confounds and detrend
430+
432431
filter1 = MapNode(fsl.GLM(out_f_name='F_mcart.nii',
433432
out_pf_name='pF_mcart.nii',
434433
demean=True),
@@ -439,9 +438,8 @@ def merge_files(in1, in2):
439438
wf.connect(normalize_func, ('normalized_files', rename, '_filtermotart'),
440439
filter1, 'out_res_name')
441440
wf.connect(createfilter1, 'out_files', filter1, 'design')
442-
#wf.connect(masktransform, 'transformed_file', filter1, 'mask')
443441

444-
# Create a filter to remove noise components based on white matter and CSF
442+
445443
createfilter2 = MapNode(Function(input_names=['realigned_file', 'mask_file',
446444
'num_components',
447445
'extra_regressors'],
@@ -450,58 +448,44 @@ def merge_files(in1, in2):
450448
imports=imports),
451449
iterfield=['realigned_file', 'extra_regressors'],
452450
name='makecompcorrfilter')
453-
createfilter2.inputs.num_components = num_components
451+
createfilter2.inputs.num_components = 5
452+
454453
wf.connect(createfilter1, 'out_files', createfilter2, 'extra_regressors')
455454
wf.connect(filter1, 'out_res', createfilter2, 'realigned_file')
456-
wf.connect(bin_and_erode, ('out_file', selectN, 2), createfilter2, 'mask_file')
455+
wf.connect(bin_and_erode, 'out_file', createfilter2, 'mask_file')
456+
457457

458-
# Filter noise components from unsmoothed data
459458
filter2 = MapNode(fsl.GLM(out_f_name='F.nii',
460459
out_pf_name='pF.nii',
461460
demean=True),
462461
iterfield=['in_file', 'design', 'out_res_name'],
463462
name='filter_noise_nosmooth')
464-
wf.connect(normalize_func, 'normalized_files', filter2, 'in_file')
465-
wf.connect(normalize_func, ('normalized_files', rename, '_unsmooth_cleaned'),
463+
wf.connect(filter1, 'out_res', filter2, 'in_file')
464+
wf.connect(filter1, ('out_res', rename, '_unsmooth_cleaned'),
466465
filter2, 'out_res_name')
467466
wf.connect(createfilter2, 'out_files', filter2, 'design')
468-
wf.connect(mask, 'mask_file', filter2, 'mask')
469467

470-
# Filter noise components from smoothed data
471-
filter3 = MapNode(fsl.GLM(out_f_name='F.nii',
472-
out_pf_name='pF.nii',
473-
demean=True),
474-
iterfield=['in_file', 'design', 'out_res_name'],
475-
name='filter_noise_smooth')
476-
wf.connect(smooth, ('smoothed_files', rename, '_cleaned'),
477-
filter3, 'out_res_name')
478-
wf.connect(smooth, 'smoothed_files', filter3, 'in_file')
479-
wf.connect(createfilter2, 'out_files', filter3, 'design')
480-
wf.connect(mask, 'mask_file', filter3, 'mask')
481-
482-
# Bandpass filter the data
483-
bandpass1 = Node(Function(input_names=['files', 'lowpass_freq',
468+
469+
bandpass = Node(Function(input_names=['files', 'lowpass_freq',
484470
'highpass_freq', 'fs'],
485471
output_names=['out_files'],
486472
function=bandpass_filter,
487473
imports=imports),
488474
name='bandpass_unsmooth')
489-
bandpass1.inputs.fs = 1./TR
475+
bandpass.inputs.fs = 1./TR
476+
bandpass.inputs.highpass_freq = highpass_freq
477+
bandpass.inputs.lowpass_freq = lowpass_freq
478+
wf.connect(filter2, 'out_res', bandpass, 'files')
490479

491-
bandpass1.inputs.highpass_freq = highpass_freq
492-
bandpass1.inputs.lowpass_freq = lowpass_freq
493-
wf.connect(filter2, 'out_res', bandpass1, 'files')
494480

495-
bandpass2 = bandpass1.clone(name='bandpass_smooth')
496-
wf.connect(filter3, 'out_res', bandpass2, 'files')
481+
wf.connect(bandpass, 'out_files', smooth, 'in_files')
482+
483+
484+
collector = Node(Merge(2), name='collect_streams')
485+
wf.connect(smooth, 'smoothed_files', collector, 'in1')
486+
wf.connect(bandpass, 'out_files', collector, 'in2')
487+
497488

498-
bandpass = Node(Function(input_names=['in1', 'in2'],
499-
output_names=['out_file'],
500-
function=merge_files,
501-
imports=imports),
502-
name='bandpass_merge')
503-
wf.connect(bandpass1, 'out_files', bandpass, 'in1')
504-
wf.connect(bandpass2, 'out_files', bandpass, 'in2')
505489

506490
# Save the relevant data into an output directory
507491
datasink = Node(interface=DataSink(), name="datasink")
@@ -513,16 +497,14 @@ def merge_files(in1, in2):
513497
wf.connect(art, 'norm_files', datasink, 'resting.qa.art.@norm')
514498
wf.connect(art, 'intensity_files', datasink, 'resting.qa.art.@intensity')
515499
wf.connect(art, 'outlier_files', datasink, 'resting.qa.art.@outlier_files')
516-
wf.connect(smooth, 'smoothed_files', datasink, 'resting.timeseries.fullpass')
517500
wf.connect(bin_and_erode, 'out_file', datasink, 'resting.mask_files')
518501
wf.connect(mask, 'mask_file', datasink, 'resting.mask_files.@brainmask')
519502
wf.connect(filter1, 'out_f', datasink, 'resting.qa.compmaps.@mc_F')
520503
wf.connect(filter1, 'out_pf', datasink, 'resting.qa.compmaps.@mc_pF')
521504
wf.connect(filter2, 'out_f', datasink, 'resting.qa.compmaps')
522505
wf.connect(filter2, 'out_pf', datasink, 'resting.qa.compmaps.@p')
523-
wf.connect(filter3, 'out_f', datasink, 'resting.qa.compmaps.@sF')
524-
wf.connect(filter3, 'out_pf', datasink, 'resting.qa.compmaps.@sp')
525506
wf.connect(bandpass, 'out_file', datasink, 'resting.timeseries.bandpassed')
507+
wf.connect(smooth, 'smoothed_files', datasink, 'resting.timeseries.smoothed')
526508
wf.connect(createfilter1, 'out_files',
527509
datasink, 'resting.regress.@regressors')
528510
wf.connect(createfilter2, 'out_files',

0 commit comments

Comments
 (0)