Esempio n. 1
0
def tissue_seg_EPI_template_based(wf, cfg, strat_pool, pipe_num, opt=None):
    '''
    {"name": "tissue_seg_EPI_template_based",
     "config": ["segmentation"],
     "switch": ["run"],
     "option_key": ["tissue_segmentation", "using"],
     "option_val": "Template_Based",
     "inputs": [("desc-mean_bold",
                 "from-template_to-bold_mode-image_desc-linear_xfm")],
     "outputs": ["space-bold_label-CSF_mask",
                 "space-bold_label-GM_mask",
                 "space-bold_label-WM_mask"]}
    '''

    xfm_prov = strat_pool.get_cpac_provenance(
        'from-template_to-bold_mode-image_desc-linear_xfm')
    reg_tool = check_prov_for_regtool(xfm_prov)
    use_ants = reg_tool == 'ants'

    csf_template2t1 = tissue_mask_template_to_t1('CSF', use_ants)
    csf_template2t1.inputs.inputspec.tissue_mask_template = cfg[
        'segmentation']['tissue_segmentation']['Template_Based']['CSF']

    gm_template2t1 = tissue_mask_template_to_t1('GM', use_ants)
    gm_template2t1.inputs.inputspec.tissue_mask_template = cfg[
        'segmentation']['tissue_segmentation']['Template_Based']['GRAY']

    wm_template2t1 = tissue_mask_template_to_t1('WM', use_ants)
    wm_template2t1.inputs.inputspec.tissue_mask_template = cfg[
        'segmentation']['tissue_segmentation']['Template_Based']['WHITE']

    node, out = strat_pool.get_data('desc-mean_bold')
    wf.connect(node, out, csf_template2t1, 'inputspec.brain')
    wf.connect(node, out, gm_template2t1, 'inputspec.brain')
    wf.connect(node, out, wm_template2t1, 'inputspec.brain')

    node, out = \
        strat_pool.get_data(
            'from-template_to-bold_mode-image_desc-linear_xfm')
    wf.connect(node, out,
               csf_template2t1, 'inputspec.standard2highres_mat')
    wf.connect(node, out,
               wm_template2t1, 'inputspec.standard2highres_mat')
    wf.connect(node, out,
               gm_template2t1, 'inputspec.standard2highres_mat')

    outputs = {
        'space-bold_label-CSF_mask': (csf_template2t1,
                                      'outputspec.segment_mask_temp2t1'),
        'space-bold_label-GM_mask': (gm_template2t1,
                                     'outputspec.segment_mask_temp2t1'),
        'space-bold_label-WM_mask': (wm_template2t1,
                                     'outputspec.segment_mask_temp2t1')
    }

    return (wf, outputs)
Esempio n. 2
0
def warp_longitudinal_T1w_to_template(wf, cfg, strat_pool, pipe_num, opt=None):
    '''
    {"name": "warp_longitudinal_T1w_to_template",
     "config": ["longitudinal_template_generation"],
     "switch": ["run"],
     "option_key": "None",
     "option_val": "None",
     "inputs": [("space-longitudinal_desc-brain_T1w",
                 "from-longitudinal_to-template_mode-image_xfm")],
     "outputs": ["space-template_desc-brain_T1w"]}
    '''

    xfm_prov = strat_pool.get_cpac_provenance(
        'from-longitudinal_to-template_mode-image_xfm')
    reg_tool = check_prov_for_regtool(xfm_prov)

    num_cpus = cfg.pipeline_setup['system_config']['max_cores_per_participant']

    num_ants_cores = cfg.pipeline_setup['system_config']['num_ants_threads']

    apply_xfm = apply_transform(f'warp_longitudinal_to_T1template_{pipe_num}',
                                reg_tool,
                                time_series=False,
                                num_cpus=num_cpus,
                                num_ants_cores=num_ants_cores)

    if reg_tool == 'ants':
        apply_xfm.inputs.inputspec.interpolation = cfg.registration_workflows[
            'anatomical_registration']['registration']['ANTs']['interpolation']
    elif reg_tool == 'fsl':
        apply_xfm.inputs.inputspec.interpolation = cfg.registration_workflows[
            'anatomical_registration']['registration']['FSL-FNIRT'][
                'interpolation']

    node, out = strat_pool.get_data("space-longitudinal_desc-brain_T1w")
    wf.connect(node, out, apply_xfm, 'inputspec.input_image')

    node, out = strat_pool.get_data("T1w_brain_template")
    wf.connect(node, out, apply_xfm, 'inputspec.reference')

    node, out = \
        strat_pool.get_data("from-longitudinal_to-template_mode-image_xfm")
    wf.connect(node, out, apply_xfm, 'inputspec.transform')

    outputs = {
        'space-template_desc-brain_T1w': (apply_xfm, 'outputspec.output_image')
    }

    return (wf, outputs)
