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

import typing
import pathlib
from styxdefs import *

LABEL_PROBABILITY_METADATA = Metadata(
    id="17883125fa07b84610948fe71508e3f8bf4671e0.boutiques",
    name="label-probability",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


LabelProbabilityParameters = typing.TypedDict('LabelProbabilityParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/label-probability"]],
    "label_maps": InputPathType,
    "probability_metric_out": str,
    "opt_exclude_unlabeled": bool,
})
LabelProbabilityParametersTagged = typing.TypedDict('LabelProbabilityParametersTagged', {
    "@type": typing.Literal["workbench/label-probability"],
    "label_maps": InputPathType,
    "probability_metric_out": str,
    "opt_exclude_unlabeled": bool,
})


class LabelProbabilityOutputs(typing.NamedTuple):
    """
    Output object returned when calling `LabelProbabilityParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    probability_metric_out: OutputPathType
    """the relative frequencies of each label at each vertex"""


def label_probability_params(
    label_maps: InputPathType,
    probability_metric_out: str,
    opt_exclude_unlabeled: bool = False,
) -> LabelProbabilityParametersTagged:
    """
    Build parameters.
    
    Args:
        label_maps: label file containing individual label maps from many\
            subjects.
        probability_metric_out: the relative frequencies of each label at each\
            vertex.
        opt_exclude_unlabeled: don't make a probability map of the unlabeled\
            key.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/label-probability",
        "label_maps": label_maps,
        "probability_metric_out": probability_metric_out,
        "opt_exclude_unlabeled": opt_exclude_unlabeled,
    }
    return params


def label_probability_cargs(
    params: LabelProbabilityParameters,
    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("-label-probability")
    cargs.append(execution.input_file(params.get("label_maps", None)))
    cargs.append(params.get("probability_metric_out", None))
    if params.get("opt_exclude_unlabeled", False):
        cargs.append("-exclude-unlabeled")
    return cargs


def label_probability_outputs(
    params: LabelProbabilityParameters,
    execution: Execution,
) -> LabelProbabilityOutputs:
    """
    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 = LabelProbabilityOutputs(
        root=execution.output_file("."),
        probability_metric_out=execution.output_file(params.get("probability_metric_out", None)),
    )
    return ret


def label_probability_execute(
    params: LabelProbabilityParameters,
    runner: Runner | None = None,
) -> LabelProbabilityOutputs:
    """
    label-probability
    
    Find frequency of surface 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,
    divided by the number of input maps.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `LabelProbabilityOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(LABEL_PROBABILITY_METADATA)
    params = execution.params(params)
    cargs = label_probability_cargs(params, execution)
    ret = label_probability_outputs(params, execution)
    execution.run(cargs)
    return ret


def label_probability(
    label_maps: InputPathType,
    probability_metric_out: str,
    opt_exclude_unlabeled: bool = False,
    runner: Runner | None = None,
) -> LabelProbabilityOutputs:
    """
    label-probability
    
    Find frequency of surface 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,
    divided by the number of input maps.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        label_maps: label file containing individual label maps from many\
            subjects.
        probability_metric_out: the relative frequencies of each label at each\
            vertex.
        opt_exclude_unlabeled: don't make a probability map of the unlabeled\
            key.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `LabelProbabilityOutputs`).
    """
    params = label_probability_params(
        label_maps=label_maps,
        probability_metric_out=probability_metric_out,
        opt_exclude_unlabeled=opt_exclude_unlabeled,
    )
    return label_probability_execute(params, runner)


__all__ = [
    "LABEL_PROBABILITY_METADATA",
    "LabelProbabilityOutputs",
    "label_probability",
    "label_probability_execute",
    "label_probability_params",
]
