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

import typing
import pathlib
from styxdefs import *

CIFTI_PAIRWISE_CORRELATION_METADATA = Metadata(
    id="ad1c3d662547315bfc0576b17cb38a01d7cddf48.workbench",
    name="cifti-pairwise-correlation",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_CiftiPairwiseCorrelationParamsDictNoTag = typing.TypedDict('_CiftiPairwiseCorrelationParamsDictNoTag', {
    "cifti-a": InputPathType,
    "cifti-b": InputPathType,
    "cifti-out": str,
    "override-mapping-check": bool,
    "fisher-z": bool,
})
CiftiPairwiseCorrelationParamsDictTagged = typing.TypedDict('CiftiPairwiseCorrelationParamsDictTagged', {
    "@type": typing.Literal["workbench/cifti-pairwise-correlation"],
    "cifti-a": InputPathType,
    "cifti-b": InputPathType,
    "cifti-out": str,
    "override-mapping-check": bool,
    "fisher-z": bool,
})
CiftiPairwiseCorrelationParamsDict = _CiftiPairwiseCorrelationParamsDictNoTag | CiftiPairwiseCorrelationParamsDictTagged


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


def cifti_pairwise_correlation_params(
    cifti_a: InputPathType,
    cifti_b: InputPathType,
    cifti_out: str,
    override_mapping_check: bool = False,
    fisher_z: bool = False,
) -> CiftiPairwiseCorrelationParamsDictTagged:
    """
    Build parameters.
    
    Args:
        cifti_a: first input cifti file.
        cifti_b: second input cifti file.
        cifti_out: output cifti file.
        override_mapping_check: don't check the mappings for compatibility,\
            only check length.
        fisher_z: apply fisher small z transform (ie, artanh) to correlation.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-pairwise-correlation",
        "cifti-a": cifti_a,
        "cifti-b": cifti_b,
        "cifti-out": cifti_out,
        "override-mapping-check": override_mapping_check,
        "fisher-z": fisher_z,
    }
    return params


def cifti_pairwise_correlation_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiPairwiseCorrelationParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("cifti-a", None) is None:
        raise StyxValidationError("`cifti-a` must not be None")
    if not isinstance(params["cifti-a"], (pathlib.Path, str)):
        raise StyxValidationError(f'`cifti-a` has the wrong type: Received `{type(params.get("cifti-a", None))}` expected `InputPathType`')
    if params.get("cifti-b", None) is None:
        raise StyxValidationError("`cifti-b` must not be None")
    if not isinstance(params["cifti-b"], (pathlib.Path, str)):
        raise StyxValidationError(f'`cifti-b` has the wrong type: Received `{type(params.get("cifti-b", None))}` expected `InputPathType`')
    if params.get("cifti-out", None) is None:
        raise StyxValidationError("`cifti-out` must not be None")
    if not isinstance(params["cifti-out"], str):
        raise StyxValidationError(f'`cifti-out` has the wrong type: Received `{type(params.get("cifti-out", None))}` expected `str`')
    if params.get("override-mapping-check", False) is None:
        raise StyxValidationError("`override-mapping-check` must not be None")
    if not isinstance(params["override-mapping-check"], bool):
        raise StyxValidationError(f'`override-mapping-check` has the wrong type: Received `{type(params.get("override-mapping-check", False))}` expected `bool`')
    if params.get("fisher-z", False) is None:
        raise StyxValidationError("`fisher-z` must not be None")
    if not isinstance(params["fisher-z"], bool):
        raise StyxValidationError(f'`fisher-z` has the wrong type: Received `{type(params.get("fisher-z", False))}` expected `bool`')


def cifti_pairwise_correlation_cargs(
    params: CiftiPairwiseCorrelationParamsDict,
    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.extend([
        "wb_command",
        "-cifti-pairwise-correlation"
    ])
    cargs.append(execution.input_file(params.get("cifti-a", None)))
    cargs.append(execution.input_file(params.get("cifti-b", None)))
    cargs.append(params.get("cifti-out", None))
    if params.get("override-mapping-check", False):
        cargs.append("-override-mapping-check")
    if params.get("fisher-z", False):
        cargs.append("-fisher-z")
    return cargs


def cifti_pairwise_correlation_outputs(
    params: CiftiPairwiseCorrelationParamsDict,
    execution: Execution,
) -> CiftiPairwiseCorrelationOutputs:
    """
    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 = CiftiPairwiseCorrelationOutputs(
        root=execution.output_file("."),
        cifti_out=execution.output_file(params.get("cifti-out", None)),
    )
    return ret


def cifti_pairwise_correlation_execute(
    params: CiftiPairwiseCorrelationParamsDict,
    runner: Runner | None = None,
) -> CiftiPairwiseCorrelationOutputs:
    """
    CORRELATE PAIRED ROWS BETWEEN TWO CIFTI FILES.
    
    For each row in <cifti-a>, correlate it with the same row in <cifti-b>, and
    put the result in the same row of <cifti-out>, which has only one column.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiPairwiseCorrelationOutputs`).
    """
    cifti_pairwise_correlation_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_PAIRWISE_CORRELATION_METADATA)
    params = execution.params(params)
    cargs = cifti_pairwise_correlation_cargs(params, execution)
    ret = cifti_pairwise_correlation_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_pairwise_correlation(
    cifti_a: InputPathType,
    cifti_b: InputPathType,
    cifti_out: str,
    override_mapping_check: bool = False,
    fisher_z: bool = False,
    runner: Runner | None = None,
) -> CiftiPairwiseCorrelationOutputs:
    """
    CORRELATE PAIRED ROWS BETWEEN TWO CIFTI FILES.
    
    For each row in <cifti-a>, correlate it with the same row in <cifti-b>, and
    put the result in the same row of <cifti-out>, which has only one column.
    
    Args:
        cifti_a: first input cifti file.
        cifti_b: second input cifti file.
        cifti_out: output cifti file.
        override_mapping_check: don't check the mappings for compatibility,\
            only check length.
        fisher_z: apply fisher small z transform (ie, artanh) to correlation.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiPairwiseCorrelationOutputs`).
    """
    params = cifti_pairwise_correlation_params(
        cifti_a=cifti_a,
        cifti_b=cifti_b,
        cifti_out=cifti_out,
        override_mapping_check=override_mapping_check,
        fisher_z=fisher_z,
    )
    return cifti_pairwise_correlation_execute(params, runner)


__all__ = [
    "CIFTI_PAIRWISE_CORRELATION_METADATA",
    "CiftiPairwiseCorrelationOutputs",
    "CiftiPairwiseCorrelationParamsDict",
    "CiftiPairwiseCorrelationParamsDictTagged",
    "cifti_pairwise_correlation",
    "cifti_pairwise_correlation_execute",
    "cifti_pairwise_correlation_params",
]
