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

import typing
import pathlib
from styxdefs import *

CIFTI_LABEL_PROBABILITY_METADATA = Metadata(
    id="0435d93a94c261bb607b4770626109d9ebab1571.workbench",
    name="cifti-label-probability",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_CiftiLabelProbabilityParamsDictNoTag = typing.TypedDict('_CiftiLabelProbabilityParamsDictNoTag', {
    "label-maps": InputPathType,
    "probability-dscalar-out": str,
    "exclude-unlabeled": bool,
})
CiftiLabelProbabilityParamsDictTagged = typing.TypedDict('CiftiLabelProbabilityParamsDictTagged', {
    "@type": typing.Literal["workbench/cifti-label-probability"],
    "label-maps": InputPathType,
    "probability-dscalar-out": str,
    "exclude-unlabeled": bool,
})
CiftiLabelProbabilityParamsDict = _CiftiLabelProbabilityParamsDictNoTag | CiftiLabelProbabilityParamsDictTagged


class CiftiLabelProbabilityOutputs(typing.NamedTuple):
    """
    Output object returned when calling `CiftiLabelProbabilityParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    probability_dscalar_out: OutputPathType
    """the relative frequencies of each label at each vertex/voxel"""


def cifti_label_probability_params(
    label_maps: InputPathType,
    probability_dscalar_out: str,
    exclude_unlabeled: bool = False,
) -> CiftiLabelProbabilityParamsDictTagged:
    """
    Build parameters.
    
    Args:
        label_maps: cifti dlabel file containing individual label maps from\
            many subjects.
        probability_dscalar_out: the relative frequencies of each label at each\
            vertex/voxel.
        exclude_unlabeled: don't make a probability map of the unlabeled key.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-label-probability",
        "label-maps": label_maps,
        "probability-dscalar-out": probability_dscalar_out,
        "exclude-unlabeled": exclude_unlabeled,
    }
    return params


def cifti_label_probability_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiLabelProbabilityParamsDict` 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("label-maps", None) is None:
        raise StyxValidationError("`label-maps` must not be None")
    if not isinstance(params["label-maps"], (pathlib.Path, str)):
        raise StyxValidationError(f'`label-maps` has the wrong type: Received `{type(params.get("label-maps", None))}` expected `InputPathType`')
    if params.get("probability-dscalar-out", None) is None:
        raise StyxValidationError("`probability-dscalar-out` must not be None")
    if not isinstance(params["probability-dscalar-out"], str):
        raise StyxValidationError(f'`probability-dscalar-out` has the wrong type: Received `{type(params.get("probability-dscalar-out", None))}` expected `str`')
    if params.get("exclude-unlabeled", False) is None:
        raise StyxValidationError("`exclude-unlabeled` must not be None")
    if not isinstance(params["exclude-unlabeled"], bool):
        raise StyxValidationError(f'`exclude-unlabeled` has the wrong type: Received `{type(params.get("exclude-unlabeled", False))}` expected `bool`')


def cifti_label_probability_cargs(
    params: CiftiLabelProbabilityParamsDict,
    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-label-probability"
    ])
    cargs.append(execution.input_file(params.get("label-maps", None)))
    cargs.append(params.get("probability-dscalar-out", None))
    if params.get("exclude-unlabeled", False):
        cargs.append("-exclude-unlabeled")
    return cargs


def cifti_label_probability_outputs(
    params: CiftiLabelProbabilityParamsDict,
    execution: Execution,
) -> CiftiLabelProbabilityOutputs:
    """
    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 = CiftiLabelProbabilityOutputs(
        root=execution.output_file("."),
        probability_dscalar_out=execution.output_file(params.get("probability-dscalar-out", None)),
    )
    return ret


def cifti_label_probability_execute(
    params: CiftiLabelProbabilityParamsDict,
    runner: Runner | None = None,
) -> CiftiLabelProbabilityOutputs:
    """
    FIND FREQUENCY OF CIFTI LABELS.
    
    This command outputs a set of soft ROIs, one for each label in the input,
    where the value is how many of the input maps had that label at that
    vertex/voxel, divided by the number of input maps.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiLabelProbabilityOutputs`).
    """
    cifti_label_probability_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_LABEL_PROBABILITY_METADATA)
    params = execution.params(params)
    cargs = cifti_label_probability_cargs(params, execution)
    ret = cifti_label_probability_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_label_probability(
    label_maps: InputPathType,
    probability_dscalar_out: str,
    exclude_unlabeled: bool = False,
    runner: Runner | None = None,
) -> CiftiLabelProbabilityOutputs:
    """
    FIND FREQUENCY OF CIFTI LABELS.
    
    This command outputs a set of soft ROIs, one for each label in the input,
    where the value is how many of the input maps had that label at that
    vertex/voxel, divided by the number of input maps.
    
    Args:
        label_maps: cifti dlabel file containing individual label maps from\
            many subjects.
        probability_dscalar_out: the relative frequencies of each label at each\
            vertex/voxel.
        exclude_unlabeled: don't make a probability map of the unlabeled key.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiLabelProbabilityOutputs`).
    """
    params = cifti_label_probability_params(
        label_maps=label_maps,
        probability_dscalar_out=probability_dscalar_out,
        exclude_unlabeled=exclude_unlabeled,
    )
    return cifti_label_probability_execute(params, runner)


__all__ = [
    "CIFTI_LABEL_PROBABILITY_METADATA",
    "CiftiLabelProbabilityOutputs",
    "CiftiLabelProbabilityParamsDict",
    "CiftiLabelProbabilityParamsDictTagged",
    "cifti_label_probability",
    "cifti_label_probability_execute",
    "cifti_label_probability_params",
]
