@@ -110,11 +110,11 @@ def create_reg_workflow(name='registration'):
110
110
register = pe .Workflow (name = name )
111
111
112
112
inputnode = pe .Node (interface = niu .IdentityInterface (fields = ['source_files' ,
113
- 'mean_image' ,
114
- 'anatomical_image' ,
115
- 'target_image' ,
116
- 'target_image_brain' ,
117
- 'config_file' ]),
113
+ 'mean_image' ,
114
+ 'anatomical_image' ,
115
+ 'target_image' ,
116
+ 'target_image_brain' ,
117
+ 'config_file' ]),
118
118
name = 'inputspec' )
119
119
outputnode = pe .Node (interface = niu .IdentityInterface (fields = ['func2anat_transform' ,
120
120
'anat2target_transform' ,
@@ -185,7 +185,7 @@ def create_reg_workflow(name='registration'):
185
185
convert2itk .inputs .fsl2ras = True
186
186
convert2itk .inputs .itk_transform = True
187
187
register .connect (mean2anatbbr , 'out_matrix_file' , convert2itk , 'transform_file' )
188
- register .connect (inputnode , 'mean_image' ,convert2itk , 'source_file' )
188
+ register .connect (inputnode , 'mean_image' , convert2itk , 'source_file' )
189
189
register .connect (stripper , 'out_file' , convert2itk , 'reference_file' )
190
190
191
191
"""
@@ -226,7 +226,7 @@ def create_reg_workflow(name='registration'):
226
226
reg .plugin_args = {'qsub_args' : '-pe orte 4' ,
227
227
'sbatch_args' : '--mem=6G -c 4' }
228
228
register .connect (stripper , 'out_file' , reg , 'moving_image' )
229
- register .connect (inputnode ,'target_image_brain' , reg ,'fixed_image' )
229
+ register .connect (inputnode , 'target_image_brain' , reg , 'fixed_image' )
230
230
231
231
"""
232
232
Concatenate the affine and ants transforms into a list
@@ -249,7 +249,7 @@ def create_reg_workflow(name='registration'):
249
249
warpmean .inputs .invert_transform_flags = [False , False ]
250
250
warpmean .inputs .terminal_output = 'file'
251
251
252
- register .connect (inputnode ,'target_image_brain' , warpmean ,'reference_image' )
252
+ register .connect (inputnode , 'target_image_brain' , warpmean , 'reference_image' )
253
253
register .connect (inputnode , 'mean_image' , warpmean , 'input_image' )
254
254
register .connect (merge , 'out' , warpmean , 'transforms' )
255
255
@@ -265,8 +265,8 @@ def create_reg_workflow(name='registration'):
265
265
warpall .inputs .invert_transform_flags = [False , False ]
266
266
warpall .inputs .terminal_output = 'file'
267
267
268
- register .connect (inputnode ,'target_image_brain' ,warpall ,'reference_image' )
269
- register .connect (inputnode ,'source_files' , warpall , 'input_image' )
268
+ register .connect (inputnode , 'target_image_brain' , warpall , 'reference_image' )
269
+ register .connect (inputnode , 'source_files' , warpall , 'input_image' )
270
270
register .connect (merge , 'out' , warpall , 'transforms' )
271
271
272
272
"""
@@ -515,6 +515,7 @@ def create_fs_reg_workflow(name='registration'):
515
515
Get info for a given subject
516
516
"""
517
517
518
+
518
519
def get_subjectinfo (subject_id , base_dir , task_id , model_id ):
519
520
"""Get info for a given subject
520
521
@@ -559,7 +560,7 @@ def get_subjectinfo(subject_id, base_dir, task_id, model_id):
559
560
for idx in range (n_tasks ):
560
561
taskidx = np .where (taskinfo [:, 0 ] == 'task%03d' % (idx + 1 ))
561
562
conds .append ([condition .replace (' ' , '_' ) for condition
562
- in taskinfo [taskidx [0 ], 2 ]]) # if 'junk' not in condition])
563
+ in taskinfo [taskidx [0 ], 2 ]]) # if 'junk' not in condition])
563
564
files = sorted (glob (os .path .join (base_dir ,
564
565
subject_id ,
565
566
'BOLD' ,
@@ -588,6 +589,7 @@ def get_subjectinfo(subject_id, base_dir, task_id, model_id):
588
589
Analyzes an open fmri dataset
589
590
"""
590
591
592
+
591
593
def analyze_openfmri_dataset (data_dir , subject = None , model_id = None ,
592
594
task_id = None , output_dir = None , subj_prefix = '*' ,
593
595
hpcutoff = 120. , use_derivatives = True ,
@@ -661,15 +663,15 @@ def analyze_openfmri_dataset(data_dir, subject=None, model_id=None,
661
663
has_contrast = os .path .exists (contrast_file )
662
664
if has_contrast :
663
665
datasource = pe .Node (nio .DataGrabber (infields = ['subject_id' , 'run_id' ,
664
- 'task_id' , 'model_id' ],
665
- outfields = ['anat' , 'bold' , 'behav' ,
666
- 'contrasts' ]),
667
- name = 'datasource' )
666
+ 'task_id' , 'model_id' ],
667
+ outfields = ['anat' , 'bold' , 'behav' ,
668
+ 'contrasts' ]),
669
+ name = 'datasource' )
668
670
else :
669
671
datasource = pe .Node (nio .DataGrabber (infields = ['subject_id' , 'run_id' ,
670
- 'task_id' , 'model_id' ],
671
- outfields = ['anat' , 'bold' , 'behav' ]),
672
- name = 'datasource' )
672
+ 'task_id' , 'model_id' ],
673
+ outfields = ['anat' , 'bold' , 'behav' ]),
674
+ name = 'datasource' )
673
675
datasource .inputs .base_directory = data_dir
674
676
datasource .inputs .template = '*'
675
677
@@ -681,19 +683,19 @@ def analyze_openfmri_dataset(data_dir, subject=None, model_id=None,
681
683
'contrasts' : ('models/model%03d/'
682
684
'task_contrasts.txt' )}
683
685
datasource .inputs .template_args = {'anat' : [['subject_id' ]],
684
- 'bold' : [['subject_id' , 'task_id' ]],
685
- 'behav' : [['subject_id' , 'model_id' ,
686
- 'task_id' , 'run_id' ]],
687
- 'contrasts' : [['model_id' ]]}
686
+ 'bold' : [['subject_id' , 'task_id' ]],
687
+ 'behav' : [['subject_id' , 'model_id' ,
688
+ 'task_id' , 'run_id' ]],
689
+ 'contrasts' : [['model_id' ]]}
688
690
else :
689
691
datasource .inputs .field_template = {'anat' : '%s/anatomy/T1_001.nii.gz' ,
690
692
'bold' : '%s/BOLD/task%03d_r*/bold.nii.gz' ,
691
693
'behav' : ('%s/model/model%03d/onsets/task%03d_'
692
694
'run%03d/cond*.txt' )}
693
695
datasource .inputs .template_args = {'anat' : [['subject_id' ]],
694
- 'bold' : [['subject_id' , 'task_id' ]],
695
- 'behav' : [['subject_id' , 'model_id' ,
696
- 'task_id' , 'run_id' ]]}
696
+ 'bold' : [['subject_id' , 'task_id' ]],
697
+ 'behav' : [['subject_id' , 'model_id' ,
698
+ 'task_id' , 'run_id' ]]}
697
699
698
700
datasource .inputs .sort_filelist = True
699
701
@@ -736,7 +738,7 @@ def get_contrasts(contrast_file, task_id, conds):
736
738
for row in contrast_def :
737
739
if row [0 ] != 'task%03d' % task_id :
738
740
continue
739
- con = [row [1 ], 'T' , ['cond%03d' % (i + 1 ) for i in range (len (conds ))],
741
+ con = [row [1 ], 'T' , ['cond%03d' % (i + 1 ) for i in range (len (conds ))],
740
742
row [2 :].astype (float ).tolist ()]
741
743
contrasts .append (con )
742
744
# add auto contrasts for each column
@@ -762,7 +764,7 @@ def get_contrasts(contrast_file, task_id, conds):
762
764
name = "art" )
763
765
764
766
modelspec = pe .Node (interface = model .SpecifyModel (),
765
- name = "modelspec" )
767
+ name = "modelspec" )
766
768
modelspec .inputs .input_units = 'secs'
767
769
768
770
def check_behav_list (behav , run_id , conds ):
@@ -776,9 +778,9 @@ def check_behav_list(behav, run_id, conds):
776
778
return behav_array .reshape (num_elements / num_conds , num_conds ).tolist ()
777
779
778
780
reshape_behav = pe .Node (niu .Function (input_names = ['behav' , 'run_id' , 'conds' ],
779
- output_names = ['behav' ],
780
- function = check_behav_list ),
781
- name = 'reshape_behav' )
781
+ output_names = ['behav' ],
782
+ function = check_behav_list ),
783
+ name = 'reshape_behav' )
782
784
783
785
wf .connect (subjinfo , 'TR' , modelspec , 'time_repetition' )
784
786
wf .connect (datasource , 'behav' , reshape_behav , 'behav' )
@@ -858,7 +860,7 @@ def sort_copes(copes, varcopes, contrasts):
858
860
('varcopes' , 'inputspec.varcopes' ),
859
861
('n_runs' , 'l2model.num_copes' )]),
860
862
(modelfit , fixed_fx , [('outputspec.dof_file' ,
861
- 'inputspec.dof_files' ),
863
+ 'inputspec.dof_files' ),
862
864
])
863
865
])
864
866
@@ -888,9 +890,9 @@ def merge_files(copes, varcopes, zstats):
888
890
889
891
mergefunc = pe .Node (niu .Function (input_names = ['copes' , 'varcopes' ,
890
892
'zstats' ],
891
- output_names = ['out_files' , 'splits' ],
892
- function = merge_files ),
893
- name = 'merge_files' )
893
+ output_names = ['out_files' , 'splits' ],
894
+ function = merge_files ),
895
+ name = 'merge_files' )
894
896
wf .connect ([(fixed_fx .get_node ('outputspec' ), mergefunc ,
895
897
[('copes' , 'copes' ),
896
898
('varcopes' , 'varcopes' ),
@@ -908,7 +910,7 @@ def split_files(in_files, splits):
908
910
output_names = ['copes' , 'varcopes' ,
909
911
'zstats' ],
910
912
function = split_files ),
911
- name = 'split_files' )
913
+ name = 'split_files' )
912
914
wf .connect (mergefunc , 'splits' , splitfunc , 'splits' )
913
915
wf .connect (registration , 'outputspec.transformed_files' ,
914
916
splitfunc , 'in_files' )
@@ -932,12 +934,12 @@ def split_files(in_files, splits):
932
934
933
935
def get_subs (subject_id , conds , run_id , model_id , task_id ):
934
936
subs = [('_subject_id_%s_' % subject_id , '' )]
935
- subs .append (('_model_id_%d' % model_id , 'model%03d' % model_id ))
937
+ subs .append (('_model_id_%d' % model_id , 'model%03d' % model_id ))
936
938
subs .append (('task_id_%d/' % task_id , '/task%03d_' % task_id ))
937
939
subs .append (('bold_dtype_mcf_mask_smooth_mask_gms_tempfilt_mean_warp' ,
938
- 'mean' ))
940
+ 'mean' ))
939
941
subs .append (('bold_dtype_mcf_mask_smooth_mask_gms_tempfilt_mean_flirt' ,
940
- 'affine' ))
942
+ 'affine' ))
941
943
942
944
for i in range (len (conds )):
943
945
subs .append (('_flameo%d/cope1.' % i , 'cope%02d.' % (i + 1 )))
@@ -1058,7 +1060,7 @@ def get_subs(subject_id, conds, run_id, model_id, task_id):
1058
1060
help = "Model index" + defstr )
1059
1061
parser .add_argument ('-x' , '--subjectprefix' , default = 'sub*' ,
1060
1062
help = "Subject prefix" + defstr )
1061
- parser .add_argument ('-t' , '--task' , default = 1 , #nargs='+',
1063
+ parser .add_argument ('-t' , '--task' , default = 1 ,
1062
1064
type = int , help = "Task index" + defstr )
1063
1065
parser .add_argument ('--hpfilter' , default = 120. ,
1064
1066
type = float , help = "High pass filter cutoff (in secs)" + defstr )
0 commit comments