Esempio n. 3
0
def tissue_seg_fsl_fast(wf, cfg, strat_pool, pipe_num, opt=None):
    '''
    {"name": "tissue_seg_fsl_fast",
     "config": ["segmentation"],
     "switch": ["run"],
     "option_key": ["tissue_segmentation", "using"],
     "option_val": "FSL-FAST",
     "inputs": [(["desc-brain_T1w", "space-longitudinal_desc-brain_T1w"],
                 ["space-T1w_desc-brain_mask",
                  "space-longitudinal_desc-brain_mask"],
                 ["from-template_to-T1w_mode-image_desc-linear_xfm",
                  "from-template_to-longitudinal_mode-image_desc-linear_xfm"]),
                "CSF_path",
                "GM_path",
                "WM_path"],
     "outputs": ["label-CSF_mask", "label-GM_mask", "label-WM_mask",
                 "label-CSF_desc-preproc_mask", "label-GM_desc-preproc_mask",
                 "label-WM_desc-preproc_mask",
                 "label-CSF_probseg", "label-GM_probseg", "label-WM_probseg",
                 "space-longitudinal_label-CSF_mask",
                 "space-longitudinal_label-GM_mask",
                 "space-longitudinal_label-WM_mask",
                 "space-longitudinal_label-CSF_desc-preproc_mask",
                 "space-longitudinal_label-GM_desc-preproc_mask",
                 "space-longitudinal_label-WM_desc-preproc_mask",
                 "space-longitudinal_label-CSF_probseg",
                 "space-longitudinal_label-GM_probseg",
                 "space-longitudinal_label-WM_probseg"]}
    '''

    # FSL-FAST
    #  'tissue_class_files' output is a list of individual binary tissue masks
    #      triggered by 'segments' boolean input (-g or --segments)
    #  'probability_maps' output is a list of individual probability maps
    #      triggered by 'probability_maps' boolean input (-p)

    segment = pe.Node(interface=fsl.FAST(), name=f'segment_{pipe_num}')
    segment.inputs.img_type = 1
    segment.inputs.segments = True
    segment.inputs.probability_maps = True
    segment.inputs.out_basename = 'segment'

    check_wm = pe.Node(name='check_wm',
                       interface=Function(function=check_if_file_is_empty,
                                          input_names=['in_file'],
                                          output_names=['out_file']))
    check_gm = pe.Node(name='check_gm',
                       interface=Function(function=check_if_file_is_empty,
                                          input_names=['in_file'],
                                          output_names=['out_file']))
    check_csf = pe.Node(name='check_csf', interface=Function(
        function=check_if_file_is_empty, input_names=['in_file'],
        output_names=['out_file']))

    connect, resource = \
        strat_pool.get_data(["desc-brain_T1w",
                             "space-longitudinal_desc-brain_T1w"],
                            report_fetched=True)
    node, out = connect
    wf.connect(node, out, segment, 'in_files')

    long = ''
    xfm = 'from-template_to-T1w_mode-image_desc-linear_xfm'
    if 'space-longitudinal' in resource:
        long = 'space-longitudinal_'
        xfm = 'from-template_to-longitudinal_mode-image_desc-linear_xfm'

    use_custom_threshold = cfg['segmentation']['tissue_segmentation'][
                               'FSL-FAST']['thresholding'][
                               'use'] == 'Custom'

    use_priors = cfg['segmentation']['tissue_segmentation'][
        'FSL-FAST']['use_priors']['run']

    xfm_prov = strat_pool.get_cpac_provenance(xfm)
    reg_tool = check_prov_for_regtool(xfm_prov)

    process_csf = process_segment_map(f'CSF_{pipe_num}', use_priors,
                                      use_custom_threshold, reg_tool)
    process_csf.inputs.inputspec.threshold = cfg['segmentation'][
        'tissue_segmentation']['FSL-FAST']['thresholding']['Custom'][
        'CSF_threshold_value']

    if use_priors:
        node, out = strat_pool.get_data('CSF_path')
        wf.connect(node, out, process_csf, 'inputspec.tissue_prior')

    process_gm = process_segment_map(f'GM_{pipe_num}', use_priors,
                                     use_custom_threshold, reg_tool)
    process_gm.inputs.inputspec.threshold = cfg['segmentation'][
        'tissue_segmentation']['FSL-FAST']['thresholding']['Custom'][
        'GM_threshold_value']

    if use_priors:
        node, out = strat_pool.get_data('GM_path')
        wf.connect(node, out, process_gm, 'inputspec.tissue_prior')

    process_wm = process_segment_map(f'WM_{pipe_num}', use_priors,
                                     use_custom_threshold, reg_tool)
    process_wm.inputs.inputspec.threshold = cfg['segmentation'][
        'tissue_segmentation']['FSL-FAST']['thresholding']['Custom'][
        'WM_threshold_value']

    if use_priors:
        node, out = strat_pool.get_data('WM_path')
        wf.connect(node, out, process_wm, 'inputspec.tissue_prior')

    node, out = strat_pool.get_data(["desc-brain_T1w",
                                     "space-longitudinal_desc-brain_T1w"])
    wf.connect(node, out, process_csf, 'inputspec.brain')
    wf.connect(node, out, process_gm, 'inputspec.brain')
    wf.connect(node, out, process_wm, 'inputspec.brain')

    node, out = strat_pool.get_data(["space-T1w_desc-brain_mask",
                                     "space-longitudinal_desc-brain_mask"])
    wf.connect(node, out, process_csf, 'inputspec.brain_mask')
    wf.connect(node, out, process_gm, 'inputspec.brain_mask')
    wf.connect(node, out, process_wm, 'inputspec.brain_mask')

    node, out = strat_pool.get_data(xfm)
    wf.connect(node, out, process_csf, 'inputspec.template_to_T1_xfm')
    wf.connect(node, out, process_gm, 'inputspec.template_to_T1_xfm')
    wf.connect(node, out, process_wm, 'inputspec.template_to_T1_xfm')

    wf.connect(segment, ('tissue_class_files', pick_wm_class_0),
               process_csf, 'inputspec.tissue_class_file')
    wf.connect(segment, ('probability_maps', pick_wm_prob_0),
               process_csf, 'inputspec.probability_tissue_map')

    wf.connect(segment, ('tissue_class_files', pick_wm_class_1),
               process_gm, 'inputspec.tissue_class_file')
    wf.connect(segment, ('probability_maps', pick_wm_prob_1),
               process_gm, 'inputspec.probability_tissue_map')

    wf.connect(segment, ('tissue_class_files', pick_wm_class_2),
               process_wm, 'inputspec.tissue_class_file')
    wf.connect(segment, ('probability_maps', pick_wm_prob_2),
               process_wm, 'inputspec.probability_tissue_map')

    get_csf = pe.Node(util.Function(input_names=['probability_maps'],
                                    output_names=['filename'],
                                    function=pick_wm_prob_0),
                      name=f'get_csf_{pipe_num}')

    wf.connect(segment, 'probability_maps', get_csf, 'probability_maps')

    outputs = {
        f'{long}label-CSF_probseg': (get_csf, 'filename'),
        f'{long}label-GM_probseg':
            (segment, ('probability_maps', pick_wm_prob_1)),
        f'{long}label-WM_probseg':
            (segment, ('probability_maps', pick_wm_prob_2)),
        f'{long}label-CSF_mask':
            (segment, ('tissue_class_files', pick_wm_class_0)),
        f'{long}label-GM_mask':
            (segment, ('tissue_class_files', pick_wm_class_1)),
        f'{long}label-WM_mask':
            (segment, ('tissue_class_files', pick_wm_class_2)),
        f'{long}label-CSF_desc-preproc_mask':
            (process_csf, 'outputspec.segment_mask'),
        f'{long}label-GM_desc-preproc_mask':
            (process_gm, 'outputspec.segment_mask'),
        f'{long}label-WM_desc-preproc_mask':
            (process_wm, 'outputspec.segment_mask')
    }

    return (wf, outputs)
