26
26
27
27
28
28
class Task (tasks .BaseTask ):
29
- def __init__ (self , sub , ses , run , bids , outdir , qsiprep_config , fs_license , container_dir = None , custom_eddy = False , no_gpu = False , output_resolution = None , tempdir = None , pipenv = None ):
29
+ def __init__ (self , sub , ses , run , bids , outdir , qsiprep_config , fs_license , truncate_fmap = False , container_dir = None , custom_eddy = False , no_gpu = False , output_resolution = None , tempdir = None , pipenv = None ):
30
30
self ._sub = sub
31
31
self ._ses = ses
32
32
self ._run = run
33
33
self ._bids = bids
34
34
self ._qsiprep_config = qsiprep_config
35
35
self ._fs_license = fs_license
36
+ self ._truncate_fmap = truncate_fmap
36
37
self ._container_dir = container_dir
37
38
self ._custom_eddy = custom_eddy
38
39
self ._no_gpu = no_gpu
@@ -329,7 +330,7 @@ def extract_vols(self, dwi_full_path, dwi_basename):
329
330
330
331
epi_output_path = epi_output .replace ('/dwi/' , '/fmap/' )
331
332
332
- self .run_extract (dwi_full_path , bval , epi_output_path )
333
+ fmap_path = self .run_extract (dwi_full_path , bval , epi_output_path )
333
334
334
335
335
336
# create an output file path for the new fmap's json file
@@ -352,6 +353,20 @@ def extract_vols(self, dwi_full_path, dwi_basename):
352
353
353
354
self .insert_json_value ('IntendedFor' , f'ses-{ self ._ses } /dwi/{ dwi_basename } ' , fmap_json_file_path )
354
355
356
+ if self ._truncate_fmap :
357
+ shape = nib .load (fmap_path ).get_fdata ().shape
358
+ if len (shape ) == 4 :
359
+ num_vols = shape [3 ]
360
+ middle_vol = num_vols // 2
361
+
362
+ self .run_fslroi (fmap_path , middle_vol )
363
+
364
+ def run_fslroi (self , fmap , volume ):
365
+ vol_index = int (volume ) - 1
366
+ split_command = f'singularity exec /{ self ._fsl_sif } /APPS/fsl/bin/fslroi { fmap } { fmap } { volume } { str (vol_index )} '
367
+ logger .info (f'executing { split_command } ' )
368
+ proc1 = subprocess .check_output (split_command , shell = True , stderr = subprocess .STDOUT , text = True )
369
+
355
370
def run_extract (self , dwi_full_path , bval_path , epi_out_path ):
356
371
357
372
bvec_path = bval_path .replace ('.bval' , '.bvec' )
@@ -395,6 +410,7 @@ def run_extract(self, dwi_full_path, bval_path, epi_out_path):
395
410
logger .critical (f'fslselectvols failed to produce "{ epi_out_path } "' )
396
411
raise subprocess .CalledProcessError (returncode = 1 , cmd = extract_command )
397
412
logger .info (f'found fslselectvols derived file "{ epi_out_path } "' )
413
+ return epi_out_path
398
414
except subprocess .CalledProcessError as e :
399
415
print (e .stdout )
400
416
raise e
0 commit comments