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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_SURFCLUSTER_METADATA = Metadata(
    id="d511292684dbbb10f74daadd0e2a8026a7360392.boutiques",
    name="mri_surfcluster",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriSurfclusterOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_surfcluster(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_surface_file: OutputPathType | None
    """Filtered surface file with non-cluster vertices set to 0"""
    output_cluster_number_file: OutputPathType | None
    """Surface file with cluster number per vertex"""
    output_labels: OutputPathType | None
    """Label files for clusters"""
    output_summary_file: OutputPathType | None
    """Text summary file of clustering results"""
    output_pointset_file: OutputPathType | None
    """Pointset file for visualization in Freeview"""
    output_max_area_file: OutputPathType | None
    """File containing the area of the largest cluster"""


def mri_surfcluster(
    infile: InputPathType,
    thmin: float | None = None,
    sign: str | None = None,
    no_adjust_flag: bool = False,
    fdr: float | None = None,
    subject: str | None = None,
    hemi: str | None = None,
    surf: str | None = None,
    surfpath: str | None = None,
    annot: str | None = None,
    frame: float | None = None,
    csd: list[InputPathType] | None = None,
    vwsig: str | None = None,
    cwsig: str | None = None,
    maxcwpval: str | None = None,
    bonferroni: float | None = None,
    sig2p_max_flag: bool = False,
    bonferroni_max: float | None = None,
    csdpdf: str | None = None,
    csdpdf_only_flag: bool = False,
    csd_out: InputPathType | None = None,
    cwpvalthresh: float | None = None,
    fwhm: float | None = None,
    fwhmdat: str | None = None,
    clabel: InputPathType | None = None,
    cortex_flag: bool = False,
    mask: InputPathType | None = None,
    mask_inv_flag: bool = False,
    centroid_flag: bool = False,
    sum_: InputPathType | None = None,
    pointset: InputPathType | None = None,
    maxareafile: str | None = None,
    o: str | None = None,
    ocn: str | None = None,
    olab: str | None = None,
    oannot: str | None = None,
    minarea: float | None = None,
    xfm: InputPathType | None = None,
    no_fixmni_flag: bool = False,
    sd: str | None = None,
    thmax: float | None = None,
    runner: Runner | None = None,
) -> MriSurfclusterOutputs:
    """
    A tool for clustering vertices on a cortical surface based on intensity values.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        infile: Source of surface values.
        thmin: Minimum intensity threshold.
        sign: Sign of threshold criteria (abs, pos, neg).
        no_adjust_flag: Do not adjust threshold for one-tailed tests.
        fdr: Set thmin with False Discovery Rate.
        subject: Source surface subject (can be ico).
        hemi: Cortical hemisphere, either lh or rh.
        surf: Coordinates from surface (e.g., white).
        surfpath: Full path to surface.
        annot: Report annotation for max vertex (e.g., aparc).
        frame: 0-based frame number of the input file.
        csd: Load one or more CSD files.
        vwsig: Map of corrected voxel-wise significances.
        cwsig: Map of cluster-wise significances.
        maxcwpval: Save p-value of the largest (max) cluster.
        bonferroni: Apply Bonferroni correction across N spaces.
        sig2p_max_flag: Convert max from sig to p.
        bonferroni_max: Apply Bonferroni correction to maximum.
        csdpdf: Compute PDF/CDF of CSD data and save.
        csdpdf_only_flag: Only write the CSD PDF file.
        csd_out: Write out merged CSD files as one.
        cwpvalthresh: Cluster-wise threshold.
        fwhm: FWHM in mm^2 for GRF.
        fwhmdat: Text file with FWHM in mm^2 for GRF.
        clabel: Constrain cluster search to be inside or outside clabel.
        cortex_flag: Set clabel to be subject/label/hemi.cortex.label.
        mask: Constrain to be within mask.
        mask_inv_flag: Constrain cluster search to be outside mask or clabel.
        centroid_flag: Report centroid instead of location of maximum stat.
        sum_: Text file to store cluster summary.
        pointset: File that can be read into Freeview with -c.
        maxareafile: Write area of largest cluster to this file.
        o: Output file with non-clusters set to 0.
        ocn: Output file where value is cluster number.
        olab: Output clusters as labels.
        oannot: Output clusters as an annotation.
        minarea: Area threshold for a cluster (mm^2).
        xfm: Talairach transform file.
        no_fixmni_flag: Do not fix MNI Talairach coordinates.
        sd: FreeSurfer subjects directory.
        thmax: Maximum intensity threshold.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriSurfclusterOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_SURFCLUSTER_METADATA)
    cargs = []
    cargs.append("mri_surfcluster")
    cargs.extend([
        "--in",
        execution.input_file(infile)
    ])
    if thmin is not None:
        cargs.extend([
            "--thmin",
            str(thmin)
        ])
    if sign is not None:
        cargs.extend([
            "--sign",
            sign
        ])
    if no_adjust_flag:
        cargs.append("--no-adjust")
    if fdr is not None:
        cargs.extend([
            "--fdr",
            str(fdr)
        ])
    if subject is not None:
        cargs.extend([
            "--subject",
            subject
        ])
    if hemi is not None:
        cargs.extend([
            "--hemi",
            hemi
        ])
    if surf is not None:
        cargs.extend([
            "--surf",
            surf
        ])
    if surfpath is not None:
        cargs.extend([
            "--surfpath",
            surfpath
        ])
    if annot is not None:
        cargs.extend([
            "--annot",
            annot
        ])
    if frame is not None:
        cargs.extend([
            "--frame",
            str(frame)
        ])
    if csd is not None:
        cargs.extend([
            "--csd",
            *[execution.input_file(f) for f in csd]
        ])
    if vwsig is not None:
        cargs.extend([
            "--vwsig",
            vwsig
        ])
    if cwsig is not None:
        cargs.extend([
            "--cwsig",
            cwsig
        ])
    if maxcwpval is not None:
        cargs.extend([
            "--maxcwpval",
            maxcwpval
        ])
    if bonferroni is not None:
        cargs.extend([
            "--bonferroni",
            str(bonferroni)
        ])
    if sig2p_max_flag:
        cargs.append("--sig2p-max")
    if bonferroni_max is not None:
        cargs.extend([
            "--bonferroni-max",
            str(bonferroni_max)
        ])
    if csdpdf is not None:
        cargs.extend([
            "--csdpdf",
            csdpdf
        ])
    if csdpdf_only_flag:
        cargs.append("--csdpdf-only")
    if csd_out is not None:
        cargs.extend([
            "--csd-out",
            execution.input_file(csd_out)
        ])
    if cwpvalthresh is not None:
        cargs.extend([
            "--cwpvalthresh",
            str(cwpvalthresh)
        ])
    if fwhm is not None:
        cargs.extend([
            "--fwhm",
            str(fwhm)
        ])
    if fwhmdat is not None:
        cargs.extend([
            "--fwhmdat",
            fwhmdat
        ])
    if clabel is not None:
        cargs.extend([
            "--clabel",
            execution.input_file(clabel)
        ])
    if cortex_flag:
        cargs.append("--cortex")
    if mask is not None:
        cargs.extend([
            "--mask",
            execution.input_file(mask)
        ])
    if mask_inv_flag:
        cargs.append("--mask-inv")
    if centroid_flag:
        cargs.append("--centroid")
    if sum_ is not None:
        cargs.extend([
            "--sum",
            execution.input_file(sum_)
        ])
    if pointset is not None:
        cargs.extend([
            "--pointset",
            execution.input_file(pointset)
        ])
    if maxareafile is not None:
        cargs.extend([
            "--maxareafile",
            maxareafile
        ])
    if o is not None:
        cargs.extend([
            "--o",
            o
        ])
    if ocn is not None:
        cargs.extend([
            "--ocn",
            ocn
        ])
    if olab is not None:
        cargs.extend([
            "--olab",
            olab
        ])
    if oannot is not None:
        cargs.extend([
            "--oannot",
            oannot
        ])
    if minarea is not None:
        cargs.extend([
            "--minarea",
            str(minarea)
        ])
    if xfm is not None:
        cargs.extend([
            "--xfm",
            execution.input_file(xfm)
        ])
    if no_fixmni_flag:
        cargs.append("--nofixmni")
    if sd is not None:
        cargs.extend([
            "--sd",
            sd
        ])
    if thmax is not None:
        cargs.extend([
            "--thmax",
            str(thmax)
        ])
    ret = MriSurfclusterOutputs(
        root=execution.output_file("."),
        output_surface_file=execution.output_file(o) if (o is not None) else None,
        output_cluster_number_file=execution.output_file(ocn) if (ocn is not None) else None,
        output_labels=execution.output_file(olab + "-*.label") if (olab is not None) else None,
        output_summary_file=execution.output_file(pathlib.Path(sum_).name) if (sum_ is not None) else None,
        output_pointset_file=execution.output_file(pathlib.Path(pointset).name) if (pointset is not None) else None,
        output_max_area_file=execution.output_file(maxareafile) if (maxareafile is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_SURFCLUSTER_METADATA",
    "MriSurfclusterOutputs",
    "mri_surfcluster",
]
