44 traits , TraitedSpec , BaseInterfaceInputSpec ,
55 File , BaseInterface
66)
7- from .utils import SliceMotionCorrection
7+ from .utils import SliceMotionCorrection , antsMotionCorr
88
9-
10- def init_bold_hmc_wf (slice_mc = False , rabies_data_type = 8 , rabies_mem_scale = 1.0 , min_proc = 1 , local_threads = 1 , name = 'bold_hmc_wf' ):
9+ def init_bold_hmc_wf (opts , name = 'bold_hmc_wf' ):
1110 """
1211 This workflow estimates the motion parameters to perform HMC over the BOLD image.
1312
@@ -28,7 +27,6 @@ def init_bold_hmc_wf(slice_mc=False, rabies_data_type=8, rabies_mem_scale=1.0, m
2827 movpar_file
2928 CSV file with antsMotionCorr motion parameters
3029 """
31- import os
3230
3331 workflow = pe .Workflow (name = name )
3432 inputnode = pe .Node (niu .IdentityInterface (fields = ['bold_file' , 'ref_image' ]),
@@ -39,23 +37,24 @@ def init_bold_hmc_wf(slice_mc=False, rabies_data_type=8, rabies_mem_scale=1.0, m
3937 name = 'outputnode' )
4038
4139 # Head motion correction (hmc)
42- motion_estimation = pe .Node (EstimateMotion (rabies_data_type = rabies_data_type ), name = 'ants_MC' , mem_gb = 1.1 * rabies_mem_scale )
40+ motion_estimation = pe .Node (antsMotionCorr (prebuilt_option = opts .HMC_option ,transform_type = opts .HMC_transform , second = False , rabies_data_type = opts .data_type ),
41+ name = 'ants_MC' , mem_gb = 1.1 * opts .scale_min_memory )
4342 motion_estimation .plugin_args = {
44- 'qsub_args' : '-pe smp %s' % (str (3 * min_proc )), 'overwrite' : True }
43+ 'qsub_args' : '-pe smp %s' % (str (3 * opts . min_proc )), 'overwrite' : True }
4544
4645 workflow .connect ([
4746 (inputnode , motion_estimation , [('ref_image' , 'ref_file' ),
4847 ('bold_file' , 'in_file' )]),
4948 (motion_estimation , outputnode , [
50- ('motcorr_params ' , 'motcorr_params' )]),
49+ ('csv_params ' , 'motcorr_params' )]),
5150 ])
5251
53- if slice_mc :
54- slice_mc_n_procs = int (local_threads / 4 )+ 1
52+ if opts . apply_slice_mc :
53+ slice_mc_n_procs = int (opts . local_threads / 4 )+ 1
5554 slice_mc_node = pe .Node (SliceMotionCorrection (n_procs = slice_mc_n_procs ),
5655 name = 'slice_mc' , mem_gb = 1 * slice_mc_n_procs , n_procs = slice_mc_n_procs )
5756 slice_mc_node .plugin_args = {
58- 'qsub_args' : '-pe smp %s' % (str (3 * min_proc )), 'overwrite' : True }
57+ 'qsub_args' : '-pe smp %s' % (str (3 * opts . min_proc )), 'overwrite' : True }
5958
6059 # conducting a volumetric realignment before slice-specific mc to correct for larger head translations and rotations
6160 workflow .connect ([
@@ -68,43 +67,3 @@ def init_bold_hmc_wf(slice_mc=False, rabies_data_type=8, rabies_mem_scale=1.0, m
6867 ])
6968
7069 return workflow
71-
72-
73- class EstimateMotionInputSpec (BaseInterfaceInputSpec ):
74- in_file = File (exists = True , mandatory = True , desc = "4D EPI file" )
75- ref_file = File (exists = True , mandatory = True ,
76- desc = "Reference image to which timeseries are realigned for motion estimation" )
77- rabies_data_type = traits .Int (mandatory = True ,
78- desc = "Integer specifying SimpleITK data type." )
79-
80-
81- class EstimateMotionOutputSpec (TraitedSpec ):
82- motcorr_params = File (
83- exists = True , desc = "Motion estimation derived from antsMotionCorr" )
84- mc_corrected_bold = File (exists = True , desc = "motion corrected time series" )
85-
86-
87- class EstimateMotion (BaseInterface ):
88- """
89- Runs ants motion correction interface and returns the motion estimation
90- """
91-
92- input_spec = EstimateMotionInputSpec
93- output_spec = EstimateMotionOutputSpec
94-
95- def _run_interface (self , runtime ):
96- import os
97- from .utils import antsMotionCorr
98- res = antsMotionCorr (in_file = self .inputs .in_file ,
99- ref_file = self .inputs .ref_file , second = False , rabies_data_type = self .inputs .rabies_data_type ).run ()
100- csv_params = os .path .abspath (res .outputs .csv_params )
101-
102- setattr (self , 'csv_params' , csv_params )
103- setattr (self , 'mc_corrected_bold' , os .path .abspath (
104- res .outputs .mc_corrected_bold ))
105-
106- return runtime
107-
108- def _list_outputs (self ):
109- return {'mc_corrected_bold' : getattr (self , 'mc_corrected_bold' ),
110- 'motcorr_params' : getattr (self , 'csv_params' )}
0 commit comments