def build_core_nodes(self): """Build and connect the core nodes of the pipelines. """ import nipype.interfaces.fsl as fsl import nipype.interfaces.utility as nutil import nipype.pipeline.engine as npe import clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_utils as utils import clinica.pipelines.dwi_preprocessing_using_t1.dwi_preprocessing_using_t1_workflows as workflows from clinica.utils.dwi import prepare_reference_b0 from clinica.workflows.dwi_preprocessing import ( ecc_pipeline, hmc_pipeline, remove_bias, ) # Nodes creation # ============== # Prepare b0 image for further corrections prepare_b0 = npe.Node(name="PrepareB0", interface=nutil.Function( input_names=['in_dwi', 'in_bval', 'in_bvec', 'low_bval'], output_names=['out_reference_b0', 'out_b0_dwi_merge', 'out_updated_bval', 'out_updated_bvec'], function=prepare_reference_b0)) prepare_b0.inputs.low_bval = self.parameters['low_bval'] # Mask b0 for computations purposes mask_b0_pre = npe.Node(fsl.BET(frac=0.3, mask=True, robust=True), name='PreMaskB0') # Head-motion correction hmc = hmc_pipeline(name='HeadMotionCorrection') # Eddy-currents correction ecc = ecc_pipeline(name='EddyCurrentCorrection') # Susceptibility distortion correction using T1w image sdc = workflows.susceptibility_distortion_correction_using_t1( name='SusceptibilityDistortionCorrection') # Remove bias correction bias = remove_bias(name='RemoveBias') # Apply all corrections aac = workflows.apply_all_corrections_using_ants( name='ApplyAllCorrections') print_begin_message = npe.Node( interface=nutil.Function( input_names=['in_bids_or_caps_file'], function=utils.print_begin_pipeline), name='Write-Begin_Message') print_end_message = npe.Node( interface=nutil.Function( input_names=['in_bids_or_caps_file', 'final_file'], function=utils.print_end_pipeline), name='Write-End_Message') # Connection # ========== self.connect([ # Print begin message (self.input_node, print_begin_message, [('dwi', 'in_bids_or_caps_file')]), # noqa # Preliminary step (possible computation of a mean b0): (self.input_node, prepare_b0, [('dwi', 'in_dwi'), # noqa ('bval', 'in_bval'), # noqa ('bvec', 'in_bvec')]), # noqa # Mask b0 before corrections (prepare_b0, mask_b0_pre, [('out_reference_b0', 'in_file')]), # noqa # Head-motion correction (prepare_b0, hmc, [('out_b0_dwi_merge', 'inputnode.in_file'), # noqa ('out_updated_bval', 'inputnode.in_bval'), # noqa ('out_updated_bvec', 'inputnode.in_bvec')]), # noqa (mask_b0_pre, hmc, [('mask_file', 'inputnode.in_mask')]), # noqa # Eddy-current correction (hmc, ecc, [('outputnode.out_xfms', 'inputnode.in_xfms')]), # noqa (prepare_b0, ecc, [('out_b0_dwi_merge', 'inputnode.in_file')]), # noqa (prepare_b0, ecc, [('out_updated_bval', 'inputnode.in_bval')]), # noqa (mask_b0_pre, ecc, [('mask_file', 'inputnode.in_mask')]), # noqa # Magnetic susceptibility correction (self.input_node, sdc, [('T1w', 'inputnode.in_t1')]), # noqa (ecc, sdc, [('outputnode.out_file', 'inputnode.in_dwi')]), # noqa (hmc, sdc, [('outputnode.out_bvec', 'inputnode.in_bvec')]), # noqa # Apply all corrections (prepare_b0, aac, [('out_b0_dwi_merge', 'inputnode.in_dwi')]), # noqa (hmc, aac, [('outputnode.out_xfms', 'inputnode.in_hmc')]), # noqa (ecc, aac, [('outputnode.out_xfms', 'inputnode.in_ecc')]), # noqa (sdc, aac, [('outputnode.out_warp', 'inputnode.in_sdc_syb')]), # noqa (self.input_node, aac, [('T1w', 'inputnode.in_t1')]), # noqa # Bias correction (aac, bias, [('outputnode.out_file', 'inputnode.in_file')]), # Outputnode: (bias, self.output_node, [('outputnode.out_file', 'preproc_dwi')]), # noqa (sdc, self.output_node, [('outputnode.out_bvec', 'preproc_bvec')]), # noqa (prepare_b0, self.output_node, [('out_updated_bval', 'preproc_bval')]), # noqa (bias, self.output_node, [('outputnode.b0_mask', 'b0_mask')]), # noqa # Print end message (self.input_node, print_end_message, [('dwi', 'in_bids_or_caps_file')]), # noqa (bias, print_end_message, [('outputnode.out_file', 'final_file')]), # noqa ])
def build_core_nodes(self): """Build and connect the core nodes of the pipeline. """ import nipype.interfaces.utility as nutil import nipype.pipeline.engine as npe import nipype.interfaces.fsl as fsl from nipype.workflows.dmri.fsl.utils import apply_all_corrections from clinica.utils.dwi import prepare_reference_b0 from clinica.workflows.dwi_preprocessing import ecc_pipeline from clinica.workflows.dwi_preprocessing import hmc_pipeline from clinica.workflows.dwi_preprocessing import remove_bias import clinica.pipelines.dwi_preprocessing_using_phasediff_fieldmap.dwi_preprocessing_using_phasediff_fieldmap_workflows as workflows # Nodes creation # ============== # Prepare b0 image for further corrections prepare_b0 = npe.Node( name="PrepareB0", interface=nutil.Function( input_names=['in_dwi', 'in_bval', 'in_bvec', 'low_bval'], output_names=[ 'out_reference_b0', 'out_b0_dwi_merge', 'out_updated_bval', 'out_updated_bvec' ], function=prepare_reference_b0)) prepare_b0.inputs.low_bval = self.parameters['low_bval'] # Mask b0 for computations purposes mask_b0_pre = npe.Node(fsl.BET(frac=0.3, mask=True, robust=True), name='PreMaskB0') # Head-motion correction hmc = hmc_pipeline(name='HeadMotionCorrection') # Eddy-currents correction ecc = ecc_pipeline(name='EddyCurrentCorrection') # Susceptibility distortion correction using fmap sdc = workflows.susceptibility_distortion_correction_using_phasediff_fmap( register_fmap_on_b0=True, name='SusceptibilityDistortionCorrection') # Apply all corrections unwarp = apply_all_corrections(name='ApplyAllCorrections') # Remove bias correction bias = remove_bias(name='RemoveBias') # # Connection # ========== self.connect([ # Preliminary step (possible computation of a mean b0) ( self.input_node, prepare_b0, [ ('dwi', 'in_dwi'), # noqa ('bval', 'in_bval'), # noqa ('bvec', 'in_bvec') ]), # noqa # Mask b0 before corrections (prepare_b0, mask_b0_pre, [('out_reference_b0', 'in_file')] ), # noqa # Head-motion correction ( prepare_b0, hmc, [ ('out_b0_dwi_merge', 'inputnode.in_file'), # noqa ('out_updated_bval', 'inputnode.in_bval'), # noqa ('out_updated_bvec', 'inputnode.in_bvec') ]), # noqa (mask_b0_pre, hmc, [('mask_file', 'inputnode.in_mask')]), # noqa # Eddy-current correction (hmc, ecc, [('outputnode.out_xfms', 'inputnode.in_xfms')]), # noqa (prepare_b0, ecc, [('out_b0_dwi_merge', 'inputnode.in_file') ]), # noqa (prepare_b0, ecc, [('out_updated_bval', 'inputnode.in_bval') ]), # noqa (mask_b0_pre, ecc, [('mask_file', 'inputnode.in_mask')]), # noqa # Magnetic susceptibility correction (ecc, sdc, [('outputnode.out_file', 'inputnode.in_dwi')]), # noqa (mask_b0_pre, sdc, [('mask_file', 'inputnode.in_mask')]), # noqa (self.input_node, sdc, [('fmap_phasediff', 'inputnode.in_fmap_phasediff')]), # noqa (self.input_node, sdc, [('fmap_magnitude', 'inputnode.in_fmap_magnitude')]), # noqa (self.input_node, sdc, [('delta_echo_time', 'inputnode.delta_echo_time')]), # noqa (self.input_node, sdc, [ ('effective_echo_spacing', 'inputnode.effective_echo_spacing') ]), # noqa (self.input_node, sdc, [('phase_encoding_direction', 'inputnode.phase_encoding_direction') ]), # noqa # Apply all corrections (prepare_b0, unwarp, [('out_b0_dwi_merge', 'inputnode.in_dwi')] ), # noqa (hmc, unwarp, [('outputnode.out_xfms', 'inputnode.in_hmc') ]), # noqa (ecc, unwarp, [('outputnode.out_xfms', 'inputnode.in_ecc') ]), # noqa (sdc, unwarp, [('outputnode.out_warp', 'inputnode.in_sdc') ]), # noqa # Bias correction (unwarp, bias, [('outputnode.out_file', 'inputnode.in_file')]), # Outputnode (bias, self.output_node, [('outputnode.out_file', 'preproc_dwi')] ), # noqa (hmc, self.output_node, [('outputnode.out_bvec', 'preproc_bvec') ]), # noqa (prepare_b0, self.output_node, [('out_updated_bval', 'preproc_bval')]), # noqa (bias, self.output_node, [('outputnode.b0_mask', 'b0_mask')] ) # noqa ])