@@ -18,6 +18,28 @@ def getthreshop(thresh):
1818 return ['-thr %.10f -Tmin -bin' % (0.1 * val [1 ]) for val in thresh ]
1919
2020
21+ def pickrun (files , whichrun ):
22+ """pick file from list of files"""
23+
24+ filemap = {'first' : 0 , 'last' : - 1 , 'middle' : len (files ) // 2 }
25+
26+ if isinstance (files , list ):
27+
28+ # whichrun is given as integer
29+ if isinstance (whichrun , int ):
30+ return files [whichrun ]
31+ # whichrun is given as string
32+ elif isinstance (whichrun , str ):
33+ if whichrun not in filemap .keys ():
34+ raise (KeyError , 'Sorry, whichrun must be either integer index'
35+ 'or string in form of "first", "last" or "middle' )
36+ else :
37+ return files [filemap [whichrun ]]
38+ else :
39+ # in case single file name is given
40+ return files
41+
42+
2143def pickfirst (files ):
2244 if isinstance (files , list ):
2345 return files [0 ]
@@ -401,7 +423,7 @@ def create_parallelfeat_preproc(name='featpreproc', highpass=True):
401423 return featpreproc
402424
403425
404- def create_featreg_preproc (name = 'featpreproc' , highpass = True , whichvol = 'middle' ):
426+ def create_featreg_preproc (name = 'featpreproc' , highpass = True , whichvol = 'middle' , whichrun = 0 ):
405427 """Create a FEAT preprocessing workflow with registration to one volume of the first run
406428
407429 Parameters
@@ -412,6 +434,7 @@ def create_featreg_preproc(name='featpreproc', highpass=True, whichvol='middle')
412434 name : name of workflow (default: featpreproc)
413435 highpass : boolean (default: True)
414436 whichvol : which volume of the first run to register to ('first', 'middle', 'last', 'mean')
437+ whichrun : which run to draw reference volume from (integer index or 'first', 'middle', 'last')
415438
416439 Inputs::
417440
@@ -511,8 +534,8 @@ def create_featreg_preproc(name='featpreproc', highpass=True, whichvol='middle')
511534 if whichvol != 'mean' :
512535 extract_ref = pe .Node (interface = fsl .ExtractROI (t_size = 1 ),
513536 iterfield = ['in_file' ],
514- name = 'extractref' )
515- featpreproc .connect (img2float , ('out_file' , pickfirst ), extract_ref , 'in_file' )
537+ name = 'extractref' )
538+ featpreproc .connect (img2float , ('out_file' , pickrun , whichrun ), extract_ref , 'in_file' )
516539 featpreproc .connect (img2float , ('out_file' , pickvol , 0 , whichvol ), extract_ref , 't_min' )
517540 featpreproc .connect (extract_ref , 'roi_file' , outputnode , 'reference' )
518541
@@ -530,7 +553,7 @@ def create_featreg_preproc(name='featpreproc', highpass=True, whichvol='middle')
530553 featpreproc .connect (extract_ref , 'roi_file' , motion_correct , 'ref_file' )
531554 else :
532555 motion_correct .inputs .mean_vol = True
533- featpreproc .connect (motion_correct , ('mean_img' , pickfirst ), outputnode , 'reference' )
556+ featpreproc .connect (motion_correct , ('mean_img' , pickrun , whichrun ), outputnode , 'reference' )
534557
535558 featpreproc .connect (motion_correct , 'par_file' , outputnode , 'motion_parameters' )
536559 featpreproc .connect (motion_correct , 'out_file' , outputnode , 'realigned_files' )
@@ -550,10 +573,9 @@ def create_featreg_preproc(name='featpreproc', highpass=True, whichvol='middle')
550573 Extract the mean volume of the first functional run
551574 """
552575
553- meanfunc = pe .Node (interface = fsl .ImageMaths (op_string = '-Tmean' ,
554- suffix = '_mean' ),
576+ meanfunc = pe .Node (interface = fsl .ImageMaths (op_string = '-Tmean' , suffix = '_mean' ),
555577 name = 'meanfunc' )
556- featpreproc .connect (motion_correct , ('out_file' , pickfirst ), meanfunc , 'in_file' )
578+ featpreproc .connect (motion_correct , ('out_file' , pickrun , whichrun ), meanfunc , 'in_file' )
557579
558580 """
559581 Strip the skull from the mean functional to generate a mask
@@ -699,7 +721,7 @@ def create_featreg_preproc(name='featpreproc', highpass=True, whichvol='middle')
699721 iterfield = ['in_file' ],
700722 name = 'meanfunc3' )
701723
702- featpreproc .connect (meanscale , ('out_file' , pickfirst ), meanfunc3 , 'in_file' )
724+ featpreproc .connect (meanscale , ('out_file' , pickrun , whichrun ), meanfunc3 , 'in_file' )
703725 featpreproc .connect (meanfunc3 , 'out_file' , outputnode , 'mean' )
704726
705727 """
0 commit comments