コード例 #1
0
def flirt_anatomical_linear_registration(workflow, resource_pool, config):

    # resource pool should have:
    #     anatomical_brain

    import os
    import sys

    import nipype.interfaces.io as nio
    import nipype.pipeline.engine as pe

    import nipype.interfaces.utility as util

    import nipype.interfaces.fsl as fsl

    from workflow_utils import check_input_resources, \
                               check_config_settings

    from nipype.interfaces.fsl.base import Info

    if "template_brain_for_anat" not in config:
        config["template_brain_for_anat"] = Info.standard_image(
            "MNI152_T1_2mm_brain.nii.gz")
    check_config_settings(config, "template_brain_for_anat")

    if "anatomical_brain" not in resource_pool.keys():

        from anatomical_preproc import anatomical_skullstrip_workflow

        workflow, resource_pool = \
            anatomical_skullstrip_workflow(workflow, resource_pool, config)

    #check_input_resources(resource_pool, "anatomical_brain")

    calc_flirt_warp = pe.Node(interface=fsl.FLIRT(), name='calc_flirt_warp')

    calc_flirt_warp.inputs.cost = 'corratio'

    if len(resource_pool["anatomical_brain"]) == 2:
        node, out_file = resource_pool["anatomical_brain"]
        workflow.connect(node, out_file, calc_flirt_warp, 'in_file')
    else:
        calc_flirt_warp.inputs.in_file = resource_pool["anatomical_brain"]

    calc_flirt_warp.inputs.reference = config["template_brain_for_anat"]

    resource_pool["flirt_affine_xfm"] = (calc_flirt_warp, 'out_matrix_file')

    resource_pool["flirt_linear_warped_image"] = (calc_flirt_warp, 'out_file')

    return workflow, resource_pool
コード例 #2
0
def flirt_anatomical_linear_registration(workflow, resource_pool, config):

    # resource pool should have:
    #     anatomical_brain

    import os
    import sys

    import nipype.interfaces.io as nio
    import nipype.pipeline.engine as pe

    import nipype.interfaces.utility as util

    import nipype.interfaces.fsl as fsl

    from workflow_utils import check_input_resources, check_config_settings

    from nipype.interfaces.fsl.base import Info

    if "template_brain_for_anat" not in config:
        config["template_brain_for_anat"] = Info.standard_image("MNI152_T1_2mm_brain.nii.gz")
    check_config_settings(config, "template_brain_for_anat")

    if "anatomical_brain" not in resource_pool.keys():

        from anatomical_preproc import anatomical_skullstrip_workflow

        workflow, resource_pool = anatomical_skullstrip_workflow(workflow, resource_pool, config)

    # check_input_resources(resource_pool, "anatomical_brain")

    calc_flirt_warp = pe.Node(interface=fsl.FLIRT(), name="calc_flirt_warp")

    calc_flirt_warp.inputs.cost = "corratio"

    if len(resource_pool["anatomical_brain"]) == 2:
        node, out_file = resource_pool["anatomical_brain"]
        workflow.connect(node, out_file, calc_flirt_warp, "in_file")
    else:
        calc_flirt_warp.inputs.in_file = resource_pool["anatomical_brain"]

    calc_flirt_warp.inputs.reference = config["template_brain_for_anat"]

    resource_pool["flirt_affine_xfm"] = (calc_flirt_warp, "out_matrix_file")

    resource_pool["flirt_linear_warped_image"] = (calc_flirt_warp, "out_file")

    return workflow, resource_pool
コード例 #3
0
ファイル: dti.py プロジェクト: carlohamalainen/nipype
 def _format_arg(self, name, spec, value):
     if name == "project_data":
         if isdefined(value) and value:
             _si = self.inputs
             if isdefined(_si.use_cingulum_mask) and _si.use_cingulum_mask:
                 mask_file = Info.standard_image("LowerCingulum_1mm.nii.gz")
             else:
                 mask_file = _si.search_mask_file
             if not isdefined(_si.projected_data):
                 proj_file = self._list_outputs()["projected_data"]
             else:
                 proj_file = _si.projected_data
             return spec.argstr % (_si.threshold, _si.distance_map, mask_file, _si.data_file, proj_file)
     elif name == "skeleton_file":
         if isinstance(value, bool):
             return spec.argstr % self._list_outputs()["skeleton_file"]
         else:
             return spec.argstr % value
     return super(TractSkeleton, self)._format_arg(name, spec, value)
