def _ants_linear_coreg_pipeline(self, **name_maps): """ Registers a MR scan to a refernce MR scan using ANTS's linear_reg command """ pipeline = self.new_pipeline( name='linear_coreg', name_maps=name_maps, desc="Registers a MR scan against a reference image using ANTs") pipeline.add('ANTs_linear_Reg', AntsRegSyn(num_dimensions=3, transformation='r', out_prefix='reg2hires'), inputs={ 'ref_file': ('coreg_ref', nifti_gz_format), 'input_file': ('preproc', nifti_gz_format) }, outputs={ 'reg_file': ('coreg', nifti_gz_format), 'regmat': ('coreg_matrix', text_matrix_format) }, wall_time=10, requirements=[ants_req.v('2.0')]) return pipeline
def Image_normalization_pipeline(self, **kwargs): pipeline = self.new_pipeline( name='Image_registration', desc=('Image registration to a template using ANTs'), citations=[], **kwargs) pipeline.add( 'ANTs', AntsRegSyn( out_prefix='vol2template', num_dimensions=self.parameter('norm_dim'), num_threads=self.processor.num_processes, transformation=self.parameter('norm_transformation'), ref_file=self.parameter('norm_template')), inputs={ 'input_file': ('pet_image', nifti_gz_format)}, ouputs={ 'registered_volume': ('reg_file', nifti_gz_format), 'warp_file': ('warp_file', nifti_gz_format), 'invwarp_file': ('inv_warp', nifti_gz_format), 'affine_mat': ('regmat', text_matrix_format)}) return pipeline
def _ants_to_atlas_pipeline(self, **name_maps): pipeline = self.new_pipeline( name='coregister_to_atlas', name_maps=name_maps, desc=("Nonlinearly registers a MR scan to a standard space," "e.g. MNI-space"), references=[fsl_cite]) ants_reg = pipeline.add('Struct2MNI_reg', AntsRegSyn(num_dimensions=3, transformation='s', out_prefix='Struct2MNI', num_threads=4), inputs={ 'input_file': (self.brain_spec_name, nifti_gz_format), 'ref_file': ('atlas_brain', nifti_gz_format) }, outputs={ 'reg_file': ('coreg_to_atlas', nifti_gz_format), 'regmat': ('coreg_to_atlas_mat', text_matrix_format), 'warp_file': ('coreg_to_atlas_warp', nifti_gz_format) }, wall_time=25, requirements=[ants_req.v('2.0')]) pipeline.add('slices', FSLSlices(outname='coreg_to_atlas_report'), inputs={'im1': ('atlas', nifti_gz_format)}, connect={'im2': (ants_reg, 'reg_file')}, outputs={'report': ('coreg_to_atlas_report', gif_format)}, wall_time=1, requirements=[fsl_req.v('5.0.8')]) return pipeline
def motion_correction_pipeline(self, **name_maps): if 'struct2align' in self.input_names: StructAlignment = True else: StructAlignment = False pipeline = self.new_pipeline( name='pet_mc', desc=("Given a folder with reconstructed PET data, this " "pipeline will generate a motion corrected PET" "image using information extracted from the MR-based " "motion detection pipeline"), citations=[fsl_cite], name_maps=name_maps) check_pet = pipeline.add( 'check_pet_data', CheckPetMCInputs(), inputs={ 'pet_data': ('pet_data_prepared', directory_format), 'reference': ('ref_brain', nifti_gz_format) }, requirements=[fsl_req.v('5.0.9'), mrtrix_req.v('3.0rc3')]) if self.branch('dynamic_pet_mc'): pipeline.connect_input('fixed_binning_mats', check_pet, 'motion_mats') else: pipeline.connect_input('average_mats', check_pet, 'motion_mats') pipeline.connect_input('correction_factors', check_pet, 'corr_factors') if StructAlignment: struct_reg = pipeline.add('ref2structural_reg', FLIRT(dof=6, cost_func='normmi', cost='normmi', output_type='NIFTI_GZ'), inputs={ 'reference': ('ref_brain', nifti_gz_format), 'in_file': ('struct2align', nifti_gz_format) }, requirements=[fsl_req.v('5.0.9')]) if self.branch('dynamic_pet_mc'): pet_mc = pipeline.add('pet_mc', PetImageMotionCorrection(), inputs={ 'pet_image': (check_pet, 'pet_images'), 'motion_mat': (check_pet, 'motion_mats'), 'pet2ref_mat': (check_pet, 'pet2ref_mat') }, requirements=[fsl_req.v('5.0.9')], iterfield=['pet_image', 'motion_mat']) else: pet_mc = pipeline.add( 'pet_mc', PetImageMotionCorrection(), inputs={'corr_factor': (check_pet, 'corr_factors')}, requirements=[fsl_req.v('5.0.9')], iterfield=['corr_factor', 'pet_image', 'motion_mat']) if StructAlignment: pipeline.connect(struct_reg, 'out_matrix_file', pet_mc, 'structural2ref_regmat') pipeline.connect_input('struct2align', pet_mc, 'structural_image') if self.parameter('PET2MNI_reg'): mni_reg = True else: mni_reg = False if self.branch('dynamic_pet_mc'): merge_mc = pipeline.add( 'merge_pet_mc', fsl.Merge(dimension='t'), inputs={'in_files': (pet_mc, 'pet_mc_image')}, requirements=[fsl_req.v('5.0.9')]) merge_no_mc = pipeline.add( 'merge_pet_no_mc', fsl.Merge(dimension='t'), inputs={'in_files': (pet_mc, 'pet_no_mc_image')}, requirements=[fsl_req.v('5.0.9')]) else: static_mc = pipeline.add('static_mc_generation', StaticPETImageGeneration(), inputs={ 'pet_mc_images': (pet_mc, 'pet_mc_image'), 'pet_no_mc_images': (pet_mc, 'pet_no_mc_image') }, requirements=[fsl_req.v('5.0.9')]) merge_outputs = pipeline.add( 'merge_outputs', Merge(3), inputs={'in1': ('mean_displacement_plot', png_format)}) if not StructAlignment: cropping = pipeline.add( 'pet_cropping', PETFovCropping(x_min=self.parameter('crop_xmin'), x_size=self.parameter('crop_xsize'), y_min=self.parameter('crop_ymin'), y_size=self.parameter('crop_ysize'), z_min=self.parameter('crop_zmin'), z_size=self.parameter('crop_zsize'))) if self.branch('dynamic_pet_mc'): pipeline.connect(merge_mc, 'merged_file', cropping, 'pet_image') else: pipeline.connect(static_mc, 'static_mc', cropping, 'pet_image') cropping_no_mc = pipeline.add( 'pet_no_mc_cropping', PETFovCropping(x_min=self.parameter('crop_xmin'), x_size=self.parameter('crop_xsize'), y_min=self.parameter('crop_ymin'), y_size=self.parameter('crop_ysize'), z_min=self.parameter('crop_zmin'), z_size=self.parameter('crop_zsize'))) if self.branch('dynamic_pet_mc'): pipeline.connect(merge_no_mc, 'merged_file', cropping_no_mc, 'pet_image') else: pipeline.connect(static_mc, 'static_no_mc', cropping_no_mc, 'pet_image') if mni_reg: if self.branch('dynamic_pet_mc'): t_mean = pipeline.add( 'PET_temporal_mean', ImageMaths(op_string='-Tmean'), inputs={'in_file': (cropping, 'pet_cropped')}, requirements=[fsl_req.v('5.0.9')]) reg_tmean2MNI = pipeline.add( 'reg2MNI', AntsRegSyn(num_dimensions=3, transformation='s', out_prefix='reg2MNI', num_threads=4, ref_file=self.parameter('PET_template_MNI')), wall_time=25, requirements=[ants_req.v('2')]) if self.branch('dynamic_pet_mc'): pipeline.connect(t_mean, 'out_file', reg_tmean2MNI, 'input_file') merge_trans = pipeline.add('merge_transforms', Merge(2), inputs={ 'in1': (reg_tmean2MNI, 'warp_file'), 'in2': (reg_tmean2MNI, 'regmat') }, wall_time=1) apply_trans = pipeline.add( 'apply_trans', ApplyTransforms( reference_image=self.parameter('PET_template_MNI'), interpolation='Linear', input_image_type=3), inputs={ 'input_image': (cropping, 'pet_cropped'), 'transforms': (merge_trans, 'out') }, wall_time=7, mem_gb=24, requirements=[ants_req.v('2')]) pipeline.connect(apply_trans, 'output_image', merge_outputs, 'in2'), else: pipeline.connect(cropping, 'pet_cropped', reg_tmean2MNI, 'input_file') pipeline.connect(reg_tmean2MNI, 'reg_file', merge_outputs, 'in2') else: pipeline.connect(cropping, 'pet_cropped', merge_outputs, 'in2') pipeline.connect(cropping_no_mc, 'pet_cropped', merge_outputs, 'in3') else: if self.branch('dynamic_pet_mc'): pipeline.connect(merge_mc, 'merged_file', merge_outputs, 'in2') pipeline.connect(merge_no_mc, 'merged_file', merge_outputs, 'in3') else: pipeline.connect(static_mc, 'static_mc', merge_outputs, 'in2') pipeline.connect(static_mc, 'static_no_mc', merge_outputs, 'in3') # mcflirt = pipeline.add('mcflirt', MCFLIRT()) # 'in_file': (merge_mc_ps, 'merged_file'), # cost='normmi', copy2dir = pipeline.add('copy2dir', CopyToDir(), inputs={'in_files': (merge_outputs, 'out')}) if self.branch('dynamic_pet_mc'): pipeline.connect_output('dynamic_motion_correction_results', copy2dir, 'out_dir') else: pipeline.connect_output('static_motion_correction_results', copy2dir, 'out_dir') return pipeline
def _ants_to_tmpl_pipeline(self, **name_maps): pipeline = self.new_pipeline( name='mag_coreg_to_tmpl', name_maps=name_maps, desc=("Nonlinearly registers a MR scan to a standard space," "e.g. MNI-space"), citations=[fsl_cite]) pipeline.add( 'Struct2MNI_reg', AntsRegSyn( num_dimensions=3, transformation='s', num_threads=4), inputs={ 'input_file': (self.brain_spec_name, nifti_gz_format), 'ref_file': ('template_brain', nifti_gz_format)}, outputs={ 'mag_coreg_to_tmpl': ('reg_file', nifti_gz_format), 'coreg_to_tmpl_ants_mat': ('regmat', text_matrix_format), 'coreg_to_tmpl_ants_warp': ('warp_file', nifti_gz_format)}, wall_time=25, requirements=[ants_req.v('2.0')]) # ants_reg = pipeline.add( # 'ants_reg', # ants.Registration( # dimension=3, # collapse_output_transforms=True, # float=False, # interpolation='Linear', # use_histogram_matching=False, # winsorize_upper_quantile=0.995, # winsorize_lower_quantile=0.005, # verbose=True, # transforms=['Rigid', 'Affine', 'SyN'], # transform_parameters=[(0.1,), (0.1,), (0.1, 3, 0)], # metric=['MI', 'MI', 'CC'], # metric_weight=[1, 1, 1], # radius_or_number_of_bins=[32, 32, 32], # sampling_strategy=['Regular', 'Regular', 'None'], # sampling_percentage=[0.25, 0.25, None], # number_of_iterations=[[1000, 500, 250, 100], # [1000, 500, 250, 100], # [100, 70, 50, 20]], # convergence_threshold=[1e-6, 1e-6, 1e-6], # convergence_window_size=[10, 10, 10], # shrink_factors=[[8, 4, 2, 1], # [8, 4, 2, 1], # [8, 4, 2, 1]], # smoothing_sigmas=[[3, 2, 1, 0], # [3, 2, 1, 0], # [3, 2, 1, 0]], # output_warped_image=True), # inputs={ # 'fixed_image': ('template_brain', nifti_gz_format), # 'moving_image': (self.brain_spec_name, nifti_gz_format)}, # outputs={ # 'mag_coreg_to_tmpl': ('warped_image', nifti_gz_format)}, # wall_time=25, # requirements=[ants_req.v('2.0')]) # # select_trans = pipeline.add( # 'select', # SelectOne( # index=1), # inputs={ # 'inlist': (ants_reg, 'forward_transforms')}, # outputs={ # 'coreg_to_tmpl_ants_mat': ('out', text_matrix_format)}) # # pipeline.add( # 'select_warp', # SelectOne( # index=0), # inputs={ # 'inlist': (ants_reg, 'forward_transforms')}, # outputs={ # 'coreg_to_tmpl_ants_warp': ('out', nifti_gz_format)}) # # pipeline.add( # 'slices', # FSLSlices( # outname='coreg_to_tmpl_report'), # inputs={ # 'im1': ('template', nifti_gz_format), # 'im2': (select_trans, 'out')}, # outputs={ # 'coreg_to_tmpl_fsl_report': ('report', gif_format)}, # wall_time=1, # requirements=[fsl_req.v('5.0.8')]) return pipeline
def _optiBET_brain_extraction_pipeline(self, **name_maps): """ Generates a whole brain mask using a modified optiBET approach. """ pipeline = self.new_pipeline( name='brain_extraction', name_maps=name_maps, desc=("Modified implementation of optiBET.sh"), citations=[fsl_cite]) mni_reg = pipeline.add( 'T1_reg', AntsRegSyn( num_dimensions=3, transformation='s', out_prefix='T12MNI', num_threads=4), inputs={ 'ref_file': ('template', nifti_gz_format), 'input_file': ('mag_preproc', nifti_gz_format)}, wall_time=25, requirements=[ants_req.v('2.0')]) merge_trans = pipeline.add( 'merge_transforms', Merge(2), inputs={ 'in1': (mni_reg, 'inv_warp'), 'in2': (mni_reg, 'regmat')}, wall_time=1) trans_flags = pipeline.add( 'trans_flags', Merge(2, in1=False, in2=True), wall_time=1) apply_trans = pipeline.add( 'ApplyTransform', ApplyTransforms( interpolation='NearestNeighbor', input_image_type=3), inputs={ 'input_image': ('template_mask', nifti_gz_format), 'reference_image': ('mag_preproc', nifti_gz_format), 'transforms': (merge_trans, 'out'), 'invert_transform_flags': (trans_flags, 'out')}, wall_time=7, mem_gb=24, requirements=[ants_req.v('2.0')]) maths1 = pipeline.add( 'binarize', fsl.ImageMaths( suffix='_optiBET_brain_mask', op_string='-bin', output_type='NIFTI_GZ'), inputs={ 'in_file': (apply_trans, 'output_image')}, outputs={ 'brain_mask': ('out_file', nifti_gz_format)}, wall_time=5, requirements=[fsl_req.v('5.0.8')]) maths2 = pipeline.add( 'mask', fsl.ImageMaths( suffix='_optiBET_brain', op_string='-mas', output_type='NIFTI_GZ'), inputs={ 'in_file': ('mag_preproc', nifti_gz_format), 'in_file2': (maths1, 'out_file')}, outputs={ 'brain': ('out_file', nifti_gz_format)}, wall_time=5, requirements=[fsl_req.v('5.0.8')]) if self.branch('optibet_gen_report'): pipeline.add( 'slices', FSLSlices( outname='optiBET_report', output_type='NIFTI_GZ'), wall_time=5, inputs={ 'im1': ('mag_preproc', nifti_gz_format), 'im2': (maths2, 'out_file')}, outputs={ 'optiBET_report': ('report', gif_format)}, requirements=[fsl_req.v('5.0.8')]) return pipeline
def _ants_linear_coreg_pipeline(self, **name_maps): """ Registers a MR scan to a refernce MR scan using ANTS's linear_reg command """ pipeline = self.new_pipeline( name='linear_coreg', name_maps=name_maps, desc="Registers a MR scan against a reference image using ANTs", citations=[ants_cite]) pipeline.add( 'ANTs_linear_Reg', AntsRegSyn( num_dimensions=3, transformation='r'), inputs={ 'ref_file': ('coreg_ref', nifti_gz_format), 'input_file': ('mag_preproc', nifti_gz_format)}, outputs={ 'mag_coreg': ('reg_file', nifti_gz_format), 'coreg_ants_mat': ('regmat', text_matrix_format)}, wall_time=10, requirements=[ants_req.v('2.0')]) # ants_reg = pipeline.add( # 'ants_reg', # ants.Registration( # dimension=3, # collapse_output_transforms=True, # float=False, # interpolation='Linear', # use_histogram_matching=False, # winsorize_upper_quantile=0.995, # winsorize_lower_quantile=0.005, # verbose=True, # transforms=['Rigid'], # transform_parameters=[(0.1,)], # metric=['MI'], # metric_weight=[1], # radius_or_number_of_bins=[32], # sampling_strategy=['Regular'], # sampling_percentage=[0.25], # number_of_iterations=[[1000, 500, 250, 100]], # convergence_threshold=[1e-6], # convergence_window_size=[10], # shrink_factors=[[8, 4, 2, 1]], # smoothing_sigmas=[[3, 2, 1, 0]], # output_warped_image=True), # inputs={ # 'fixed_image': ('coreg_ref', nifti_gz_format), # 'moving_image': ('mag_preproc', nifti_gz_format)}, # outputs={ # 'mag_coreg': ('warped_image', nifti_gz_format)}, # wall_time=10, # requirements=[ants_req.v('2.0')]) # # pipeline.add( # 'select', # SelectOne( # index=0), # inputs={ # 'inlist': (ants_reg, 'forward_transforms')}, # outputs={ # 'coreg_ants_mat': ('out', text_matrix_format)}) return pipeline