def qap_functional_spatial_workflow(workflow, resource_pool, config):

    # resource pool should have:
    #     mean_functional
    #     functional_brain_mask

    import os
    import sys

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

    import nipype.algorithms.misc as nam
    import nipype.interfaces.utility as niu
    import nipype.algorithms.misc as nam

    from qap_workflows_utils import qap_functional_spatial
    from qap.viz.interfaces import PlotMosaic

    from workflow_utils import check_input_resources

    if "mean_functional" not in resource_pool.keys():
        from functional_preproc import mean_functional_workflow

        workflow, resource_pool = mean_functional_workflow(workflow, resource_pool, config)

    if "functional_brain_mask" not in resource_pool.keys():
        from functional_preproc import functional_brain_mask_workflow

        workflow, resource_pool = functional_brain_mask_workflow(workflow, resource_pool, config)

    spatial_epi = pe.Node(
        niu.Function(
            input_names=[
                "mean_epi",
                "func_brain_mask",
                "direction",
                "subject_id",
                "session_id",
                "scan_id",
                "site_name",
            ],
            output_names=["qc"],
            function=qap_functional_spatial,
        ),
        name="qap_functional_spatial",
    )

    # Subject infos
    if "ghost_direction" not in config.keys():
        config["ghost_direction"] = "y"

    spatial_epi.inputs.direction = config["ghost_direction"]
    spatial_epi.inputs.subject_id = config["subject_id"]
    spatial_epi.inputs.session_id = config["session_id"]
    spatial_epi.inputs.scan_id = config["scan_id"]

    if "site_name" in config.keys():
        spatial_epi.inputs.site_name = config["site_name"]

    if len(resource_pool["mean_functional"]) == 2:
        node, out_file = resource_pool["mean_functional"]
        workflow.connect(node, out_file, spatial_epi, "mean_epi")
    else:
        spatial_epi.inputs.mean_epi = resource_pool["mean_functional"]

    if len(resource_pool["functional_brain_mask"]) == 2:
        node, out_file = resource_pool["functional_brain_mask"]
        workflow.connect(node, out_file, spatial_epi, "func_brain_mask")
    else:
        spatial_epi.inputs.func_brain_mask = resource_pool["functional_brain_mask"]

    if config.get("write_report", False):
        plot = pe.Node(PlotMosaic(), name="plot_mosaic")
        plot.inputs.subject = config["subject_id"]

        metadata = [config["session_id"], config["scan_id"]]
        if "site_name" in config.keys():
            metadata.append(config["site_name"])

        plot.inputs.metadata = metadata
        plot.inputs.title = "Mean EPI"

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

        # Enable this if we want masks
        # if len(resource_pool['functional_brain_mask']) == 2:
        #     node, out_file = resource_pool['functional_brain_mask']
        #     workflow.connect(node, out_file, plot, 'in_mask')
        # else:
        #     plot.inputs.in_mask = resource_pool['functional_brain_mask']
        resource_pool["qap_mosaic"] = (plot, "out_file")

    out_csv = op.join(config["output_directory"], "qap_functional_spatial.csv")
    spatial_epi_to_csv = pe.Node(nam.AddCSVRow(in_file=out_csv), name="qap_functional_spatial_to_csv")
    workflow.connect(spatial_epi, "qc", spatial_epi_to_csv, "_outputs")
    resource_pool["qap_functional_spatial"] = (spatial_epi_to_csv, "csv_file")

    return workflow, resource_pool
def qap_functional_spatial_workflow(workflow, resource_pool, config):

    # resource pool should have:
    #     mean_functional
    #     functional_brain_mask

    import os
    import sys

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

    import nipype.interfaces.utility as util

    from qap_workflows_utils import qap_functional_spatial, write_to_csv

    from workflow_utils import check_input_resources

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

        from functional_preproc import mean_functional_workflow

        workflow, resource_pool = mean_functional_workflow(workflow, resource_pool, config)

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

        from functional_preproc import functional_brain_mask_workflow

        workflow, resource_pool = functional_brain_mask_workflow(workflow, resource_pool, config)

    spatial_epi = pe.Node(
        util.Function(
            input_names=[
                "mean_epi",
                "func_brain_mask",
                "direction",
                "subject_id",
                "session_id",
                "scan_id",
                "site_name",
            ],
            output_names=["qc"],
            function=qap_functional_spatial,
        ),
        name="qap_functional_spatial",
    )

    spatial_epi_to_csv = pe.Node(
        util.Function(input_names=["sub_qap_dict"], output_names=["outfile"], function=write_to_csv),
        name="qap_functional_spatial_to_csv",
    )

    if len(resource_pool["mean_functional"]) == 2:
        node, out_file = resource_pool["mean_functional"]
        workflow.connect(node, out_file, spatial_epi, "mean_epi")
    else:
        spatial_epi.inputs.mean_epi = resource_pool["mean_functional"]

    if len(resource_pool["functional_brain_mask"]) == 2:
        node, out_file = resource_pool["functional_brain_mask"]
        workflow.connect(node, out_file, spatial_epi, "func_brain_mask")
    else:
        spatial_epi.inputs.func_brain_mask = resource_pool["functional_brain_mask"]

    # Subject infos
    if "ghost_direction" not in config.keys():
        config["ghost_direction"] = "y"

    spatial_epi.inputs.direction = config["ghost_direction"]

    spatial_epi.inputs.subject_id = config["subject_id"]
    spatial_epi.inputs.session_id = config["session_id"]
    spatial_epi.inputs.scan_id = config["scan_id"]

    if "site_name" in config.keys():
        spatial_epi.inputs.site_name = config["site_name"]

    workflow.connect(spatial_epi, "qc", spatial_epi_to_csv, "sub_qap_dict")

    resource_pool["qap_functional_spatial"] = (spatial_epi_to_csv, "outfile")

    return workflow, resource_pool