コード例 #4
0
ファイル: dti.py プロジェクト: cindeem/nipype
 def _format_arg(self, name, spec, value):
     if name == "project_data":
         if isdefined(value) and value:
             _si = self.inputs
             if isdefined(_si.use_cingulum_mask) and _si.use_cingulum_mask:
                 mask_file = Info.standard_image("LowerCingulum_1mm.nii.gz")
             else:
                 mask_file = _si.search_mask_file
             if not isdefined(_si.projected_data):
                 proj_file = self._list_outputs()["projected_data"]
             else:
                 proj_file = _si.projected_data
             return spec.argstr % (_si.threshold, _si.distance_map,
                                   mask_file, _si.data_file, proj_file)
     elif name == "skeleton_file":
         if isinstance(value, bool):
             return spec.argstr % self._list_outputs()["skeleton_file"]
         else:
             return spec.argstr % value
     return super(TractSkeleton, self)._format_arg(name, spec, value)
コード例 #5
0
def qap_mask_workflow(workflow, resource_pool, config):

    import os
    import sys

    import nipype.interfaces.io as nio
    import nipype.pipeline.engine as pe

    import nipype.interfaces.utility as niu
    import nipype.interfaces.fsl.maths as fsl
    from nipype.interfaces.fsl.base import Info

    from qap_workflows_utils import select_thresh, slice_head_mask

    from workflow_utils import check_input_resources, check_config_settings

    # check_input_resources(resource_pool, 'anatomical_reorient')
    # check_input_resources(resource_pool, 'ants_affine_xfm')
    if "template_skull_for_anat" not in config:
        config["template_skull_for_anat"] = Info.standard_image("MNI152_T1_2mm.nii.gz")

    check_config_settings(config, "template_skull_for_anat")

    if "flirt_affine_xfm" not in resource_pool.keys():

        from anatomical_preproc import flirt_anatomical_linear_registration

        workflow, resource_pool = flirt_anatomical_linear_registration(workflow, resource_pool, config)

    if "anatomical_reorient" not in resource_pool.keys():

        from anatomical_preproc import anatomical_reorient_workflow

        workflow, resource_pool = anatomical_reorient_workflow(workflow, resource_pool, config)

    select_thresh = pe.Node(
        niu.Function(input_names=["input_skull"], output_names=["thresh_out"], function=select_thresh),
        name="qap_headmask_select_thresh",
        iterfield=["input_skull"],
    )

    mask_skull = pe.Node(fsl.Threshold(args="-bin"), name="qap_headmask_thresh")

    dilate_node = pe.Node(fsl.MathsCommand(args="-dilM -dilM -dilM -dilM -dilM -dilM"), name="qap_headmask_dilate")

    erode_node = pe.Node(fsl.MathsCommand(args="-eroF -eroF -eroF -eroF -eroF -eroF"), name="qap_headmask_erode")

    slice_head_mask = pe.Node(
        niu.Function(
            input_names=["infile", "transform", "standard"], output_names=["outfile_path"], function=slice_head_mask
        ),
        name="qap_headmask_slice_head_mask",
    )

    combine_masks = pe.Node(fsl.BinaryMaths(operation="add", args="-bin"), name="qap_headmask_combine_masks")

    if len(resource_pool["anatomical_reorient"]) == 2:
        node, out_file = resource_pool["anatomical_reorient"]
        workflow.connect(
            [
                (node, select_thresh, [(out_file, "input_skull")]),
                (node, mask_skull, [(out_file, "in_file")]),
                (node, slice_head_mask, [(out_file, "infile")]),
            ]
        )
    else:
        select_thresh.inputs.input_skull = resource_pool["anatomical_reorient"]
        mask_skull.inputs.in_file = resource_pool["anatomical_reorient"]
        # convert_fsl_xfm.inputs.infile =
        #    resource_pool['anatomical_reorient']
        slice_head_mask.inputs.infile = resource_pool["anatomical_reorient"]

    if len(resource_pool["flirt_affine_xfm"]) == 2:
        node, out_file = resource_pool["flirt_affine_xfm"]
        workflow.connect(node, out_file, slice_head_mask, "transform")
    else:
        slice_head_mask.inputs.transform = resource_pool["flirt_affine_xfm"]

    # convert_fsl_xfm.inputs.standard = config['template_skull_for_anat']
    slice_head_mask.inputs.standard = config["template_skull_for_anat"]

    workflow.connect(
        [
            (select_thresh, mask_skull, [("thresh_out", "thresh")]),
            # (convert_fsl_xfm, slice_head_mask, [('converted_xfm', 'transform')])
            (mask_skull, dilate_node, [("out_file", "in_file")]),
            (dilate_node, erode_node, [("out_file", "in_file")]),
            (erode_node, combine_masks, [("out_file", "in_file")]),
            (slice_head_mask, combine_masks, [("outfile_path", "operand_file")]),
        ]
    )

    resource_pool["qap_head_mask"] = (combine_masks, "out_file")
    return workflow, resource_pool
