# This file was auto generated by Styx.
# Do not edit this file directly.

import typing
import pathlib
from styxdefs import *

CIFTI_AVERAGE_ROI_CORRELATION_METADATA = Metadata(
    id="539e96c2fb64bff82d21688d1bec36d954413c34.boutiques",
    name="cifti-average-roi-correlation",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


CiftiAverageRoiCorrelationCiftiRoiParameters = typing.TypedDict('CiftiAverageRoiCorrelationCiftiRoiParameters', {
    "@type": typing.NotRequired[typing.Literal["cifti_roi"]],
    "roi_cifti": InputPathType,
    "opt_in_memory": bool,
})
CiftiAverageRoiCorrelationCiftiRoiParametersTagged = typing.TypedDict('CiftiAverageRoiCorrelationCiftiRoiParametersTagged', {
    "@type": typing.Literal["cifti_roi"],
    "roi_cifti": InputPathType,
    "opt_in_memory": bool,
})


CiftiAverageRoiCorrelationCiftiParameters = typing.TypedDict('CiftiAverageRoiCorrelationCiftiParameters', {
    "@type": typing.NotRequired[typing.Literal["cifti"]],
    "cifti_in": InputPathType,
})
CiftiAverageRoiCorrelationCiftiParametersTagged = typing.TypedDict('CiftiAverageRoiCorrelationCiftiParametersTagged', {
    "@type": typing.Literal["cifti"],
    "cifti_in": InputPathType,
})


CiftiAverageRoiCorrelationParameters = typing.TypedDict('CiftiAverageRoiCorrelationParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/cifti-average-roi-correlation"]],
    "cifti_out": str,
    "cifti_roi": typing.NotRequired[CiftiAverageRoiCorrelationCiftiRoiParameters | None],
    "opt_left_roi_roi_metric": typing.NotRequired[InputPathType | None],
    "opt_right_roi_roi_metric": typing.NotRequired[InputPathType | None],
    "opt_cerebellum_roi_roi_metric": typing.NotRequired[InputPathType | None],
    "opt_vol_roi_roi_vol": typing.NotRequired[InputPathType | None],
    "opt_left_area_surf_left_surf": typing.NotRequired[InputPathType | None],
    "opt_right_area_surf_right_surf": typing.NotRequired[InputPathType | None],
    "opt_cerebellum_area_surf_cerebellum_surf": typing.NotRequired[InputPathType | None],
    "cifti": typing.NotRequired[list[CiftiAverageRoiCorrelationCiftiParameters] | None],
})
CiftiAverageRoiCorrelationParametersTagged = typing.TypedDict('CiftiAverageRoiCorrelationParametersTagged', {
    "@type": typing.Literal["workbench/cifti-average-roi-correlation"],
    "cifti_out": str,
    "cifti_roi": typing.NotRequired[CiftiAverageRoiCorrelationCiftiRoiParameters | None],
    "opt_left_roi_roi_metric": typing.NotRequired[InputPathType | None],
    "opt_right_roi_roi_metric": typing.NotRequired[InputPathType | None],
    "opt_cerebellum_roi_roi_metric": typing.NotRequired[InputPathType | None],
    "opt_vol_roi_roi_vol": typing.NotRequired[InputPathType | None],
    "opt_left_area_surf_left_surf": typing.NotRequired[InputPathType | None],
    "opt_right_area_surf_right_surf": typing.NotRequired[InputPathType | None],
    "opt_cerebellum_area_surf_cerebellum_surf": typing.NotRequired[InputPathType | None],
    "cifti": typing.NotRequired[list[CiftiAverageRoiCorrelationCiftiParameters] | None],
})