Пример #3
0
def qap_functional_spatial_workflow(workflow, resource_pool, config):

    # resource pool should have:
    #     mean_functional
    #     functional_brain_mask

    import os
    import sys

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

    import nipype.algorithms.misc as nam
    import nipype.interfaces.utility as niu
    import nipype.algorithms.misc as nam

    from qap_workflows_utils import qap_functional_spatial
    from qap.viz.interfaces import PlotMosaic

    from workflow_utils import check_input_resources

    if 'mean_functional' not in resource_pool.keys():
        from functional_preproc import mean_functional_workflow
        workflow, resource_pool = \
            mean_functional_workflow(workflow, resource_pool, config)

    if 'functional_brain_mask' not in resource_pool.keys():
        from functional_preproc import functional_brain_mask_workflow
        workflow, resource_pool = \
            functional_brain_mask_workflow(workflow, resource_pool, config)

    spatial_epi = pe.Node(niu.Function(input_names=[
        'mean_epi', 'func_brain_mask', 'direction', 'subject_id', 'session_id',
        'scan_id', 'site_name'
    ],
                                       output_names=['qc'],
                                       function=qap_functional_spatial),
                          name='qap_functional_spatial')

    # Subject infos
    if 'ghost_direction' not in config.keys():
        config['ghost_direction'] = 'y'

    spatial_epi.inputs.direction = config['ghost_direction']
    spatial_epi.inputs.subject_id = config['subject_id']
    spatial_epi.inputs.session_id = config['session_id']
    spatial_epi.inputs.scan_id = config['scan_id']

    if 'site_name' in config.keys():
        spatial_epi.inputs.site_name = config['site_name']

    if len(resource_pool['mean_functional']) == 2:
        node, out_file = resource_pool['mean_functional']
        workflow.connect(node, out_file, spatial_epi, 'mean_epi')
    else:
        spatial_epi.inputs.mean_epi = resource_pool['mean_functional']

    if len(resource_pool['functional_brain_mask']) == 2:
        node, out_file = resource_pool['functional_brain_mask']
        workflow.connect(node, out_file, spatial_epi, 'func_brain_mask')
    else:
        spatial_epi.inputs.func_brain_mask = \
            resource_pool['functional_brain_mask']

    if config.get('write_report', False):
        plot = pe.Node(PlotMosaic(), name='plot_mosaic')
        plot.inputs.subject = config['subject_id']

        metadata = [config['session_id'], config['scan_id']]
        if 'site_name' in config.keys():
            metadata.append(config['site_name'])

        plot.inputs.metadata = metadata
        plot.inputs.title = 'Mean EPI'

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

        # Enable this if we want masks
        # if len(resource_pool['functional_brain_mask']) == 2:
        #     node, out_file = resource_pool['functional_brain_mask']
        #     workflow.connect(node, out_file, plot, 'in_mask')
        # else:
        #     plot.inputs.in_mask = resource_pool['functional_brain_mask']
        resource_pool['qap_mosaic'] = (plot, 'out_file')

    out_csv = op.join(config['output_directory'], 'qap_functional_spatial.csv')
    spatial_epi_to_csv = pe.Node(nam.AddCSVRow(in_file=out_csv),
                                 name='qap_functional_spatial_to_csv')
    workflow.connect(spatial_epi, 'qc', spatial_epi_to_csv, '_outputs')
    resource_pool['qap_functional_spatial'] = (spatial_epi_to_csv, 'csv_file')

    return workflow, resource_pool