コード例 #6
0
def ants_anatomical_linear_registration(workflow, resource_pool, config):

    # resource pool should have:
    #     anatomical_brain

    # linear ANTS registration takes roughly 2.5 minutes per subject running
    # on one core of an Intel Core i7-4800MQ CPU @ 2.70GHz

    import os
    import sys

    import nipype.interfaces.io as nio
    import nipype.pipeline.engine as pe

    import nipype.interfaces.utility as util

    from anatomical_preproc_utils import ants_lin_reg, \
                                         separate_warps_list

    from workflow_utils import check_input_resources, \
                               check_config_settings
    from nipype.interfaces.fsl.base import Info

    if "template_brain_for_anat" not in config:
        config["template_brain_for_anat"] = Info.standard_image(
            "MNI152_T1_2mm_brain.nii.gz")
    check_config_settings(config, "template_brain_for_anat")

    if "anatomical_brain" not in resource_pool.keys():

        from anatomical_preproc import anatomical_skullstrip_workflow

        workflow, resource_pool = \
            anatomical_skullstrip_workflow(workflow, resource_pool, config)

    #check_input_resources(resource_pool, "anatomical_brain")

    calc_ants_warp = pe.Node(interface=util.Function(
        input_names=['anatomical_brain', 'reference_brain'],
        output_names=['warp_list', 'warped_image'],
        function=ants_lin_reg),
                             name='calc_ants_linear_warp')

    select_forward_initial = pe.Node(util.Function(
        input_names=['warp_list', 'selection'],
        output_names=['selected_warp'],
        function=separate_warps_list),
                                     name='select_forward_initial')

    select_forward_initial.inputs.selection = "Initial"

    select_forward_rigid = pe.Node(util.Function(
        input_names=['warp_list', 'selection'],
        output_names=['selected_warp'],
        function=separate_warps_list),
                                   name='select_forward_rigid')

    select_forward_rigid.inputs.selection = "Rigid"

    select_forward_affine = pe.Node(util.Function(
        input_names=['warp_list', 'selection'],
        output_names=['selected_warp'],
        function=separate_warps_list),
                                    name='select_forward_affine')

    select_forward_affine.inputs.selection = "Affine"

    if len(resource_pool["anatomical_brain"]) == 2:
        node, out_file = resource_pool["anatomical_brain"]
        workflow.connect(node, out_file, calc_ants_warp, 'anatomical_brain')
    else:
        calc_ants_warp.inputs.anatomical_brain = \
             resource_pool["anatomical_brain"]

    calc_ants_warp.inputs.reference_brain = config["template_brain_for_anat"]

    workflow.connect(calc_ants_warp, 'warp_list', select_forward_initial,
                     'warp_list')

    workflow.connect(calc_ants_warp, 'warp_list', select_forward_rigid,
                     'warp_list')

    workflow.connect(calc_ants_warp, 'warp_list', select_forward_affine,
                     'warp_list')


    resource_pool["ants_initial_xfm"] = \
        (select_forward_initial, 'selected_warp')

    resource_pool["ants_rigid_xfm"] = (select_forward_rigid, 'selected_warp')

    resource_pool["ants_affine_xfm"] = \
        (select_forward_affine, 'selected_warp')

    resource_pool["ants_linear_warped_image"] = \
        (calc_ants_warp, 'warped_image')

    return workflow, resource_pool