def cifti_average_roi_correlation_cifti_roi_params(
    roi_cifti: InputPathType,
    opt_in_memory: bool = False,
) -> CiftiAverageRoiCorrelationCiftiRoiParametersTagged:
    """
    Build parameters.
    
    Args:
        roi_cifti: the roi cifti file.
        opt_in_memory: cache the roi in memory so that it isn't re-read for\
            each input cifti.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "cifti_roi",
        "roi_cifti": roi_cifti,
        "opt_in_memory": opt_in_memory,
    }
    return params


def cifti_average_roi_correlation_cifti_roi_cargs(
    params: CiftiAverageRoiCorrelationCiftiRoiParameters,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("-cifti-roi")
    cargs.append(execution.input_file(params.get("roi_cifti", None)))
    if params.get("opt_in_memory", False):
        cargs.append("-in-memory")
    return cargs


def cifti_average_roi_correlation_cifti_params(
    cifti_in: InputPathType,
) -> CiftiAverageRoiCorrelationCiftiParametersTagged:
    """
    Build parameters.
    
    Args:
        cifti_in: a cifti file to average across.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "cifti",
        "cifti_in": cifti_in,
    }
    return params


def cifti_average_roi_correlation_cifti_cargs(
    params: CiftiAverageRoiCorrelationCiftiParameters,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("-cifti")
    cargs.append(execution.input_file(params.get("cifti_in", None)))
    return cargs


class CiftiAverageRoiCorrelationOutputs(typing.NamedTuple):
    """
    Output object returned when calling `CiftiAverageRoiCorrelationParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    cifti_out: OutputPathType
    """output cifti file"""


def cifti_average_roi_correlation_params(
    cifti_out: str,
    cifti_roi: CiftiAverageRoiCorrelationCiftiRoiParameters | None = None,
    opt_left_roi_roi_metric: InputPathType | None = None,
    opt_right_roi_roi_metric: InputPathType | None = None,
    opt_cerebellum_roi_roi_metric: InputPathType | None = None,
    opt_vol_roi_roi_vol: InputPathType | None = None,
    opt_left_area_surf_left_surf: InputPathType | None = None,
    opt_right_area_surf_right_surf: InputPathType | None = None,
    opt_cerebellum_area_surf_cerebellum_surf: InputPathType | None = None,
    cifti: list[CiftiAverageRoiCorrelationCiftiParameters] | None = None,
) -> CiftiAverageRoiCorrelationParametersTagged:
    """
    Build parameters.
    
    Args:
        cifti_out: output cifti file.
        cifti_roi: cifti file containing combined weights.
        opt_left_roi_roi_metric: weights to use for left hempsphere: the left\
            roi as a metric file.
        opt_right_roi_roi_metric: weights to use for right hempsphere: the\
            right roi as a metric file.
        opt_cerebellum_roi_roi_metric: weights to use for cerebellum surface:\
            the cerebellum roi as a metric file.
        opt_vol_roi_roi_vol: voxel weights to use: the roi volume file.
        opt_left_area_surf_left_surf: specify the left surface for vertex area\
            correction: the left surface file.
        opt_right_area_surf_right_surf: specify the right surface for vertex\
            area correction: the right surface file.
        opt_cerebellum_area_surf_cerebellum_surf: specify the cerebellum\
            surface for vertex area correction: the cerebellum surface file.
        cifti: specify an input cifti file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-average-roi-correlation",
        "cifti_out": cifti_out,
    }
    if cifti_roi is not None:
        params["cifti_roi"] = cifti_roi
    if opt_left_roi_roi_metric is not None:
        params["opt_left_roi_roi_metric"] = opt_left_roi_roi_metric
    if opt_right_roi_roi_metric is not None:
        params["opt_right_roi_roi_metric"] = opt_right_roi_roi_metric
    if opt_cerebellum_roi_roi_metric is not None:
        params["opt_cerebellum_roi_roi_metric"] = opt_cerebellum_roi_roi_metric
    if opt_vol_roi_roi_vol is not None:
        params["opt_vol_roi_roi_vol"] = opt_vol_roi_roi_vol
    if opt_left_area_surf_left_surf is not None:
        params["opt_left_area_surf_left_surf"] = opt_left_area_surf_left_surf
    if opt_right_area_surf_right_surf is not None:
        params["opt_right_area_surf_right_surf"] = opt_right_area_surf_right_surf
    if opt_cerebellum_area_surf_cerebellum_surf is not None:
        params["opt_cerebellum_area_surf_cerebellum_surf"] = opt_cerebellum_area_surf_cerebellum_surf
    if cifti is not None:
        params["cifti"] = cifti
    return params


