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

import typing
import pathlib
from styxdefs import *
import dataclasses

V_3DCLUST_METADATA = Metadata(
    id="3ce8cefee5cef3ba7b1a972b0fcad6cd5a2fd94f.boutiques",
    name="3dclust",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class V3dclustOutputs(typing.NamedTuple):
    """
    Output object returned when calling `v_3dclust(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    prefixed_output: OutputPathType | None
    """New dataset with clusters set to zero based on prefix."""
    ordered_mask_output: OutputPathType | None
    """Ordered mask dataset based on savemask prefix."""


def v_3dclust(
    datasets: list[InputPathType],
    rmm: float | None = None,
    vmul: float | None = None,
    nn1: bool = False,
    nn2: bool = False,
    nn3: bool = False,
    noabs: bool = False,
    summarize: bool = False,
    nosum: bool = False,
    verb: bool = False,
    oned_format: bool = False,
    no_oned_format: bool = False,
    quiet: bool = False,
    mni: bool = False,
    isovalue: bool = False,
    isomerge: bool = False,
    inmask: bool = False,
    prefix: str | None = None,
    savemask: str | None = None,
    binary: bool = False,
    runner: Runner | None = None,
) -> V3dclustOutputs:
    """
    Performs simple-minded cluster detection in 3D datasets.
    
    Author: AFNI Developers
    
    URL: https://afni.nimh.nih.gov/
    
    Args:
        datasets: Input dataset(s). More than one allowed, but only the first\
            sub-brick of the dataset.
        rmm: Cluster connection radius in millimeters.
        vmul: Minimum cluster volume in micro-liters or minimum number of\
            voxels if negative.
        nn1: 1st nearest-neighbor clustering (faces touching).
        nn2: 2nd nearest-neighbor clustering (edges touching).
        nn3: 3rd nearest-neighbor clustering (corners touching).
        noabs: Use the signed voxel intensities for calculations.
        summarize: Write out only the total nonzero voxel count and volume for\
            each dataset.
        nosum: Suppress printout of the totals.
        verb: Print out a progress report to stderr as computations proceed.
        oned_format: Write output in 1D format (default).
        no_oned_format: Do not write output in 1D format.
        quiet: Suppress all non-essential output.
        mni: Transform output xyz-coordinates from TLRC to MNI space if the\
            input dataset has the +tlrc view.
        isovalue: Clusters will be formed only from contiguous voxels that also\
            have the same value.
        isomerge: Clusters will be formed from each distinct value in the\
            dataset; spatial contiguity will not be used.
        inmask: Use an internal mask from the dataset to eliminate voxels\
            before clustering.
        prefix: Write a new dataset that is a copy of the input, but with all\
            voxels not in a cluster set to zero; provide a prefix for the new\
            dataset.
        savemask: Write a new dataset that is an ordered mask where the largest\
            cluster is labeled '1', the next largest '2', and so forth.
        binary: Turn the output of '-savemask' into a binary (0 or 1) mask.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `V3dclustOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(V_3DCLUST_METADATA)
    cargs = []
    cargs.append("3dclust")
    if rmm is not None:
        cargs.append(str(rmm))
    if vmul is not None:
        cargs.append(str(vmul))
    cargs.extend([execution.input_file(f) for f in datasets])
    if nn1:
        cargs.append("-NN1")
    if nn2:
        cargs.append("-NN2")
    if nn3:
        cargs.append("-NN3")
    if noabs:
        cargs.append("-noabs")
    if summarize:
        cargs.append("-summarize")
    if nosum:
        cargs.append("-nosum")
    if verb:
        cargs.append("-verb")
    if oned_format:
        cargs.append("-1Dformat")
    if no_oned_format:
        cargs.append("-no_1Dformat")
    if quiet:
        cargs.append("-quiet")
    if mni:
        cargs.append("-mni")
    if isovalue:
        cargs.append("-isovalue")
    if isomerge:
        cargs.append("-isomerge")
    if inmask:
        cargs.append("-inmask")
    if prefix is not None:
        cargs.extend([
            "-prefix",
            prefix
        ])
    if savemask is not None:
        cargs.extend([
            "-savemask",
            savemask
        ])
    if binary:
        cargs.append("-binary")
    ret = V3dclustOutputs(
        root=execution.output_file("."),
        prefixed_output=execution.output_file(prefix + ".nii.gz") if (prefix is not None) else None,
        ordered_mask_output=execution.output_file(savemask + ".nii.gz") if (savemask is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "V3dclustOutputs",
    "V_3DCLUST_METADATA",
    "v_3dclust",
]
