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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_VOLCLUSTER_METADATA = Metadata(
    id="86e5f012e8262b1a51728b36e2469f6a4678ccf5.boutiques",
    name="mri_volcluster",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriVolclusterOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_volcluster(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_volume: OutputPathType | None
    """Output volume after clustering."""
    output_cluster_number_volume: OutputPathType | None
    """Output cluster number volume."""
    output_binary_mask: OutputPathType | None
    """Final binary mask output."""
    output_label_file: OutputPathType | None
    """Saved cluster as label file."""


def mri_volcluster(
    input_file: InputPathType,
    summary_file: str | None = None,
    output_volid: str | None = None,
    output_cluster_num_volid: str | None = None,
    cwsig_volid: str | None = None,
    pointset_file: str | None = None,
    min_threshold: float | None = None,
    max_threshold: float | None = None,
    sign: str | None = None,
    no_adjust_flag: bool = False,
    match_value: float | None = None,
    cwpval_threshold: float | None = None,
    registration_file: InputPathType | None = None,
    mni152reg_flag: bool = False,
    regheader_subject: str | None = None,
    fsaverage_flag: bool = False,
    frame_number: float | None = None,
    csd_files: list[InputPathType] | None = None,
    cwsig_map: str | None = None,
    vwsig_map: str | None = None,
    max_cwpval_file: str | None = None,
    csdpdf_file: str | None = None,
    csdpdf_only_flag: bool = False,
    fwhm_value: float | None = None,
    fwhm_file: InputPathType | None = None,
    min_size: float | None = None,
    min_size_vox: float | None = None,
    min_distance: float | None = None,
    allow_diag_flag: bool = False,
    bonferroni_number: float | None = None,
    bonferroni_max_number: float | None = None,
    sig2p_max_flag: bool = False,
    gte_flag: bool = False,
    mask_volid: InputPathType | None = None,
    mask_type: str | None = None,
    mask_frame: float | None = None,
    mask_threshold: float | None = None,
    mask_sign: str | None = None,
    mask_invert_flag: bool = False,
    out_mask_volid: str | None = None,
    out_mask_type: str | None = None,
    label_file: str | None = None,
    nlabel_cluster: float | None = None,
    label_base: str | None = None,
    synth_func: str | None = None,
    diagnostic_level: float | None = None,
    fill_params: str | None = None,
    help_flag: bool = False,
    runner: Runner | None = None,
) -> MriVolclusterOutputs:
    """
    A tool for finding clusters in a volume, useful for analyzing MRI data.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        input_file: Source of volume values.
        summary_file: Text summary file.
        output_volid: Output volume ID after clustering.
        output_cluster_num_volid: Output volume ID with cluster number values.
        cwsig_volid: Volume ID for clusterwise significance.
        pointset_file: Create a freeview pointset of the clusters.
        min_threshold: Minimum intensity threshold.
        max_threshold: Maximum intensity threshold.
        sign: Sign for one-sided tests (<abs>, pos, neg).
        no_adjust_flag: Do not adjust threshold for one-tailed tests.
        match_value: Set thmin=matchval-0.5 and thmax=matchval+0.5.
        cwpval_threshold: Require clusters to have cwp < threshold.
        registration_file: For reporting Talairach coordinates.
        mni152reg_flag: Input is in MNI152 space.
        regheader_subject: Use header registration with subject.
        fsaverage_flag: Assume input is in fsaverage space.
        frame_number: Perform cluster analysis on the nth frame (0-based).
        csd_files: Cluster simulation data files.
        cwsig_map: Map of corrected cluster-wise significances.
        vwsig_map: Map of corrected voxel-wise significances.
        max_cwpval_file: Save p-value of the largest cluster.
        csdpdf_file: PDF/CDF of cluster and max significance.
        csdpdf_only_flag: Write CSD PDF file and exit.
        fwhm_value: FWHM in mm^3, forces GRF analysis.
        fwhm_file: Text file with FWHM in mm^3 for GRF.
        min_size: Minimum volume (mm^3) for a cluster.
        min_size_vox: Minimum number of contiguous voxels for a cluster.
        min_distance: Minimum distance between peak clusters.
        allow_diag_flag: Allow diagonal adjacency for contiguity.
        bonferroni_number: Bonferroni correction across spaces.
        bonferroni_max_number: Bonferroni correction applied to maximum.
        sig2p_max_flag: Convert maximum significance to p-value.
        gte_flag: Use >= when computing p-value from CSD.
        mask_volid: Mask volume ID.
        mask_type: File type of mask volume.
        mask_frame: Nth frame of mask to use.
        mask_threshold: Upper threshold for the mask.
        mask_sign: Sign in mask thresholding (<abs>, neg, pos).
        mask_invert_flag: Invert mask after thresholding.
        out_mask_volid: Path for final binary mask.
        out_mask_type: File type for output mask.
        label_file: File to save nth cluster as a label.
        nlabel_cluster: Save the nth cluster as a label.
        label_base: Base name for saving clusters as labels.
        synth_func: Function for synthetic data (uniform, loguniform,\
            gaussian).
        diagnostic_level: Set diagnostic level.
        fill_params: Parameters for fill operation (invol outvol matchval).
        help_flag: Display help message and exit.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriVolclusterOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_VOLCLUSTER_METADATA)
    cargs = []
    cargs.append("mri_volcluster")
    cargs.extend([
        "--in",
        execution.input_file(input_file)
    ])
    if summary_file is not None:
        cargs.extend([
            "--sum",
            summary_file
        ])
    if output_volid is not None:
        cargs.extend([
            "--out",
            output_volid
        ])
    if output_cluster_num_volid is not None:
        cargs.extend([
            "--ocn",
            output_cluster_num_volid
        ])
    if cwsig_volid is not None:
        cargs.extend([
            "--cwsig",
            cwsig_volid
        ])
    if pointset_file is not None:
        cargs.extend([
            "--pointset",
            pointset_file
        ])
    if min_threshold is not None:
        cargs.extend([
            "--thmin",
            str(min_threshold)
        ])
    if max_threshold is not None:
        cargs.extend([
            "--thmax",
            str(max_threshold)
        ])
    if sign is not None:
        cargs.extend([
            "--sign",
            sign
        ])
    if no_adjust_flag:
        cargs.append("--no-adjust")
    if match_value is not None:
        cargs.extend([
            "--match",
            str(match_value)
        ])
    if cwpval_threshold is not None:
        cargs.extend([
            "--cwpvalthresh",
            str(cwpval_threshold)
        ])
    if registration_file is not None:
        cargs.extend([
            "--reg",
            execution.input_file(registration_file)
        ])
    if mni152reg_flag:
        cargs.append("--mni152reg")
    if regheader_subject is not None:
        cargs.extend([
            "--regheader",
            regheader_subject
        ])
    if fsaverage_flag:
        cargs.append("--fsaverage")
    if frame_number is not None:
        cargs.extend([
            "--frame",
            str(frame_number)
        ])
    if csd_files is not None:
        cargs.extend([
            "--csd",
            *[execution.input_file(f) for f in csd_files]
        ])
    if cwsig_map is not None:
        cargs.extend([
            "--cwsig",
            cwsig_map
        ])
    if vwsig_map is not None:
        cargs.extend([
            "--vwsig",
            vwsig_map
        ])
    if max_cwpval_file is not None:
        cargs.extend([
            "--maxcwpval",
            max_cwpval_file
        ])
    if csdpdf_file is not None:
        cargs.extend([
            "--csdpdf",
            csdpdf_file
        ])
    if csdpdf_only_flag:
        cargs.append("--csdpdf-only")
    if fwhm_value is not None:
        cargs.extend([
            "--fwhm",
            str(fwhm_value)
        ])
    if fwhm_file is not None:
        cargs.extend([
            "--fwhmdat",
            execution.input_file(fwhm_file)
        ])
    if min_size is not None:
        cargs.extend([
            "--minsize",
            str(min_size)
        ])
    if min_size_vox is not None:
        cargs.extend([
            "--minsizevox",
            str(min_size_vox)
        ])
    if min_distance is not None:
        cargs.extend([
            "--mindist",
            str(min_distance)
        ])
    if allow_diag_flag:
        cargs.append("--allowdiag")
    if bonferroni_number is not None:
        cargs.extend([
            "--bonferroni",
            str(bonferroni_number)
        ])
    if bonferroni_max_number is not None:
        cargs.extend([
            "--bonferroni-max",
            str(bonferroni_max_number)
        ])
    if sig2p_max_flag:
        cargs.append("--sig2p-max")
    if gte_flag:
        cargs.append("--gte")
    if mask_volid is not None:
        cargs.extend([
            "--mask",
            execution.input_file(mask_volid)
        ])
    if mask_type is not None:
        cargs.extend([
            "--mask_type",
            mask_type
        ])
    if mask_frame is not None:
        cargs.extend([
            "--maskframe",
            str(mask_frame)
        ])
    if mask_threshold is not None:
        cargs.extend([
            "--maskthresh",
            str(mask_threshold)
        ])
    if mask_sign is not None:
        cargs.extend([
            "--masksign",
            mask_sign
        ])
    if mask_invert_flag:
        cargs.append("--maskinvert")
    if out_mask_volid is not None:
        cargs.extend([
            "--outmask",
            out_mask_volid
        ])
    if out_mask_type is not None:
        cargs.extend([
            "--outmask_type",
            out_mask_type
        ])
    if label_file is not None:
        cargs.extend([
            "--label",
            label_file
        ])
    if nlabel_cluster is not None:
        cargs.extend([
            "--nlabelcluster",
            str(nlabel_cluster)
        ])
    if label_base is not None:
        cargs.extend([
            "--labelbase",
            label_base
        ])
    if synth_func is not None:
        cargs.extend([
            "--synth",
            synth_func
        ])
    if diagnostic_level is not None:
        cargs.extend([
            "--diag",
            str(diagnostic_level)
        ])
    if fill_params is not None:
        cargs.extend([
            "--fill",
            fill_params
        ])
    if help_flag:
        cargs.append("--help")
    ret = MriVolclusterOutputs(
        root=execution.output_file("."),
        output_volume=execution.output_file(output_volid) if (output_volid is not None) else None,
        output_cluster_number_volume=execution.output_file(output_cluster_num_volid) if (output_cluster_num_volid is not None) else None,
        output_binary_mask=execution.output_file(out_mask_volid) if (out_mask_volid is not None) else None,
        output_label_file=execution.output_file(label_file) if (label_file is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_VOLCLUSTER_METADATA",
    "MriVolclusterOutputs",
    "mri_volcluster",
]
