@@ -284,7 +284,7 @@ def get_subjectinfo(subject_id, base_dir, task_id, model_id):
284284 for idx in range (n_tasks ):
285285 taskidx = np .where (taskinfo [:, 0 ] == 'task%03d' % (idx + 1 ))
286286 conds .append ([condition .replace (' ' , '_' ) for condition
287- in taskinfo [taskidx [0 ], 2 ]])
287+ in taskinfo [taskidx [0 ], 2 ] if 'junk' not in condition ])
288288 files = sorted (glob (os .path .join (base_dir ,
289289 subject_id ,
290290 'BOLD' ,
@@ -520,32 +520,39 @@ def check_behav_list(behav, conds):
520520 Reorder the copes so that now it combines across runs
521521 """
522522
523- def sort_copes (files ):
524- numelements = len (files [0 ])
525- outfiles = []
526- for i in range (numelements ):
527- outfiles .insert (i , [])
528- for j , elements in enumerate (files ):
529- outfiles [i ].append (elements [i ])
530- return outfiles
531-
532- def num_copes (files ):
533- return len (files )
523+ def sort_copes (copes , varcopes , conds ):
524+ import numpy as np
525+ if not isinstance (copes , list ):
526+ copes = [copes ]
527+ varcopes = [varcopes ]
528+ num_copes = len (conds )
529+ n_runs = len (copes )
530+ all_copes = np .array (copes ).flatten ()
531+ all_varcopes = np .array (varcopes ).flatten ()
532+ outcopes = all_copes .reshape (len (all_copes )/ num_copes , num_copes ).T .tolist ()
533+ outvarcopes = all_varcopes .reshape (len (all_varcopes )/ num_copes , num_copes ).T .tolist ()
534+ return outcopes , outvarcopes , n_runs
535+
536+ cope_sorter = pe .Node (niu .Function (input_names = ['copes' , 'varcopes' ,
537+ 'conds' ],
538+ output_names = ['copes' , 'varcopes' ,
539+ 'n_runs' ],
540+ function = sort_copes ),
541+ name = 'cope_sorter' )
534542
535543 pickfirst = lambda x : x [0 ]
536544
545+ wf .connect (subjinfo , 'conds' , cope_sorter , 'conds' )
537546 wf .connect ([(preproc , fixed_fx , [(('outputspec.mask' , pickfirst ),
538547 'flameo.mask_file' )]),
539- (modelfit , fixed_fx , [(('outputspec.copes' , sort_copes ),
540- 'inputspec.copes' ),
541- ('outputspec.dof_file' ,
548+ (modelfit , cope_sorter , [('outputspec.copes' , 'copes' )]),
549+ (modelfit , cope_sorter , [('outputspec.varcopes' , 'varcopes' )]),
550+ (cope_sorter , fixed_fx , [('copes' , 'inputspec.copes' ),
551+ ('varcopes' , 'inputspec.varcopes' ),
552+ ('n_runs' , 'l2model.num_copes' )]),
553+ (modelfit , fixed_fx , [('outputspec.dof_file' ,
542554 'inputspec.dof_files' ),
543- (('outputspec.varcopes' ,
544- sort_copes ),
545- 'inputspec.varcopes' ),
546- (('outputspec.copes' , num_copes ),
547- 'l2model.num_copes' ),
548- ])
555+ ])
549556 ])
550557
551558 wf .connect (preproc , 'outputspec.mean' , registration , 'inputspec.mean_image' )
0 commit comments