Skip to content

Commit 531e6e9

Browse files
committed
enh: added datasink
1 parent a37f67a commit 531e6e9

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

examples/rsfmri_conn_spm_preprocessing.py

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
from nipype.algorithms.rapidart import ArtifactDetect
6464
from nipype.interfaces.utility import Rename
6565
from nipype.utils.filemanip import filename_to_list
66+
from nipype.interfaces.io import DataSink
6667

6768
import numpy as np
6869
import scipy as sp
@@ -497,16 +498,43 @@ def merge_files(in1, in2):
497498
wf.connect(bandpass1, 'out_files', bandpass, 'in1')
498499
wf.connect(bandpass2, 'out_files', bandpass, 'in2')
499500

501+
# Save the relevant data into an output directory
502+
datasink = Node(interface=DataSink(), name="datasink")
503+
datasink.inputs.base_directory = sink_directory
504+
datasink.inputs.container = subject_id
505+
#datasink.inputs.substitutions = [('_target_subject_', '')]
506+
#datasink.inputs.regexp_substitutions = (r'(/_.*(\d+/))', r'/run\2')
507+
wf.connect(realign, 'par_file', datasink, 'resting.qa.motion')
508+
wf.connect(art, 'norm_files', datasink, 'resting.qa.art.@norm')
509+
wf.connect(art, 'intensity_files', datasink, 'resting.qa.art.@intensity')
510+
wf.connect(art, 'outlier_files', datasink, 'resting.qa.art.@outlier_files')
511+
wf.connect(smooth, 'out_file', datasink, 'resting.timeseries.fullpass')
512+
wf.connect(bin_and_erode, 'out_file', datasink, 'resting.mask_files')
513+
wf.connect(filter1, 'out_f', datasink, 'resting.qa.compmaps.@mc_F')
514+
wf.connect(filter1, 'out_pf', datasink, 'resting.qa.compmaps.@mc_pF')
515+
wf.connect(filter2, 'out_f', datasink, 'resting.qa.compmaps')
516+
wf.connect(filter2, 'out_pf', datasink, 'resting.qa.compmaps.@p')
517+
wf.connect(filter3, 'out_f', datasink, 'resting.qa.compmaps.@sF')
518+
wf.connect(filter3, 'out_pf', datasink, 'resting.qa.compmaps.@sp')
519+
wf.connect(bandpass, 'out_file', datasink, 'resting.timeseries.bandpassed')
520+
wf.connect(createfilter1, 'out_files',
521+
datasink, 'resting.regress.@regressors')
522+
wf.connect(createfilter2, 'out_files',
523+
datasink, 'resting.regress.@compcorr')
500524
return wf
501525

502526

503-
from glob import glob
527+
if __name__ == "__main__":
528+
from glob import glob
529+
530+
subj_id = 'SUB_1024011'
531+
files = sorted(glob(os.path.abspath('%s/E?/func/rest.nii' % subj_id)))
532+
anat_file = glob(os.path.abspath('%s/EO/anat/anat.nii' % subj_id))[0]
533+
wf = create_workflow(files, anat_file, subj_id, 2.0, 33, vol_fwhm=6.0,
534+
lowpass_freq=0.1, highpass_freq=0.01,
535+
sink_directory=os.getcwd(),
536+
name='resting_' + subj_id)
537+
wf.base_dir = os.getcwd()
538+
#wf.run(plugin='MultiProc', plugin_args={'nprocs': 4})
539+
wf.run()
504540

505-
subj_id = 'SUB_1024011'
506-
files = sorted(glob(os.path.abspath('%s/E?/func/rest.nii' % subj_id)))
507-
anat_file = glob(os.path.abspath('%s/EO/anat/anat.nii' % subj_id))[0]
508-
wf = create_workflow(files, anat_file, subj_id, 2.0, 33, vol_fwhm=6.0,
509-
lowpass_freq=0.1, highpass_freq=0.01)
510-
wf.base_dir = os.getcwd()
511-
#wf.run(plugin='MultiProc', plugin_args={'nprocs': 4})
512-
wf.run()

0 commit comments

Comments
 (0)