@@ -18,6 +18,28 @@ def getthreshop(thresh):
18
18
return ['-thr %.10f -Tmin -bin' % (0.1 * val [1 ]) for val in thresh ]
19
19
20
20
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
+
21
43
def pickfirst (files ):
22
44
if isinstance (files , list ):
23
45
return files [0 ]
@@ -401,7 +423,7 @@ def create_parallelfeat_preproc(name='featpreproc', highpass=True):
401
423
return featpreproc
402
424
403
425
404
- def create_featreg_preproc (name = 'featpreproc' , highpass = True , whichvol = 'middle' ):
426
+ def create_featreg_preproc (name = 'featpreproc' , highpass = True , whichvol = 'middle' , whichrun = 0 ):
405
427
"""Create a FEAT preprocessing workflow with registration to one volume of the first run
406
428
407
429
Parameters
@@ -412,6 +434,7 @@ def create_featreg_preproc(name='featpreproc', highpass=True, whichvol='middle')
412
434
name : name of workflow (default: featpreproc)
413
435
highpass : boolean (default: True)
414
436
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')
415
438
416
439
Inputs::
417
440
@@ -511,8 +534,8 @@ def create_featreg_preproc(name='featpreproc', highpass=True, whichvol='middle')
511
534
if whichvol != 'mean' :
512
535
extract_ref = pe .Node (interface = fsl .ExtractROI (t_size = 1 ),
513
536
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' )
516
539
featpreproc .connect (img2float , ('out_file' , pickvol , 0 , whichvol ), extract_ref , 't_min' )
517
540
featpreproc .connect (extract_ref , 'roi_file' , outputnode , 'reference' )
518
541
@@ -530,7 +553,7 @@ def create_featreg_preproc(name='featpreproc', highpass=True, whichvol='middle')
530
553
featpreproc .connect (extract_ref , 'roi_file' , motion_correct , 'ref_file' )
531
554
else :
532
555
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' )
534
557
535
558
featpreproc .connect (motion_correct , 'par_file' , outputnode , 'motion_parameters' )
536
559
featpreproc .connect (motion_correct , 'out_file' , outputnode , 'realigned_files' )
@@ -550,10 +573,9 @@ def create_featreg_preproc(name='featpreproc', highpass=True, whichvol='middle')
550
573
Extract the mean volume of the first functional run
551
574
"""
552
575
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' ),
555
577
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' )
557
579
558
580
"""
559
581
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')
699
721
iterfield = ['in_file' ],
700
722
name = 'meanfunc3' )
701
723
702
- featpreproc .connect (meanscale , ('out_file' , pickfirst ), meanfunc3 , 'in_file' )
724
+ featpreproc .connect (meanscale , ('out_file' , pickrun , whichrun ), meanfunc3 , 'in_file' )
703
725
featpreproc .connect (meanfunc3 , 'out_file' , outputnode , 'mean' )
704
726
705
727
"""
0 commit comments