Esempio n. 4
0
def warp_timeseries_to_sym_template(wf, cfg, strat_pool, pipe_num, opt=None):
    '''
    Node Block:
    {"name": "transform_timeseries_to_sym_template",
     "config": ["voxel_mirrored_homotopic_connectivity"],
     "switch": ["run"],
     "option_key": "None",
     "option_val": "None",
     "inputs": [["desc-cleaned-sm_bold",
                 "desc-brain-sm_bold",
                 "desc-preproc-sm_bold",
                 "desc-sm_bold"],
                "from-bold_to-symtemplate_mode-image_xfm",
                "T1w_brain_template_symmetric"],
     "outputs": ["space-symtemplate_desc-sm_bold"]}
    '''

    xfm_prov = strat_pool.get_cpac_provenance(
        'from-bold_to-symtemplate_mode-image_xfm')
    reg_tool = check_prov_for_regtool(xfm_prov)

    num_cpus = cfg.pipeline_setup['system_config']['max_cores_per_participant']

    num_ants_cores = cfg.pipeline_setup['system_config']['num_ants_threads']

    apply_xfm = apply_transform(f'warp_ts_to_sym_template_{pipe_num}',
                                reg_tool,
                                time_series=True,
                                num_cpus=num_cpus,
                                num_ants_cores=num_ants_cores,
                                mem_gb=5.0)

    if reg_tool == 'ants':
        apply_xfm.inputs.inputspec.interpolation = cfg.registration_workflows[
            'functional_registration']['func_registration_to_template'][
                'ANTs_pipelines']['interpolation']
    elif reg_tool == 'fsl':
        apply_xfm.inputs.inputspec.interpolation = cfg.registration_workflows[
            'functional_registration']['func_registration_to_template'][
                'FNIRT_pipelines']['interpolation']

    # smoothed BOLD
    connect, resource = strat_pool.get_data([
        "desc-cleaned-sm_bold", "desc-brain-sm_bold", "desc-preproc-sm_bold",
        "desc-sm_bold"
    ],
                                            report_fetched=True)
    node, out = connect
    wf.connect(node, out, apply_xfm, 'inputspec.input_image')

    node, out = strat_pool.get_data("T1w_brain_template_symmetric")
    wf.connect(node, out, apply_xfm, 'inputspec.reference')

    node, out = strat_pool.get_data("from-bold_to-symtemplate_mode-image_xfm")
    wf.connect(node, out, apply_xfm, 'inputspec.transform')

    outputs = {
        f'space-symtemplate_{resource}': (apply_xfm, 'outputspec.output_image')
    }

    return (wf, outputs)