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

import typing
import pathlib
from styxdefs import *
import dataclasses

SURF_CLUST_METADATA = Metadata(
    id="2346425eb197f04f33322dea847636dd74a3b8a3.boutiques",
    name="SurfClust",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class SurfClustOutputs(typing.NamedTuple):
    """
    Output object returned when calling `surf_clust(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    cluster_table: OutputPathType | None
    """Cluster table output"""
    clustered_dataset: OutputPathType | None
    """Clustered version of input dataset"""
    roi_dataset: OutputPathType | None
    """ROI dataset with rank of clusters"""


def surf_clust(
    input_dataset: list[InputPathType],
    rmm: float,
    specfile: InputPathType | None = None,
    input_surface: str | None = None,
    input_surf_name: InputPathType | None = None,
    amm2: float | None = None,
    min_nodes: float | None = None,
    prefix: str | None = None,
    out_clusterdset: bool = False,
    out_roidset: bool = False,
    out_fulllist: bool = False,
    sort_none: bool = False,
    sort_n_nodes: bool = False,
    sort_area: bool = False,
    thresh_col: float | None = None,
    thresh: float | None = None,
    athresh: float | None = None,
    ir_range: list[float] | None = None,
    ex_range: list[float] | None = None,
    prepend_node_index: bool = False,
    update_: float | None = None,
    no_cent: bool = False,
    cent: bool = False,
    novolreg: bool = False,
    noxform: bool = False,
    set_env: str | None = None,
    trace_: bool = False,
    trace_extreme: bool = False,
    no_memory_trace: bool = False,
    yes_memory_trace: bool = False,
    mini_help: bool = False,
    help_: bool = False,
    extreme_help: bool = False,
    view_help: bool = False,
    web_help: bool = False,
    find_help: str | None = None,
    raw_help: bool = False,
    spx_help: bool = False,
    aspx_help: bool = False,
    runner: Runner | None = None,
) -> SurfClustOutputs:
    """
    A program to perform clustering analysis surfaces.
    
    Author: AFNI Developers
    
    URL: https://afni.nimh.nih.gov/
    
    Args:
        input_dataset: The input dataset and the index of the datacolumn to use\
            (index 0 for 1st column). Values of 0 indicate inactive nodes.
        rmm: Maximum distance between an activated node and the cluster to\
            which it belongs.
        specfile: The surface spec file.
        input_surface: The input surface name.
        input_surf_name: Full name of the input surface.
        amm2: Minimum area for clusters.
        min_nodes: Minimum nodes for clusters.
        prefix: Prefix for output. Default is the prefix of the input dataset.
        out_clusterdset: Output a clustered version of input dataset.
        out_roidset: Output an ROI dataset with the rank of its cluster.
        out_fulllist: Output a value for all nodes of input surface.
        sort_none: No sorting of ROI clusters.
        sort_n_nodes: Sorting based on number of nodes in cluster.
        sort_area: Sorting based on area of clusters (default).
        thresh_col: Index of thresholding column. Default is column 0.
        thresh: Apply thresholding prior to clustering.
        athresh: Apply absolute thresholding prior to clustering.
        ir_range: Apply thresholding in range. A node n is considered if\
            thresh_col[n] >= R0 && thresh_col[n] <= R1.
        ex_range: Apply thresholding outside of range. A node n is considered\
            if thresh_col[n] < R0 || thresh_col[n] > R1.
        prepend_node_index: Force the output dataset to have node indices in\
            column 0 of output.
        update_: Pacify me when perc of the data have been processed. perc is\
            between 1% and 50%. Default is no update.
        no_cent: Do not find the central nodes.
        cent: Do find the central nodes (default).
        novolreg: Ignore any Rotate, Volreg, Tagalign, or WarpDrive\
            transformations present in the Surface Volume.
        noxform: Same as -novolreg.
        set_env: Set environment variable ENVname to be ENVvalue. Quotes are\
            necessary.
        trace_: Turns on In/Out debug and Memory tracing.
        trace_extreme: Turns on extreme tracing.
        no_memory_trace: Turn off memory tracing.
        yes_memory_trace: Turn on memory tracing (default).
        mini_help: Mini help, same as -help in many cases.
        help_: The entire help output.
        extreme_help: Extreme help, same as -help in majority of cases.
        view_help: Open help in text editor. AFNI will try to find a GUI editor\
            on your machine. You can control which it should use by setting\
            environment variable AFNI_GUI_EDITOR.
        web_help: Open help in web browser. AFNI will try to find a browser.\
            You can control which it should use by setting environment variable\
            AFNI_GUI_EDITOR.
        find_help: Look for lines in this program's -help output that match\
            (approximately) the given word.
        raw_help: Help string unedited.
        spx_help: Help string in sphinx format, but do not try to autoformat.
        aspx_help: Help string in sphinx format with autoformatting of options.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfClustOutputs`).
    """
    if (len(input_dataset) != 2): 
        raise ValueError(f"Length of 'input_dataset' must be 2 but was {len(input_dataset)}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(SURF_CLUST_METADATA)
    cargs = []
    cargs.append("SurfClust")
    if specfile is not None:
        cargs.extend([
            "-spec",
            execution.input_file(specfile)
        ])
    if input_surface is not None:
        cargs.extend([
            "-surf_A",
            input_surface
        ])
    if input_surf_name is not None:
        cargs.extend([
            "-i",
            execution.input_file(input_surf_name)
        ])
    cargs.extend([
        "-input",
        *[execution.input_file(f) for f in input_dataset]
    ])
    cargs.extend([
        "-rmm",
        str(rmm)
    ])
    if amm2 is not None:
        cargs.extend([
            "-amm2",
            str(amm2)
        ])
    if min_nodes is not None:
        cargs.extend([
            "-n",
            str(min_nodes)
        ])
    if prefix is not None:
        cargs.extend([
            "-prefix",
            prefix
        ])
    if out_clusterdset:
        cargs.append("-out_clusterdset")
    if out_roidset:
        cargs.append("-out_roidset")
    if out_fulllist:
        cargs.append("-out_fulllist")
    if sort_none:
        cargs.append("-sort_none")
    if sort_n_nodes:
        cargs.append("-sort_n_nodes")
    if sort_area:
        cargs.append("-sort_area")
    if thresh_col is not None:
        cargs.extend([
            "-thresh_col",
            str(thresh_col)
        ])
    if thresh is not None:
        cargs.extend([
            "-thresh",
            str(thresh)
        ])
    if athresh is not None:
        cargs.extend([
            "-athresh",
            str(athresh)
        ])
    if ir_range is not None:
        cargs.extend([
            "-ir_range",
            *map(str, ir_range)
        ])
    if ex_range is not None:
        cargs.extend([
            "-ex_range",
            *map(str, ex_range)
        ])
    if prepend_node_index:
        cargs.append("-prepend_node_index")
    if update_ is not None:
        cargs.extend([
            "-update",
            str(update_)
        ])
    if no_cent:
        cargs.append("-no_cent")
    if cent:
        cargs.append("-cent")
    if novolreg:
        cargs.append("-novolreg")
    if noxform:
        cargs.append("-noxform")
    if set_env is not None:
        cargs.extend([
            "-setenv",
            set_env
        ])
    if trace_:
        cargs.append("-trace")
    if trace_extreme:
        cargs.append("-TRACE")
    if no_memory_trace:
        cargs.append("-nomall")
    if yes_memory_trace:
        cargs.append("-yesmall")
    if mini_help:
        cargs.append("-h")
    if help_:
        cargs.append("-help")
    if extreme_help:
        cargs.append("-HELP")
    if view_help:
        cargs.append("-h_view")
    if web_help:
        cargs.append("-h_web")
    if find_help is not None:
        cargs.extend([
            "-h_find",
            find_help
        ])
    if raw_help:
        cargs.append("-h_raw")
    if spx_help:
        cargs.append("-h_spx")
    if aspx_help:
        cargs.append("-h_aspx")
    ret = SurfClustOutputs(
        root=execution.output_file("."),
        cluster_table=execution.output_file(prefix + "_ClstTable_rXX_aXX.1D") if (prefix is not None) else None,
        clustered_dataset=execution.output_file(prefix + "_Clustered_rXX_aXX.dset") if (prefix is not None) else None,
        roi_dataset=execution.output_file(prefix + "_ClstMsk_rXX_aXX.dset") if (prefix is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "SURF_CLUST_METADATA",
    "SurfClustOutputs",
    "surf_clust",
]
