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

import typing
import pathlib
from styxdefs import *
import dataclasses

V_3D_ANOVA2_METADATA = Metadata(
    id="ebf600e872cacd3686c204e18def40bac83877e7.boutiques",
    name="3dANOVA2",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class V3dAnova2Outputs(typing.NamedTuple):
    """
    Output object returned when calling `v_3d_anova2(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_ftr: OutputPathType | None
    """F-statistic for treatment effect output file"""
    output_fa: OutputPathType | None
    """F-statistic for factor A effect output file"""
    output_fb: OutputPathType | None
    """F-statistic for factor B effect output file"""
    output_fab: OutputPathType | None
    """F-statistic for interaction output file"""
    output_amean: OutputPathType | None
    """Estimate mean of factor A level output file"""
    output_bmean: OutputPathType | None
    """Estimate mean of factor B level output file"""
    output_xmean: OutputPathType | None
    """Estimate mean of cell at level i of factor A and level j of factor B
    output file"""
    output_adiff: OutputPathType | None
    """Difference between levels i and j of factor A output file"""
    output_bdiff: OutputPathType | None
    """Difference between levels i and j of factor B output file"""
    output_xdiff: OutputPathType | None
    """Difference between cell mean at A=i, B=j and cell mean at A=k, B=l output
    file"""
    output_acontr: OutputPathType | None
    """Contrast in factor A levels output file"""
    output_bcontr: OutputPathType | None
    """Contrast in factor B levels output file"""
    output_xcontr: OutputPathType | None
    """Contrast in cell means output file"""
    output_bucket: OutputPathType | None
    """Create one AFNI 'bucket' dataset file"""


def v_3d_anova2(
    type_: int,
    alevels: int,
    blevels: int,
    dataset: list[str] | None = None,
    voxel: int | None = None,
    diskspace: bool = False,
    mask: InputPathType | None = None,
    ftr: str | None = None,
    fa: str | None = None,
    fb: str | None = None,
    fab: str | None = None,
    amean: str | None = None,
    bmean: str | None = None,
    xmean: str | None = None,
    adiff: str | None = None,
    bdiff: str | None = None,
    xdiff: str | None = None,
    acontr: str | None = None,
    bcontr: str | None = None,
    xcontr: str | None = None,
    bucket: str | None = None,
    old_method: bool = False,
    ok: bool = False,
    assume_sph: bool = False,
    runner: Runner | None = None,
) -> V3dAnova2Outputs:
    """
    This program performs a two-factor Analysis of Variance (ANOVA) on 3D datasets.
    
    Author: AFNI Developers
    
    URL: https://afni.nimh.nih.gov/
    
    Args:
        type_: Type of ANOVA model to be used: 1=fixed, 2=random, 3=mixed.
        alevels: Number of levels of factor A.
        blevels: Number of levels of factor B.
        dataset: Data set for levels of factor A and factor B.
        voxel: Screen output for voxel number.
        diskspace: Print out disk space required for program execution.
        mask: Use sub-brick #0 of dataset 'mset' to define which voxels to\
            process.
        ftr: F-statistic for treatment effect.
        fa: F-statistic for factor A effect.
        fb: F-statistic for factor B effect.
        fab: F-statistic for interaction.
        amean: Estimate mean of factor A level.
        bmean: Estimate mean of factor B level.
        xmean: Estimate mean of cell at level i of factor A and level j of\
            factor B.
        adiff: Difference between levels i and j of factor A.
        bdiff: Difference between levels i and j of factor B.
        xdiff: Difference between cell mean at A=i, B=j and cell mean at A=k,\
            B=l.
        acontr: Contrast in factor A levels.
        bcontr: Contrast in factor B levels.
        xcontr: Contrast in cell means.
        bucket: Create one AFNI 'bucket' dataset whose sub-bricks are obtained\
            by concatenating the above output files.
        old_method: Request to perform ANOVA using the previous functionality\
            (requires -OK, also).
        ok: Confirm understanding that contrasts that do not sum to zero have\
            inflated t-stats, and contrasts that do sum to zero assume sphericity\
            (to be used with -old_method).
        assume_sph: Assume sphericity (zero-sum contrasts, only). This allows\
            use of the old_method for computing contrasts which sum to zero.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `V3dAnova2Outputs`).
    """
    if not (1 <= type_ <= 3): 
        raise ValueError(f"'type_' must be between 1 <= x <= 3 but was {type_}")
    if dataset is not None and not (1 <= len(dataset)): 
        raise ValueError(f"Length of 'dataset' must be greater than 1 but was {len(dataset)}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(V_3D_ANOVA2_METADATA)
    cargs = []
    cargs.append("3dANOVA2")
    cargs.extend([
        "-type",
        str(type_)
    ])
    cargs.extend([
        "-alevels",
        str(alevels)
    ])
    cargs.extend([
        "-blevels",
        str(blevels)
    ])
    if dataset is not None:
        cargs.extend([
            "-dset",
            *dataset
        ])
    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 ftr is not None:
        cargs.extend([
            "-ftr",
            ftr
        ])
    if fa is not None:
        cargs.extend([
            "-fa",
            fa
        ])
    if fb is not None:
        cargs.extend([
            "-fb",
            fb
        ])
    if fab is not None:
        cargs.extend([
            "-fab",
            fab
        ])
    if amean is not None:
        cargs.extend([
            "-amean",
            amean
        ])
    if bmean is not None:
        cargs.extend([
            "-bmean",
            bmean
        ])
    if xmean is not None:
        cargs.extend([
            "-xmean",
            xmean
        ])
    if adiff is not None:
        cargs.extend([
            "-adiff",
            adiff
        ])
    if bdiff is not None:
        cargs.extend([
            "-bdiff",
            bdiff
        ])
    if xdiff is not None:
        cargs.extend([
            "-xdiff",
            xdiff
        ])
    if acontr is not None:
        cargs.extend([
            "-acontr",
            acontr
        ])
    if bcontr is not None:
        cargs.extend([
            "-bcontr",
            bcontr
        ])
    if xcontr is not None:
        cargs.extend([
            "-xcontr",
            xcontr
        ])
    if bucket is not None:
        cargs.extend([
            "-bucket",
            bucket
        ])
    if old_method:
        cargs.append("-old_method")
    if ok:
        cargs.append("-OK")
    if assume_sph:
        cargs.append("-assume_sph")
    ret = V3dAnova2Outputs(
        root=execution.output_file("."),
        output_ftr=execution.output_file(ftr + ".+tlrc") if (ftr is not None) else None,
        output_fa=execution.output_file(fa + ".+tlrc") if (fa is not None) else None,
        output_fb=execution.output_file(fb + ".+tlrc") if (fb is not None) else None,
        output_fab=execution.output_file(fab + ".+tlrc") if (fab is not None) else None,
        output_amean=execution.output_file(amean + ".+tlrc") if (amean is not None) else None,
        output_bmean=execution.output_file(bmean + ".+tlrc") if (bmean is not None) else None,
        output_xmean=execution.output_file(xmean + ".+tlrc") if (xmean is not None) else None,
        output_adiff=execution.output_file(adiff + ".+tlrc") if (adiff is not None) else None,
        output_bdiff=execution.output_file(bdiff + ".+tlrc") if (bdiff is not None) else None,
        output_xdiff=execution.output_file(xdiff + ".+tlrc") if (xdiff is not None) else None,
        output_acontr=execution.output_file(acontr + ".+tlrc") if (acontr is not None) else None,
        output_bcontr=execution.output_file(bcontr + ".+tlrc") if (bcontr is not None) else None,
        output_xcontr=execution.output_file(xcontr + ".+tlrc") if (xcontr is not None) else None,
        output_bucket=execution.output_file(bucket + ".+tlrc") if (bucket is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "V3dAnova2Outputs",
    "V_3D_ANOVA2_METADATA",
    "v_3d_anova2",
]