def cifti_average_roi_correlation_cargs(
    params: CiftiAverageRoiCorrelationParameters,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("wb_command")
    cargs.append("-cifti-average-roi-correlation")
    cargs.append(params.get("cifti_out", None))
    if params.get("cifti_roi", None) is not None:
        cargs.extend(cifti_average_roi_correlation_cifti_roi_cargs(params.get("cifti_roi", None), execution))
    if params.get("opt_left_roi_roi_metric", None) is not None:
        cargs.extend([
            "-left-roi",
            execution.input_file(params.get("opt_left_roi_roi_metric", None))
        ])
    if params.get("opt_right_roi_roi_metric", None) is not None:
        cargs.extend([
            "-right-roi",
            execution.input_file(params.get("opt_right_roi_roi_metric", None))
        ])
    if params.get("opt_cerebellum_roi_roi_metric", None) is not None:
        cargs.extend([
            "-cerebellum-roi",
            execution.input_file(params.get("opt_cerebellum_roi_roi_metric", None))
        ])
    if params.get("opt_vol_roi_roi_vol", None) is not None:
        cargs.extend([
            "-vol-roi",
            execution.input_file(params.get("opt_vol_roi_roi_vol", None))
        ])
    if params.get("opt_left_area_surf_left_surf", None) is not None:
        cargs.extend([
            "-left-area-surf",
            execution.input_file(params.get("opt_left_area_surf_left_surf", None))
        ])
    if params.get("opt_right_area_surf_right_surf", None) is not None:
        cargs.extend([
            "-right-area-surf",
            execution.input_file(params.get("opt_right_area_surf_right_surf", None))
        ])
    if params.get("opt_cerebellum_area_surf_cerebellum_surf", None) is not None:
        cargs.extend([
            "-cerebellum-area-surf",
            execution.input_file(params.get("opt_cerebellum_area_surf_cerebellum_surf", None))
        ])
    if params.get("cifti", None) is not None:
        cargs.extend([a for c in [cifti_average_roi_correlation_cifti_cargs(s, execution) for s in params.get("cifti", None)] for a in c])
    return cargs


def cifti_average_roi_correlation_outputs(
    params: CiftiAverageRoiCorrelationParameters,
    execution: Execution,
) -> CiftiAverageRoiCorrelationOutputs:
    """
    Build outputs object containing output file paths and possibly stdout/stderr.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Outputs object.
    """
    ret = CiftiAverageRoiCorrelationOutputs(
        root=execution.output_file("."),
        cifti_out=execution.output_file(params.get("cifti_out", None)),
    )
    return ret


def cifti_average_roi_correlation_execute(
    params: CiftiAverageRoiCorrelationParameters,
    runner: Runner | None = None,
) -> CiftiAverageRoiCorrelationOutputs:
    """
    cifti-average-roi-correlation
    
    Correlate roi average with all rows then average across subjects.
    
    Averages rows for each map of the ROI(s), takes the correlation of each ROI
    average to the rest of the rows in the same file, applies the fisher small z
    transform, then averages the results across all files. ROIs are always
    treated as weighting functions, including negative values. For efficiency,
    ensure that everything that is not intended to be used is zero in the ROI
    map. If -cifti-roi is specified, -left-roi, -right-roi, -cerebellum-roi, and
    -vol-roi must not be specified. If multiple non-cifti ROI files are
    specified, they must have the same number of columns.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiAverageRoiCorrelationOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_AVERAGE_ROI_CORRELATION_METADATA)
    params = execution.params(params)
    cargs = cifti_average_roi_correlation_cargs(params, execution)
    ret = cifti_average_roi_correlation_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_average_roi_correlation(
    cifti_out: str,
    cifti_roi: CiftiAverageRoiCorrelationCiftiRoiParameters | None = None,
    opt_left_roi_roi_metric: InputPathType | None = None,
    opt_right_roi_roi_metric: InputPathType | None = None,
    opt_cerebellum_roi_roi_metric: InputPathType | None = None,
    opt_vol_roi_roi_vol: InputPathType | None = None,
    opt_left_area_surf_left_surf: InputPathType | None = None,
    opt_right_area_surf_right_surf: InputPathType | None = None,
    opt_cerebellum_area_surf_cerebellum_surf: InputPathType | None = None,
    cifti: list[CiftiAverageRoiCorrelationCiftiParameters] | None = None,
    runner: Runner | None = None,
) -> CiftiAverageRoiCorrelationOutputs:
    """
    cifti-average-roi-correlation
    
    Correlate roi average with all rows then average across subjects.
    
    Averages rows for each map of the ROI(s), takes the correlation of each ROI
    average to the rest of the rows in the same file, applies the fisher small z
    transform, then averages the results across all files. ROIs are always
    treated as weighting functions, including negative values. For efficiency,
    ensure that everything that is not intended to be used is zero in the ROI
    map. If -cifti-roi is specified, -left-roi, -right-roi, -cerebellum-roi, and
    -vol-roi must not be specified. If multiple non-cifti ROI files are
    specified, they must have the same number of columns.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        cifti_out: output cifti file.
        cifti_roi: cifti file containing combined weights.
        opt_left_roi_roi_metric: weights to use for left hempsphere: the left\
            roi as a metric file.
        opt_right_roi_roi_metric: weights to use for right hempsphere: the\
            right roi as a metric file.
        opt_cerebellum_roi_roi_metric: weights to use for cerebellum surface:\
            the cerebellum roi as a metric file.
        opt_vol_roi_roi_vol: voxel weights to use: the roi volume file.
        opt_left_area_surf_left_surf: specify the left surface for vertex area\
            correction: the left surface file.
        opt_right_area_surf_right_surf: specify the right surface for vertex\
            area correction: the right surface file.
        opt_cerebellum_area_surf_cerebellum_surf: specify the cerebellum\
            surface for vertex area correction: the cerebellum surface file.
        cifti: specify an input cifti file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiAverageRoiCorrelationOutputs`).
    """
    params = cifti_average_roi_correlation_params(
        cifti_out=cifti_out,
        cifti_roi=cifti_roi,
        opt_left_roi_roi_metric=opt_left_roi_roi_metric,
        opt_right_roi_roi_metric=opt_right_roi_roi_metric,
        opt_cerebellum_roi_roi_metric=opt_cerebellum_roi_roi_metric,
        opt_vol_roi_roi_vol=opt_vol_roi_roi_vol,
        opt_left_area_surf_left_surf=opt_left_area_surf_left_surf,
        opt_right_area_surf_right_surf=opt_right_area_surf_right_surf,
        opt_cerebellum_area_surf_cerebellum_surf=opt_cerebellum_area_surf_cerebellum_surf,
        cifti=cifti,
    )
    return cifti_average_roi_correlation_execute(params, runner)


__all__ = [
    "CIFTI_AVERAGE_ROI_CORRELATION_METADATA",
    "CiftiAverageRoiCorrelationOutputs",
    "cifti_average_roi_correlation",
    "cifti_average_roi_correlation_cifti_params",
    "cifti_average_roi_correlation_cifti_roi_params",
    "cifti_average_roi_correlation_execute",
    "cifti_average_roi_correlation_params",
]
