Skip to content

Commit 06aeb1b

Browse files
committed
fix: cleaned up datasink
1 parent 3da0eda commit 06aeb1b

File tree

3 files changed

+25
-970
lines changed

3 files changed

+25
-970
lines changed

examples/rsfmri_conn_ants_fs_preprocessing.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ def extract_subrois(timeseries_file, label_file, indices):
298298
data = img.get_data()
299299
roiimg = nb.load(label_file)
300300
rois = roiimg.get_data()
301-
out_ts_file = os.path.join(os.getcwd(), 'subcortical_timeseries.txt')
301+
prefix = split_filename(timeseries_file)[1]
302+
out_ts_file = os.path.join(os.getcwd(), '%s_subcortical_ts.txt' % prefix)
302303
with open(out_ts_file, 'wt') as fp:
303304
for fsindex in indices:
304305
ijk = np.nonzero(rois == fsindex)
@@ -849,12 +850,28 @@ def get_names(files, suffix):
849850

850851
######
851852

853+
substitutions = [('_target_subject_', ''),
854+
('_filtermotart_cleaned_bp_trans_masked', ''),
855+
('_filtermotart_cleaned_bp', '')
856+
]
857+
regex_subs = [('_ts_masker.*/sar', '/smooth/'),
858+
('_ts_masker.*/ar', '/unsmooth/'),
859+
('_combiner.*/sar', '/smooth/'),
860+
('_combiner.*/ar', '/unsmooth/'),
861+
('_aparc_ts.*/sar', '/smooth/'),
862+
('_aparc_ts.*/ar', '/unsmooth/'),
863+
('_getsubcortts.*/sar', '/smooth/'),
864+
('_getsubcortts.*/ar', '/unsmooth/'),
865+
('series/sar', 'series/smooth/'),
866+
('series/ar', 'series/unsmooth/'),
867+
('_inverse_transform./', ''),
868+
]
852869
# Save the relevant data into an output directory
853870
datasink = Node(interface=DataSink(), name="datasink")
854871
datasink.inputs.base_directory = sink_directory
855872
datasink.inputs.container = subject_id
856-
datasink.inputs.substitutions = [('_target_subject_', '')]
857-
#datasink.inputs.regexp_substitutions = (r'(/_.*(\d+/))', r'/run\2')
873+
datasink.inputs.substitutions = substitutions
874+
datasink.inputs.regexp_substitutions = regex_subs #(r'(/_.*(\d+/))', r'/run\2')
858875
wf.connect(realign, 'realignment_parameters', datasink, 'resting.qa.motion')
859876
wf.connect(art, 'norm_files', datasink, 'resting.qa.art.@norm')
860877
wf.connect(art, 'intensity_files', datasink, 'resting.qa.art.@intensity')
@@ -867,8 +884,8 @@ def get_names(files, suffix):
867884
wf.connect(filter1, 'out_pf', datasink, 'resting.qa.compmaps.@mc_pF')
868885
wf.connect(filter2, 'out_f', datasink, 'resting.qa.compmaps')
869886
wf.connect(filter2, 'out_pf', datasink, 'resting.qa.compmaps.@p')
870-
wf.connect(bandpass, 'out_files', datasink, 'resting.timeseries.bandpassed')
871-
wf.connect(smooth, 'smoothed_files', datasink, 'resting.timeseries.smoothed')
887+
wf.connect(bandpass, 'out_files', datasink, 'resting.timeseries.@bandpassed')
888+
wf.connect(smooth, 'smoothed_files', datasink, 'resting.timeseries.@smoothed')
872889
wf.connect(createfilter1, 'out_files',
873890
datasink, 'resting.regress.@regressors')
874891
wf.connect(createfilter2, 'out_files',
@@ -884,8 +901,8 @@ def get_names(files, suffix):
884901
datasink2 = Node(interface=DataSink(), name="datasink2")
885902
datasink2.inputs.base_directory = sink_directory
886903
datasink2.inputs.container = subject_id
887-
datasink2.inputs.substitutions = [('_target_subject_', '')]
888-
#datasink2.inputs.regexp_substitutions = (r'(/_.*(\d+/))', r'/run\2')
904+
datasink2.inputs.substitutions = substitutions
905+
datasink2.inputs.regexp_substitutions = regex_subs #(r'(/_.*(\d+/))', r'/run\2')
889906
wf.connect(combiner, 'out_file',
890907
datasink2, 'resting.parcellations.grayo.@surface')
891908
return wf

0 commit comments

Comments
 (0)