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

import typing
import pathlib
from styxdefs import *
import dataclasses

V_3D_ANOVA_METADATA = Metadata(
    id="a6b18c124721654a7ec2ffc70584424d3b14a440.boutiques",
    name="3dANOVA",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class V3dAnovaOutputs(typing.NamedTuple):
    """
    Output object returned when calling `v_3d_anova(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    ftr_output: OutputPathType | None
    """Output F-statistic dataset file"""
    ftr_brick_output: OutputPathType | None
    """Output F-statistic BRIK file"""
    mean_output: OutputPathType | None
    """Output mean dataset file"""
    mean_brick_output: OutputPathType | None
    """Output mean BRIK file"""
    diff_output: OutputPathType | None
    """Output difference dataset file"""
    diff_brick_output: OutputPathType | None
    """Output difference BRIK file"""
    contr_output: OutputPathType | None
    """Output contrast dataset file"""
    contr_brick_output: OutputPathType | None
    """Output contrast BRIK file"""
    bucket_output: OutputPathType | None
    """Output bucket dataset file"""
    bucket_brick_output: OutputPathType | None
    """Output bucket BRIK file"""


def v_3d_anova(
    levels: int,
    datasets: list[str],
    voxel: int | None = None,
    diskspace: bool = False,
    mask: InputPathType | None = None,
    debug: int | None = None,
    ftr: str | None = None,
    mean: str | None = None,
    diff: str | None = None,
    contr: str | None = None,
    old_method: bool = False,
    ok: bool = False,
    assume_sph: bool = False,
    bucket: str | None = None,
    runner: Runner | None = None,
) -> V3dAnovaOutputs:
    """
    Performs single-factor Analysis of Variance (ANOVA) on 3D datasets.
    
    Author: AFNI Developers
    
    URL: https://afni.nimh.nih.gov/
    
    Args:
        levels: Number of factor levels.
        datasets: Datasets for each factor level.
        voxel: Screen output for the specified voxel number.
        diskspace: Print out the required disk space for program execution.
        mask: Use sub-brick #0 of dataset to define which voxels to process.
        debug: Request extra output verbosity.
        ftr: F-statistic for treatment effect.
        mean: Estimate of factor level mean.
        diff: Difference between factor levels.
        contr: Contrast in factor levels.
        old_method: Perform ANOVA using the previous functionality.
        ok: Confirm understanding of t-stats and sphericity assumptions with\
            old method.
        assume_sph: Assume sphericity (zero-sum contrasts only).
        bucket: Create one AFNI 'bucket' dataset.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `V3dAnovaOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(V_3D_ANOVA_METADATA)
    cargs = []
    cargs.append("3dANOVA")
    cargs.extend([
        "-levels",
        str(levels)
    ])
    cargs.extend([
        "-dset",
        *datasets
    ])
    if voxel is not None:
        cargs.extend([
            "-voxel",
            str(voxel)
        ])
    if diskspace:
        cargs.append("-diskspace")
    if mask is not None:
        cargs.extend([
            "-mask",
            execution.input_file(mask)
        ])
    if debug is not None:
        cargs.extend([
            "-debug",
            str(debug)
        ])
    if ftr is not None:
        cargs.extend([
            "-ftr",
            ftr
        ])
    if mean is not None:
        cargs.extend([
            "-mean",
            mean
        ])
    if diff is not None:
        cargs.extend([
            "-diff",
            diff
        ])
    if contr is not None:
        cargs.extend([
            "-contr",
            contr
        ])
    if old_method:
        cargs.append("-old_method")
    if ok:
        cargs.append("-OK")
    if assume_sph:
        cargs.append("-assume_sph")
    if bucket is not None:
        cargs.extend([
            "-bucket",
            bucket
        ])
    ret = V3dAnovaOutputs(
        root=execution.output_file("."),
        ftr_output=execution.output_file(ftr + ".HEAD") if (ftr is not None) else None,
        ftr_brick_output=execution.output_file(ftr + ".BRIK") if (ftr is not None) else None,
        mean_output=execution.output_file(mean + "_mean.HEAD") if (mean is not None) else None,
        mean_brick_output=execution.output_file(mean + "_mean.BRIK") if (mean is not None) else None,
        diff_output=execution.output_file(diff + "_diff.HEAD") if (diff is not None) else None,
        diff_brick_output=execution.output_file(diff + "_diff.BRIK") if (diff is not None) else None,
        contr_output=execution.output_file(contr + "_contr.HEAD") if (contr is not None) else None,
        contr_brick_output=execution.output_file(contr + "_contr.BRIK") if (contr is not None) else None,
        bucket_output=execution.output_file(bucket + ".HEAD") if (bucket is not None) else None,
        bucket_brick_output=execution.output_file(bucket + ".BRIK") if (bucket is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "V3dAnovaOutputs",
    "V_3D_ANOVA_METADATA",
    "v_3d_anova",
]
