def bet_T2s(self, **options): pipeline = self.new_pipeline( name='BET_T2s', inputs=[FilesetSpec('t2s', nifti_gz_format), FilesetSpec('t2s_last_echo', nifti_gz_format)], outputs=[FilesetSpec('betted_T2s', nifti_gz_format), FilesetSpec('betted_T2s_mask', nifti_gz_format), FilesetSpec('betted_T2s_last_echo', nifti_gz_format)], desc=("python implementation of BET"), default_options={}, citations=[fsl_cite], options=options) bet = pipeline.create_node( fsl.BET(frac=0.1, mask=True), name='bet', requirements=[fsl_req.v('5.0.8')], mem_gb=8, wall_time=45) pipeline.connect_input('t2s', bet, 'in_file') pipeline.connect_output('betted_T2s', bet, 'out_file') pipeline.connect_output('betted_T2s_mask', bet, 'mask_file') maths = pipeline.create_node( fsl.utils.ImageMaths(suffix='_BET_brain', op_string='-mas'), name='mask', requirements=[fsl_req.v('5.0.8')], mem_gb=16, wall_time=5) pipeline.connect_input('t2s_last_echo', maths, 'in_file') pipeline.connect(bet, 'mask_file', maths, 'in_file2') pipeline.connect_output('betted_T2s_last_echo', maths, 'out_file') return pipeline
def smooth_mask_pipeline(self, **name_maps): pipeline = self.new_pipeline('smooth_mask', desc="Smooths and masks a brain image", name_maps=name_maps, citations=[fsl_cite]) # Smoothing process smooth = pipeline.add( 'smooth', fsl.IsotropicSmooth(fwhm=self.parameter('smoothing_fwhm')), inputs={'in_file': ('magnitude', nifti_gz_format)}, outputs={'smooth': ('out_file', nifti_gz_format)}, requirements=[fsl_req.v('5.0.10')]) pipeline.add('mask', fsl.ApplyMask(), inputs={ 'in_file': (smooth, 'out_file'), 'mask_file': ('brain_mask', nifti_gz_format) }, outputs={'smooth_masked': ('out_file', nifti_gz_format)}, requirements=[fsl_req.v('5.0.10')]) return pipeline
def rsfMRI_filtering_pipeline(self, **name_maps): pipeline = self.new_pipeline( name='rsfMRI_filtering', desc=("Spatial and temporal rsfMRI filtering"), citations=[fsl_cite], name_maps=name_maps) afni_mc = pipeline.add( 'AFNI_MC', Volreg( zpad=1, out_file='rsfmri_mc.nii.gz', oned_file='prefiltered_func_data_mcf.par'), inputs={ 'in_file': ('series_preproc', nifti_gz_format)}, outputs={ 'mc_par': ('oned_file', par_format)}, wall_time=5, requirements=[afni_req.v('16.2.10')]) filt = pipeline.add( 'Tproject', Tproject( stopband=(0, 0.01), polort=3, blur=3, out_file='filtered_func_data.nii.gz'), inputs={ 'delta_t': ('tr', float), 'mask': ('brain_mask', nifti_gz_format), 'in_file': (afni_mc, 'out_file')}, wall_time=5, requirements=[afni_req.v('16.2.10')]) meanfunc = pipeline.add( 'meanfunc', ImageMaths( op_string='-Tmean', suffix='_mean', output_type='NIFTI_GZ'), wall_time=5, inputs={ 'in_file': (afni_mc, 'out_file')}, requirements=[fsl_req.v('5.0.10')]) pipeline.add( 'add_mean', ImageMaths( op_string='-add', output_type='NIFTI_GZ'), inputs={ 'in_file': (filt, 'out_file'), 'in_file2': (meanfunc, 'out_file')}, outputs={ 'filtered_data': ('out_file', nifti_gz_format)}, wall_time=5, requirements=[fsl_req.v('5.0.10')]) return pipeline
def _flirt_linear_coreg_pipeline(self, **name_maps): """ Registers a MR scan to a refernce MR scan using FSL's FLIRT command """ pipeline = self.new_pipeline( name='linear_coreg', name_maps=name_maps, desc="Registers a MR scan against a reference image using FLIRT", citations=[fsl_cite]) pipeline.add( 'flirt', FLIRT(dof=self.parameter('flirt_degrees_of_freedom'), cost=self.parameter('flirt_cost_func'), cost_func=self.parameter('flirt_cost_func'), output_type='NIFTI_GZ'), inputs={ 'in_file': ('mag_preproc', nifti_gz_format), 'reference': ('coreg_ref', nifti_gz_format)}, outputs={ 'mag_coreg': ('out_file', nifti_gz_format), 'coreg_fsl_mat': ('out_matrix_file', text_matrix_format)}, requirements=[fsl_req.v('5.0.8')], wall_time=5) return pipeline
def segmentation_pipeline(self, img_type=2, **name_maps): pipeline = self.new_pipeline( name='FAST_segmentation', name_maps=name_maps, inputs=[FilesetSpec('brain', nifti_gz_format)], outputs=[FilesetSpec('wm_seg', nifti_gz_format)], desc="White matter segmentation of the reference image", references=[fsl_cite]) fast = pipeline.add('fast', fsl.FAST(img_type=img_type, segments=True, out_basename='Reference_segmentation'), inputs={'in_files': ('brain', nifti_gz_format)}, requirements=[fsl_req.v('5.0.9')]), # Determine output field of split to use if img_type == 1: split_output = 'out3' elif img_type == 2: split_output = 'out2' else: raise ArcanaUsageError( "'img_type' parameter can either be 1 or 2 (not {})".format( img_type)) pipeline.add('split', Split(splits=[1, 1, 1], squeeze=True), connect={'inlist': (fast, 'tissue_class_files')}, outputs={split_output: ('wm_seg', nifti_gz_format)}) return pipeline
def qform_transform_pipeline(self, **name_maps): pipeline = self.new_pipeline( name='qform_transform', name_maps=name_maps, desc="Registers a MR scan against a reference image", citations=[fsl_cite]) if self.provided('coreg_ref'): in_file = 'mag_preproc' reference = 'coreg_ref' elif self.provided('coreg_ref_brain'): in_file = 'brain' reference = 'coreg_ref_brain' else: raise BananaUsageError( "'coreg_ref' or 'coreg_ref_brain' need to be provided to " "study in order to run qform_transform") pipeline.add( 'flirt', FLIRT( uses_qform=True, apply_xfm=True, output_type='NIFTI_GZ'), inputs={ 'in_file': (in_file, nifti_gz_format), 'reference': (reference, nifti_gz_format)}, outputs={ 'qformed': ('out_file', nifti_gz_format), 'qform_mat': ('out_matrix_file', text_matrix_format)}, requirements=[fsl_req.v('5.0.8')], wall_time=5) return pipeline
def intrascan_alignment_pipeline(self, **kwargs): # inputs=[FilesetSpec('preproc', nifti_gz_format)], # outputs=[FilesetSpec('moco', nifti_gz_format), # FilesetSpec('align_mats', directory_format), # FilesetSpec('moco_par', par_format)], pipeline = self.new_pipeline(name='MCFLIRT_pipeline', desc=("Intra-epi volumes alignment."), citations=[fsl_cite], **kwargs) mcflirt = pipeline.add('mcflirt', fsl.MCFLIRT(), requirements=[fsl_req.v('5.0.9')]) mcflirt.inputs.ref_vol = 0 mcflirt.inputs.save_mats = True mcflirt.inputs.save_plots = True mcflirt.inputs.output_type = 'NIFTI_GZ' mcflirt.inputs.out_file = 'moco.nii.gz' pipeline.connect_input('preproc', mcflirt, 'in_file') pipeline.connect_output('moco', mcflirt, 'out_file') pipeline.connect_output('moco_par', mcflirt, 'par_file') merge = pipeline.add('merge', MergeListMotionMat()) pipeline.connect(mcflirt, 'mat_file', merge, 'file_list') pipeline.connect_output('align_mats', merge, 'out_dir') return pipeline
def bet_T1(self, **name_maps): pipeline = self.new_pipeline(name='BET_T1', name_maps=name_maps, desc=("python implementation of BET"), references=[fsl_cite]) bias = pipeline.add('n4_bias_correction', ants.N4BiasFieldCorrection(), inputs={'input_image': ('t1', nifti_gz_format)}, requirements=[ants_req.v('1.9')], wall_time=60, mem_gb=12) pipeline.add('bet', fsl.BET(frac=0.15, reduce_bias=True), connections={'in_file': (bias, 'output_image')}, outputs={ 'out_file': ('betted_T1', nifti_gz_format), 'mask_file': ('betted_T1_mask', nifti_gz_format) }, requirements=[fsl_req.v('5.0.8')], mem_gb=8, wall_time=45) return pipeline
def group_melodic_pipeline(self, **name_maps): pipeline = self.new_pipeline(name='group_melodic', desc=("Group ICA"), citations=[fsl_cite], name_maps=name_maps) pipeline.add(MELODIC( no_bet=True, bg_threshold=self.parameter('brain_thresh_percent'), dim=self.parameter('group_ica_components'), report=True, out_stats=True, mm_thresh=0.5, sep_vn=True, out_dir='group_melodic.ica', output_type='NIFTI_GZ'), inputs={ 'bg_image': ('template_brain', nifti_gz_format), 'mask': ('template_mask', nifti_gz_format), 'in_files': ('smoothed_ts', nifti_gz_format), 'tr_sec': ('tr', float) }, outputs={'group_melodic': ('out_dir', directory_format)}, joinsource=self.SUBJECT_ID, joinfield=['in_files'], name='gica', requirements=[fsl_req.v('5.0.10')], wall_time=7200) return pipeline
def _bet_brain_extraction_pipeline(self, **name_maps): """ Generates a whole brain mask using FSL's BET command. """ pipeline = self.new_pipeline( name='brain_extraction', name_maps=name_maps, desc="Generate brain mask from mr_scan", citations=[fsl_cite, bet_cite, bet2_cite]) # Create mask node bet = pipeline.add( "bet", fsl.BET( mask=True, output_type='NIFTI_GZ', frac=self.parameter('bet_f_threshold'), vertical_gradient=self.parameter('bet_g_threshold')), inputs={ 'in_file': ('mag_preproc', nifti_gz_format)}, outputs={ 'brain': ('out_file', nifti_gz_format), 'brain_mask': ('mask_file', nifti_gz_format)}, requirements=[fsl_req.v('5.0.9')]) # Set either robust or reduce bias if self.branch('bet_robust'): bet.inputs.robust = True else: bet.inputs.reduce_bias = self.parameter('bet_reduce_bias') return pipeline
def intrascan_alignment_pipeline(self, **name_maps): pipeline = self.new_pipeline( name='MCFLIRT_pipeline', desc=("Intra-epi volumes alignment."), citations=[fsl_cite], name_maps=name_maps) mcflirt = pipeline.add( 'mcflirt', fsl.MCFLIRT( ref_vol=0, save_mats=True, save_plots=True, output_type='NIFTI_GZ', out_file='moco.nii.gz'), inputs={ 'in_file': ('mag_preproc', nifti_gz_format)}, outputs={ 'moco': ('out_file', nifti_gz_format), 'moco_par': ('par_file', par_format)}, requirements=[fsl_req.v('5.0.9')]) pipeline.add( 'merge', MergeListMotionMat(), inputs={ 'file_list': (mcflirt, 'mat_file')}, outputs={ 'align_mats': ('out_dir', motion_mats_format)}) return pipeline
def series_coreg_pipeline(self, **name_maps): pipeline = self.new_pipeline( 'series_coreg', desc="Applies coregistration transform to DW series", citations=[], name_maps=name_maps) if self.provided('coreg_ref'): coreg_ref = 'coreg_ref' elif self.provided('coreg_ref_brain'): coreg_ref = 'coreg_ref_brain' else: raise BananaUsageError( "Cannot coregister DW series as reference ('coreg_ref' or " "'coreg_ref_brain') has not been provided to {}".format(self)) # Apply co-registration transformation to DW series pipeline.add( 'mask_transform', fsl.ApplyXFM( output_type='NIFTI_GZ', apply_xfm=True), inputs={ 'in_matrix_file': ('coreg_fsl_mat', text_matrix_format), 'in_file': ('series_preproc', nifti_gz_format), 'reference': (coreg_ref, nifti_gz_format)}, outputs={ 'series_coreg': ('out_file', nifti_gz_format)}, requirements=[fsl_req.v('5.0.10')], wall_time=10) return pipeline
def brain_coreg_pipeline(self, **name_maps): if self.branch('coreg_method', 'epireg'): pipeline = self.coreg_pipeline( name='brain_coreg', name_maps=dict( input_map={ 'mag_preproc': 'brain', 'coreg_ref': 'coreg_ref_brain'}, output_map={ 'mag_coreg': 'brain_coreg'}, name_maps=name_maps)) pipeline.add( 'mask_transform', fsl.ApplyXFM( output_type='NIFTI_GZ', apply_xfm=True), inputs={ 'in_matrix_file': (pipeline.node('epireg'), 'epi2str_mat'), 'in_file': ('brain_mask', nifti_gz_format), 'reference': ('coreg_ref_brain', nifti_gz_format)}, outputs={ 'brain_mask_coreg': ('out_file', nifti_gz_format)}, requirements=[fsl_req.v('5.0.10')], wall_time=10) else: pipeline = super().brain_coreg_pipeline(**name_maps) return pipeline
def _epireg_linear_coreg_pipeline(self, **name_maps): pipeline = self.new_pipeline( name='linear_coreg', desc=("Intra-subjects epi registration improved using white " "matter boundaries."), citations=[fsl_cite], name_maps=name_maps) epireg = pipeline.add( 'epireg', fsl.epi.EpiReg( out_base='epireg2ref', output_type='NIFTI_GZ', no_clean=True), inputs={ 'epi': ('brain', nifti_gz_format), 't1_brain': ('coreg_ref_brain', nifti_gz_format), 't1_head': ('coreg_ref', nifti_gz_format)}, outputs={ 'brain_coreg': ('out_file', nifti_gz_format), 'coreg_fsl_mat': ('epi2str_mat', text_matrix_format)}, requirements=[fsl_req.v('5.0.9')]) if self.provided('coreg_ref_wmseg'): pipeline.connect_input('coreg_ref_wmseg', epireg, 'wmseg', nifti_gz_format) return pipeline
def bet_T1(self, **name_maps): pipeline = self.new_pipeline( name='BET_T1', name_maps=name_maps, desc=("Brain extraction pipeline using FSL's BET"), citations=[fsl_cite]) bias = pipeline.add('n4_bias_correction', ants.N4BiasFieldCorrection(), inputs={'input_image': ('t1', nifti_gz_format)}, requirements=[ants_req.v('1.9')], wall_time=60, mem_gb=12) pipeline.add('bet', fsl.BET(frac=0.15, reduce_bias=True, output_type='NIFTI_GZ'), inputs={'in_file': (bias, 'output_image')}, outputs={ 'betted_T1': ('out_file', nifti_gz_format), 'betted_T1_mask': ('mask_file', nifti_gz_format) }, requirements=[fsl_req.v('5.0.8')], mem_gb=8, wall_time=45) return pipeline
def single_subject_melodic_pipeline(self, **name_maps): pipeline = self.new_pipeline( name='MelodicL1', desc=("Single subject ICA analysis using FSL MELODIC."), citations=[fsl_cite], name_maps=name_maps) pipeline.add('melodic_L1', MELODIC( no_bet=True, bg_threshold=self.parameter('brain_thresh_percent'), report=True, out_stats=True, mm_thresh=0.5, out_dir='melodic_ica', output_type='NIFTI_GZ'), inputs={ 'mask': (self.brain_mask_spec_name, nifti_gz_format), 'tr_sec': ('tr', float), 'in_files': ('filtered_data', nifti_gz_format) }, outputs={'melodic_ica': ('out_dir', directory_format)}, wall_time=15, requirements=[fsl_req.v('5.0.10')]) return pipeline
def prepare_pipeline(self, **name_maps): """ Performs basic preprocessing, such as swapping dimensions into standard orientation and resampling (if required) Parameters ------- new_dims : tuple(str)[3] A 3-tuple with the new orientation of the image (see FSL swap dim) resolution : list(float)[3] | None New resolution of the image. If None no resampling is performed """ pipeline = self.new_pipeline( name='prepare_pipeline', name_maps=name_maps, desc=("Dimensions swapping to ensure that all the images " "have the same orientations."), citations=[fsl_cite]) if (self.branch('reorient_to_std') or self.parameter('resampled_resolution') is not None): if self.branch('reorient_to_std'): swap = pipeline.add( 'fslreorient2std', fsl.utils.Reorient2Std( output_type='NIFTI_GZ'), inputs={ 'in_file': ('magnitude', nifti_gz_format)}, requirements=[fsl_req.v('5.0.9')]) # swap.inputs.new_dims = self.parameter('reoriented_dims') if self.parameter('resampled_resolution') is not None: resample = pipeline.add( "resample", MRResize( voxel=self.parameter('resampled_resolution')), inputs={ 'in_file': (swap, 'out_file')}, requirements=[mrtrix_req.v('3.0rc3')]) pipeline.connect_output('mag_preproc', resample, 'out_file', nifti_gz_format) else: pipeline.connect_output('mag_preproc', swap, 'out_file', nifti_gz_format) else: # Don't actually do any processing just copy magnitude image to # preproc pipeline.add( 'identity', IdentityInterface( ['file']), inputs={ 'file': ('magnitude', nifti_gz_format)}, outputs={ 'mag_preproc': ('file', nifti_gz_format)}) return pipeline
def _fugue_pipeline(self, **name_maps): pipeline = self.new_pipeline( name='preprocess_pipeline', desc=("Fugue distortion correction pipeline"), citations=[fsl_cite], name_maps=name_maps) reorient_epi_in = pipeline.add( 'reorient_epi_in', fsl.utils.Reorient2Std(output_type='NIFTI_GZ'), inputs={'in_file': ('series', nifti_gz_format)}, requirements=[fsl_req.v('5.0.9')]) fm_mag_reorient = pipeline.add( 'reorient_fm_mag', fsl.utils.Reorient2Std(output_type='NIFTI_GZ'), inputs={'in_file': ('field_map_mag', nifti_gz_format)}, requirements=[fsl_req.v('5.0.9')]) fm_phase_reorient = pipeline.add( 'reorient_fm_phase', fsl.utils.Reorient2Std(output_type='NIFTI_GZ'), inputs={'in_file': ('field_map_phase', nifti_gz_format)}, requirements=[fsl_req.v('5.0.9')]) bet = pipeline.add("bet", BET(robust=True, output_type='NIFTI_GZ'), inputs={'in_file': (fm_mag_reorient, 'out_file')}, wall_time=5, requirements=[fsl_req.v('5.0.9')]) create_fmap = pipeline.add( "prepfmap", PrepareFieldmap( # delta_TE=2.46 ), inputs={ 'delta_TE': ('field_map_delta_te', float), "in_magnitude": (bet, "out_file"), 'in_phase': (fm_phase_reorient, 'out_file') }, wall_time=5, requirements=[fsl_req.v('5.0.9')]) pipeline.add( 'fugue', FUGUE(unwarp_direction='x', dwell_time=self.parameter('fugue_echo_spacing'), unwarped_file='example_func.nii.gz', output_type='NIFTI_GZ'), inputs={ 'fmap_in_file': (create_fmap, 'out_fieldmap'), 'in_file': (reorient_epi_in, 'out_file') }, outputs={'series_preproc': ('unwarped_file', nifti_gz_format)}, wall_time=5, requirements=[fsl_req.v('5.0.9')]) return pipeline
def cet_T1(self, **name_maps): pipeline = self.new_pipeline( name='CET_T1', name_maps=name_maps, desc=("Construct cerebellum mask using SUIT template"), citations=[fsl_cite]) # FIXME: Should convert to inputs nl = self._lookup_nl_tfm_inv_name('MNI') linear = self._lookup_l_tfm_to_name('MNI') # Initially use MNI space to warp SUIT into T1 and threshold to mask merge_trans = pipeline.add('merge_transforms', Merge(2), inputs={ 'in2': (nl, nifti_gz_format), 'in1': (linear, nifti_gz_format) }) apply_trans = pipeline.add('ApplyTransform', ants.resampling.ApplyTransforms( interpolation='NearestNeighbor', input_image_type=3, invert_transform_flags=[True, False]), inputs={ 'reference_image': ('betted_T1', nifti_gz_format), 'input_image': ('suit_mask', nifti_gz_format), 'transforms': (merge_trans, 'out') }, requirements=[ants_req.v('1.9')], mem_gb=16, wall_time=120) pipeline.add('maths2', fsl.utils.ImageMaths(suffix='_optiBET_cerebellum', op_string='-mas'), inputs={ 'in_file': ('betted_T1', nifti_gz_format), 'in_file2': (apply_trans, 'output_image') }, outputs={ 'cetted_T1': ('out_file', nifti_gz_format), 'cetted_T1_mask': ('output_image', nifti_gz_format) }, requirements=[fsl_req.v('5.0.8')], mem_gb=16, wall_time=5) return pipeline
def bet_T2s(self, **options): pipeline = self.new_pipeline(name='BET_T2s', desc=("python implementation of BET"), default_options={}, citations=[fsl_cite], options=options) bet = pipeline.add('bet', fsl.BET(frac=0.1, mask=True, output_type='NIFTI_GZ'), inputs={'in_file': ('t2s', nifti_gz_format)}, outputs={ 'betted_T2s': ('out_file', nifti_gz_format), 'betted_T2s_mask': ('mask_file', nifti_gz_format) }, requirements=[fsl_req.v('5.0.8')], mem_gb=8, wall_time=45) pipeline.add( 'mask', fsl.utils.ImageMaths(suffix='_BET_brain', op_string='-mas', output_type='NIFTI_GZ'), inputs={ 'in_file': ('t2s_last_echo', nifti_gz_format), 'in_file2': (bet, 'mask_file') }, outputs={'betted_T2s_last_echo': ('out_file', nifti_gz_format)}, requirements=[fsl_req.v('5.0.8')], mem_gb=16, wall_time=5) return pipeline
def _fugue_pipeline(self, **kwargs): # inputs=[FilesetSpec('magnitude', nifti_gz_format), # FilesetSpec('field_map_mag', nifti_gz_format), # FilesetSpec('field_map_phase', nifti_gz_format)], # outputs=[FilesetSpec('preproc', nifti_gz_format)], pipeline = self.new_pipeline( name='preprocess_pipeline', desc=("Fugue distortion correction pipeline"), references=[fsl_cite], **kwargs) reorient_epi_in = pipeline.create_node( fsl.utils.Reorient2Std(), name='reorient_epi_in', requirements=[fsl_req.v('5.0.9')]) pipeline.connect_input('magnitude', reorient_epi_in, 'in_file') fm_mag_reorient = pipeline.create_node( fsl.utils.Reorient2Std(), name='reorient_fm_mag', requirements=[fsl_req.v('5.0.9')]) pipeline.connect_input('field_map_mag', fm_mag_reorient, 'in_file') fm_phase_reorient = pipeline.create_node( fsl.utils.Reorient2Std(), name='reorient_fm_phase', requirements=[fsl_req.v('5.0.9')]) pipeline.connect_input('field_map_phase', fm_phase_reorient, 'in_file') bet = pipeline.create_node(BET(), name="bet", wall_time=5, requirements=[fsl_req.v('5.0.9')]) bet.inputs.robust = True pipeline.connect(fm_mag_reorient, 'out_file', bet, 'in_file') create_fmap = pipeline.create_node(PrepareFieldmap(), name="prepfmap", wall_time=5, requirements=[fsl_req.v('5.0.9')]) # create_fmap.inputs.delta_TE = 2.46 pipeline.connect_input('field_map_delta_te', create_fmap, 'delta_TE') pipeline.connect(bet, "out_file", create_fmap, "in_magnitude") pipeline.connect(fm_phase_reorient, 'out_file', create_fmap, 'in_phase') fugue = pipeline.create_node(FUGUE(), name='fugue', wall_time=5, requirements=[fsl_req.v('5.0.9')]) fugue.inputs.unwarp_direction = 'x' fugue.inputs.dwell_time = self.parameter('fugue_echo_spacing') fugue.inputs.unwarped_file = 'example_func.nii.gz' pipeline.connect(create_fmap, 'out_fieldmap', fugue, 'fmap_in_file') pipeline.connect(reorient_epi_in, 'out_file', fugue, 'in_file') pipeline.connect_output('preproc', fugue, 'unwarped_file') return pipeline
def brain_extraction_pipeline(self, **name_maps): pipeline = self.new_pipeline( 'brain_extraction', desc="Extracts brain from full-head image", name_maps=name_maps, citations=[fsl_cite]) pipeline.add('bet', fsl.BET(mask=True), inputs={'in_file': ('magnitude', nifti_gz_format)}, outputs={ 'brain': ('out_file', nifti_gz_format), 'brain_mask': ('mask_file', nifti_gz_format) }, requirements=[fsl_req.v('5.0.10')]) return pipeline
def path(self): # If resolution is a string then it is assumed to be a parameter name # of the analysis if isinstance(self._resolution, str): resolution = getattr(self.analysis, self._resolution) else: resolution = self._resolution full_atlas_name = '{}_{}mm'.format(self._atlas_name, resolution) if self._dataset is not None: full_atlas_name += '_' + self._dataset fsl_ver = self.analysis.environment.satisfy(fsl_req.v('5.0.8'))[0] if hasattr(self.analysis.environment, 'load'): self.analysis.environment.load(fsl_ver) fsl_dir = os.environ['FSLDIR'] self.analysis.environment.unload(fsl_ver) else: fsl_dir = os.environ['FSLDIR'] # Static environments return op.join(fsl_dir, 'data', *self._sub_path, full_atlas_name + '.nii.gz')
def path(self): # If resolution is a string then it is assumed to be a parameter name # of the study if isinstance(self._resolution, str): resolution = self.study.parameter(self._resolution) else: resolution = self._resolution full_atlas_name = '{}_{}mm'.format(self._atlas_name, resolution) if self._dataset is not None: full_atlas_name += '_' + self._dataset try: fsl_ver = self.study.environment.load(fsl_req.v('5.0.8')) except AttributeError: pass atlas_dir = op.join(os.environ['FSLDIR'], 'data', *self._sub_path) try: self.study.environment.unload(fsl_ver) except AttributeError: pass return op.join(atlas_dir, full_atlas_name + '.nii.gz')
def bias_correct_pipeline(self, **name_maps): # @UnusedVariable @IgnorePep8 """ Corrects B1 field inhomogeneities """ # inputs=[FilesetSpec('preproc', nifti_gz_format), # FilesetSpec('brain_mask', nifti_gz_format), # FilesetSpec('grad_dirs', fsl_bvecs_format), # FilesetSpec('bvalues', fsl_bvals_format)], # outputs=[FilesetSpec('bias_correct', nifti_gz_format)], bias_method = self.parameter('bias_correct_method') pipeline = self.new_pipeline( name='bias_correct', desc="Corrects for B1 field inhomogeneity", references=[fast_cite, (n4_cite if bias_method == 'ants' else fsl_cite)], name_maps=name_maps) # Create bias correct node bias_correct = pipeline.add( "bias_correct", DWIBiasCorrect(), requirements=( [mrtrix_req.v('3.0rc3')] + [ants_req.v('2.0') if bias_method == 'ants' else fsl_req.v('5.0.9')])) bias_correct.inputs.method = bias_method # Gradient merge node fsl_grads = pipeline.add( "fsl_grads", MergeTuple(2)) # Connect nodes pipeline.connect(fsl_grads, 'out', bias_correct, 'grad_fsl') # Connect to inputs pipeline.connect_input('grad_dirs', fsl_grads, 'in1') pipeline.connect_input('bvalues', fsl_grads, 'in2') pipeline.connect_input('preproc', bias_correct, 'in_file') pipeline.connect_input('brain_mask', bias_correct, 'mask') # Connect to outputs pipeline.connect_output('bias_correct', bias_correct, 'out_file') # Check inputs/output are connected return pipeline
def qform_transform_pipeline(self, **name_maps): pipeline = self.new_pipeline( name='qform_transform', name_maps=name_maps, desc="Registers a MR scan against a reference image", references=[fsl_cite]) pipeline.add('flirt', FLIRT(uses_qform=True, apply_xfm=True), inputs={ 'in_file': ('brain', nifti_gz_format), 'reference': ('coreg_ref_brain', nifti_gz_format) }, outputs={ 'out_file': ('qformed', nifti_gz_format), 'out_matrix_file': ('qform_mat', text_matrix_format) }, requirements=[fsl_req.v('5.0.8')], wall_time=5) 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 pet_data_preparation_pipeline(self, **kwargs): pipeline = self.new_pipeline( name='pet_data_preparation', desc=("Given a folder with reconstructed PET data, this " "pipeline will prepare the data for the motion " "correction"), citations=[], **kwargs) pipeline.add('prepare_pet', PreparePetDir(image_orientation_check=self.parameter( 'image_orientation_check')), inputs={'pet_dir': ('pet_recon_dir', directory_format)}, ouputs={ 'pet_recon_dir_prepared': ('pet_dir_prepared', directory_format) }, requirements=[mrtrix_req.v('3.0rc3'), fsl_req.v('5.0.9')]) return pipeline
def _epireg_linear_brain_coreg_pipeline(self, **kwargs): pipeline = self.new_pipeline( name='linear_coreg', desc=("Intra-subjects epi registration improved using white " "matter boundaries."), references=[fsl_cite], **kwargs) pipeline.add('epireg', fsl.epi.EpiReg(out_base='epireg2ref'), inputs={ 'epi': ('brain', nifti_gz_format), 't1_brain': ('coreg_ref_brain', nifti_gz_format), 't1_head': ('coreg_ref_preproc', nifti_gz_format), 'wmseg': ('wmseg', nifti_gz_format) }, outputs={ 'out_file': ('coreg_brain', nifti_gz_format), 'epi2str_mat': ('coreg_matrix', text_matrix_format) }, requirements=[fsl_req.v('5.0.9')]) return pipeline
def umap_realignment_pipeline(self, **name_maps): pipeline = self.new_pipeline( name='umap_realignment', desc=("Pipeline to align the original umap (if provided)" "to match the head position in each frame and improve the " "static PET image quality."), citations=[fsl_cite], name_maps=name_maps) pipeline.add( 'umap2ref_alignment', UmapAlign2Reference(pct=self.parameter('align_pct')), inputs={ 'ute_regmat': ('umap_ref_coreg_matrix', text_matrix_format), 'ute_qform_mat': ('umap_ref_qform_mat', text_matrix_format), 'average_mats': ('average_mats', directory_format), 'umap': ('umap', nifti_gz_format) }, outputs={'umaps_align2ref': ('umaps_align2ref', directory_format)}, requirements=[fsl_req.v('5.0.9')]) return pipeline