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

import typing
import pathlib
from styxdefs import *
import dataclasses

V_3D_CLUSTERIZE_METADATA = Metadata(
    id="5bc26198ecd1ed079d05ba6875036e96b7ea8faf.boutiques",
    name="3dClusterize",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class V3dClusterizeOutputs(typing.NamedTuple):
    """
    Output object returned when calling `v_3d_clusterize(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    out_map_file: OutputPathType | None
    """Output map of cluster ROIs"""
    out_data_file: OutputPathType | None
    """Cluster-masked version of the data volume"""
    out_mask_file: OutputPathType | None
    """Utilized mask dataset"""


def v_3d_clusterize(
    inset: InputPathType,
    ithr: str,
    nn: int,
    mask: InputPathType | None = None,
    mask_from_hdr: bool = False,
    out_mask: str | None = None,
    idat: str | None = None,
    onesided: str | None = None,
    twosided: str | None = None,
    bisided: str | None = None,
    within_range: str | None = None,
    clust_nvox: int | None = None,
    clust_vol: int | None = None,
    pref_map: str | None = None,
    pref_dat: str | None = None,
    one_d_format: bool = False,
    no_one_d_format: bool = False,
    summarize: bool = False,
    nosum: bool = False,
    quiet: bool = False,
    outvol_if_no_clust: bool = False,
    orient: str | None = None,
    abs_table_data: bool = False,
    binary: bool = False,
    runner: Runner | None = None,
) -> V3dClusterizeOutputs:
    """
    A tool for voxelwise thresholding and clusterizing of datasets.
    
    Author: AFNI Team
    
    URL: https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dClusterize.html
    
    Args:
        inset: Load in a dataset for thresholding and clusterizing.
        ithr: Specify the sub-brick to use as the threshold source.
        nn: Specify the number of voxel neighbors (1: 6, 2: 18, 3: 26).
        mask: Load in a dataset to use as a mask.
        mask_from_hdr: Use internal mask from dataset header.
        out_mask: Specify to dump the utilized mask as a dataset.
        idat: Specify the sub-brick to use as the data source.
        onesided: Perform one-sided testing.
        twosided: Perform two-sided testing.
        bisided: Perform bisided testing.
        within_range: Keep values within the range [AA, BB].
        clust_nvox: Specify the minimum cluster size in terms of number of\
            voxels.
        clust_vol: Specify the minimum cluster size by volume in microliters.
        pref_map: Prefix/filename of the output map of cluster ROIs.
        pref_dat: Output a cluster-masked version of the data volume.
        one_d_format: Write output in 1D format.
        no_one_d_format: Do not write output in 1D format.
        summarize: Write out only the total nonzero voxel count and volume for\
            each dataset.
        nosum: Suppress printout of the totals.
        quiet: Suppress all non-essential output.
        outvol_if_no_clust: Output an empty volume if no clusters are found.
        orient: Coordinate order in the output report table (default: RAI).
        abs_table_data: Use absolute values for mean and SEM in report table.
        binary: Turn output map of cluster ROIs into a binary mask.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `V3dClusterizeOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(V_3D_CLUSTERIZE_METADATA)
    cargs = []
    cargs.append("3dClusterize")
    cargs.extend([
        "-inset",
        execution.input_file(inset)
    ])
    if mask is not None:
        cargs.extend([
            "-mask",
            execution.input_file(mask)
        ])
    if mask_from_hdr:
        cargs.append("-mask_from_hdr")
    if out_mask is not None:
        cargs.extend([
            "-out_mask",
            out_mask
        ])
    cargs.extend([
        "-ithr",
        ithr
    ])
    if idat is not None:
        cargs.extend([
            "-idat",
            idat
        ])
    if onesided is not None:
        cargs.extend([
            "-1sided",
            onesided
        ])
    if twosided is not None:
        cargs.extend([
            "-2sided",
            twosided
        ])
    if bisided is not None:
        cargs.extend([
            "-bisided",
            bisided
        ])
    if within_range is not None:
        cargs.extend([
            "-within_range",
            within_range
        ])
    cargs.extend([
        "-NN",
        str(nn)
    ])
    if clust_nvox is not None:
        cargs.extend([
            "-clust_nvox",
            str(clust_nvox)
        ])
    if clust_vol is not None:
        cargs.extend([
            "-clust_vol",
            str(clust_vol)
        ])
    if pref_map is not None:
        cargs.extend([
            "-pref_map",
            pref_map
        ])
    if pref_dat is not None:
        cargs.extend([
            "-pref_dat",
            pref_dat
        ])
    if one_d_format:
        cargs.append("-1Dformat")
    if no_one_d_format:
        cargs.append("-no_1Dformat")
    if summarize:
        cargs.append("-summarize")
    if nosum:
        cargs.append("-nosum")
    if quiet:
        cargs.append("-quiet")
    if outvol_if_no_clust:
        cargs.append("-outvol_if_no_clust")
    if orient is not None:
        cargs.extend([
            "-orient",
            orient
        ])
    if abs_table_data:
        cargs.append("-abs_table_data")
    if binary:
        cargs.append("-binary")
    ret = V3dClusterizeOutputs(
        root=execution.output_file("."),
        out_map_file=execution.output_file(pref_map + "+orig.HEAD") if (pref_map is not None) else None,
        out_data_file=execution.output_file(pref_dat + "+orig.HEAD") if (pref_dat is not None) else None,
        out_mask_file=execution.output_file(out_mask + "+orig.HEAD") if (out_mask is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "V3dClusterizeOutputs",
    "V_3D_CLUSTERIZE_METADATA",
    "v_3d_clusterize",
]