コード例 #7
0
ファイル: qap_workflows.py プロジェクト: wangkangcheng/ccc
def qap_mask_workflow(workflow, resource_pool, config):

    import os
    import sys

    import nipype.interfaces.io as nio
    import nipype.pipeline.engine as pe

    import nipype.interfaces.utility as niu
    import nipype.interfaces.fsl.maths as fsl
    from nipype.interfaces.fsl.base import Info

    from qap_workflows_utils import select_thresh, \
        slice_head_mask

    from workflow_utils import check_input_resources, \
        check_config_settings

    # check_input_resources(resource_pool, 'anatomical_reorient')
    # check_input_resources(resource_pool, 'ants_affine_xfm')
    if 'template_skull_for_anat' not in config:
        config['template_skull_for_anat'] = Info.standard_image(
            'MNI152_T1_2mm.nii.gz')

    check_config_settings(config, 'template_skull_for_anat')

    if 'flirt_affine_xfm' not in resource_pool.keys():

        from anatomical_preproc import flirt_anatomical_linear_registration

        workflow, resource_pool = \
            flirt_anatomical_linear_registration(workflow, resource_pool,
                                                 config)

    if 'anatomical_reorient' not in resource_pool.keys():

        from anatomical_preproc import anatomical_reorient_workflow

        workflow, resource_pool = \
            anatomical_reorient_workflow(workflow, resource_pool, config)

    select_thresh = pe.Node(niu.Function(input_names=['input_skull'],
                                         output_names=['thresh_out'],
                                         function=select_thresh),
                            name='qap_headmask_select_thresh',
                            iterfield=['input_skull'])

    mask_skull = pe.Node(fsl.Threshold(args='-bin'),
                         name='qap_headmask_thresh')

    dilate_node = pe.Node(
        fsl.MathsCommand(args='-dilM -dilM -dilM -dilM -dilM -dilM'),
        name='qap_headmask_dilate')

    erode_node = pe.Node(
        fsl.MathsCommand(args='-eroF -eroF -eroF -eroF -eroF -eroF'),
        name='qap_headmask_erode')

    slice_head_mask = pe.Node(niu.Function(
        input_names=['infile', 'transform', 'standard'],
        output_names=['outfile_path'],
        function=slice_head_mask),
                              name='qap_headmask_slice_head_mask')

    combine_masks = pe.Node(fsl.BinaryMaths(operation='add', args='-bin'),
                            name='qap_headmask_combine_masks')

    if len(resource_pool['anatomical_reorient']) == 2:
        node, out_file = resource_pool['anatomical_reorient']
        workflow.connect([(node, select_thresh, [(out_file, 'input_skull')]),
                          (node, mask_skull, [(out_file, 'in_file')]),
                          (node, slice_head_mask, [(out_file, 'infile')])])
    else:
        select_thresh.inputs.input_skull = resource_pool['anatomical_reorient']
        mask_skull.inputs.in_file = resource_pool['anatomical_reorient']
        # convert_fsl_xfm.inputs.infile =
        #    resource_pool['anatomical_reorient']
        slice_head_mask.inputs.infile = resource_pool['anatomical_reorient']

    if len(resource_pool['flirt_affine_xfm']) == 2:
        node, out_file = resource_pool['flirt_affine_xfm']
        workflow.connect(node, out_file, slice_head_mask, 'transform')
    else:
        slice_head_mask.inputs.transform = resource_pool['flirt_affine_xfm']

    # convert_fsl_xfm.inputs.standard = config['template_skull_for_anat']
    slice_head_mask.inputs.standard = config['template_skull_for_anat']

    workflow.connect([
        (select_thresh, mask_skull, [('thresh_out', 'thresh')]),
        # (convert_fsl_xfm, slice_head_mask, [('converted_xfm', 'transform')])
        (mask_skull, dilate_node, [('out_file', 'in_file')]),
        (dilate_node, erode_node, [('out_file', 'in_file')]),
        (erode_node, combine_masks, [('out_file', 'in_file')]),
        (slice_head_mask, combine_masks, [('outfile_path', 'operand_file')])
    ])

    resource_pool['qap_head_mask'] = (combine_masks, 'out_file')
    return workflow, resource_pool
