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

import typing
import pathlib
from styxdefs import *
import dataclasses

DSETSTAT2P_METADATA = Metadata(
    id="ed9eb51fe358c9554d3224bb89356e67ecbcfa05.boutiques",
    name="dsetstat2p",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class Dsetstat2pOutputs(typing.NamedTuple):
    """
    Output object returned when calling `dsetstat2p(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_file: OutputPathType
    """Output p-value or stat value"""


def dsetstat2p(
    dataset: str,
    statval: float,
    one_sided: bool = False,
    quiet: bool = False,
    runner: Runner | None = None,
) -> Dsetstat2pOutputs:
    """
    Converts a statistic to a p-value with reference to a particular dataset.
    
    Author: AFNI Team
    
    URL: https://afni.nimh.nih.gov/pub/dist/doc/program_help/dsetstat2p.html
    
    Args:
        dataset: Specify a dataset DDD and, if it has multiple sub-bricks, the\
            [i]th subbrick with the statistic of interest MUST be selected\
            explicitly; note the use of quotation marks around the brick selector\
            (because of the square-brackets). Note that 'i' can be either a number\
            of a string label selector.
        statval: Input stat-value S, which MUST be in the interval [0,\
            infinity).
        one_sided: Choose one-sided or bi-sided/two-sided testing.
        quiet: An optional flag so that output ONLY the final statistic value\
            output to standard output; this can be then be viewed, redirected to a\
            text file or saved as a shell variable. (Default: display supplementary\
            text.).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `Dsetstat2pOutputs`).
    """
    if not (0 <= statval): 
        raise ValueError(f"'statval' must be greater than 0 <= x but was {statval}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(DSETSTAT2P_METADATA)
    cargs = []
    cargs.append("dsetstat2p")
    cargs.append(dataset)
    cargs.append(str(statval))
    if one_sided:
        cargs.append("-1sided")
    if quiet:
        cargs.append("-quiet")
    ret = Dsetstat2pOutputs(
        root=execution.output_file("."),
        output_file=execution.output_file("output.txt"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "DSETSTAT2P_METADATA",
    "Dsetstat2pOutputs",
    "dsetstat2p",
]