コード例 #8
0
def ants_anatomical_linear_registration(workflow, resource_pool, config):

    # resource pool should have:
    #     anatomical_brain

    # linear ANTS registration takes roughly 2.5 minutes per subject running
    # on one core of an Intel Core i7-4800MQ CPU @ 2.70GHz

    import os
    import sys

    import nipype.interfaces.io as nio
    import nipype.pipeline.engine as pe

    import nipype.interfaces.utility as util

    from anatomical_preproc_utils import ants_lin_reg, separate_warps_list

    from workflow_utils import check_input_resources, check_config_settings
    from nipype.interfaces.fsl.base import Info

    if "template_brain_for_anat" not in config:
        config["template_brain_for_anat"] = Info.standard_image("MNI152_T1_2mm_brain.nii.gz")
    check_config_settings(config, "template_brain_for_anat")

    if "anatomical_brain" not in resource_pool.keys():

        from anatomical_preproc import anatomical_skullstrip_workflow

        workflow, resource_pool = anatomical_skullstrip_workflow(workflow, resource_pool, config)

    # check_input_resources(resource_pool, "anatomical_brain")

    calc_ants_warp = pe.Node(
        interface=util.Function(
            input_names=["anatomical_brain", "reference_brain"],
            output_names=["warp_list", "warped_image"],
            function=ants_lin_reg,
        ),
        name="calc_ants_linear_warp",
    )

    select_forward_initial = pe.Node(
        util.Function(
            input_names=["warp_list", "selection"], output_names=["selected_warp"], function=separate_warps_list
        ),
        name="select_forward_initial",
    )

    select_forward_initial.inputs.selection = "Initial"

    select_forward_rigid = pe.Node(
        util.Function(
            input_names=["warp_list", "selection"], output_names=["selected_warp"], function=separate_warps_list
        ),
        name="select_forward_rigid",
    )

    select_forward_rigid.inputs.selection = "Rigid"

    select_forward_affine = pe.Node(
        util.Function(
            input_names=["warp_list", "selection"], output_names=["selected_warp"], function=separate_warps_list
        ),
        name="select_forward_affine",
    )

    select_forward_affine.inputs.selection = "Affine"

    if len(resource_pool["anatomical_brain"]) == 2:
        node, out_file = resource_pool["anatomical_brain"]
        workflow.connect(node, out_file, calc_ants_warp, "anatomical_brain")
    else:
        calc_ants_warp.inputs.anatomical_brain = resource_pool["anatomical_brain"]

    calc_ants_warp.inputs.reference_brain = config["template_brain_for_anat"]

    workflow.connect(calc_ants_warp, "warp_list", select_forward_initial, "warp_list")

    workflow.connect(calc_ants_warp, "warp_list", select_forward_rigid, "warp_list")

    workflow.connect(calc_ants_warp, "warp_list", select_forward_affine, "warp_list")

    resource_pool["ants_initial_xfm"] = (select_forward_initial, "selected_warp")

    resource_pool["ants_rigid_xfm"] = (select_forward_rigid, "selected_warp")

    resource_pool["ants_affine_xfm"] = (select_forward_affine, "selected_warp")

    resource_pool["ants_linear_warped_image"] = (calc_ants_warp, "warped_image")

    return workflow, resource_pool