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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_GLMFIT_SIM_METADATA = Metadata(
    id="b485cfa7c95293942f2efa8d5ccde5c8c33116e9.boutiques",
    name="mri_glmfit-sim",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriGlmfitSimOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_glmfit_sim(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    sig_voxel_mgh: OutputPathType | None
    """Sig volume corrected for voxel-wise multiple comparisons."""
    sig_cluster_mgh: OutputPathType | None
    """Sig volume corrected for cluster-wise multiple comparisons."""
    sig_cluster_summary: OutputPathType | None
    """Cluster summary table."""
    y_ocn_dat: OutputPathType | None
    """Summary of the input (y) over each cluster."""
    sig_ocn_mgh: OutputPathType | None
    """Output cluster number volume."""
    sig_ocn_annot: OutputPathType | None
    """Cluster annotation for surfaces."""
    sig_masked_mgh: OutputPathType | None
    """Original sig volume masked to show only clusters."""


def mri_glmfit_sim(
    glmdir: str,
    cwp: float | None = None,
    mczsim: str | None = None,
    mczsim_dir: str | None = None,
    mczsim_label: str | None = None,
    perm: str | None = None,
    perm_resid: bool = False,
    perm_signflip: bool = False,
    grf: str | None = None,
    spaces_2: bool = False,
    spaces_3: bool = False,
    overwrite: bool = False,
    bg: float | None = None,
    sleep: float | None = None,
    a2009s: bool = False,
    annot: str | None = None,
    log: str | None = None,
    base: str | None = None,
    no_sim: str | None = None,
    seed: float | None = None,
    fwhm_override: float | None = None,
    fwhm_add: float | None = None,
    uniform: list[float] | None = None,
    no_out_annot: bool = False,
    no_cluster_mean: bool = False,
    y_file: InputPathType | None = None,
    centroid: bool = False,
    spatial_sum: bool = False,
    help_: bool = False,
    runner: Runner | None = None,
) -> MriGlmfitSimOutputs:
    """
    A tool to run corrections for multiple comparisons on volumes or surfaces, using
    various methods including Monte Carlo simulation, permutation, and Gaussian
    Random Fields.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        glmdir: Path to GLM directory.
        cwp: Cluster-wise p-value threshold, default is 0.05.
        mczsim: Use pre-computed z-based Monte Carlo simulations. Requires\
            vwthreshold and sign.
        mczsim_dir: Directory for custom Monte Carlo simulations, default is\
            FREESURFER_HOME/average/mult-comp-cor.
        mczsim_label: Label for custom Monte Carlo simulations, default is\
            cortex.
        perm: Use permutation simulation with nsim iterations, cluster forming\
            threshold (CFT), and sign.
        perm_resid: Use permutation on the residual instead of raw data for\
            non-orthogonal designs.
        perm_signflip: Use sign flipping instead of shuffling for permutation.
        grf: Use Gaussian Random Fields (GRF) method, with vwthreshold and\
            sign.
        spaces_2: Apply additional Bonferroni correction across 2 spaces.
        spaces_3: Apply additional Bonferroni correction across 3 spaces.
        overwrite: Delete previous CSDs.
        bg: Divide simulation into njobs and put in background.
        sleep: Number of seconds to sleep between background polls.
        a2009s: Use aparc.a2009s instead of aparc for region of vertex max.
        annot: Use specific annotation for region of vertex max.
        log: Specify logfile, default is csdbase.mri_glmfit-sim.log.
        base: Override csdbase name.
        no_sim: Do not simulate, only run cluster.
        seed: Set simulation random number generator seed.
        fwhm_override: Override fwhm in glmdir.
        fwhm_add: Add fwhmAdd to the estimated fwhm.
        uniform: Use uniform PDF instead of gaussian, specify min and max.
        no_out_annot: Do not output a cluster annotation.
        no_cluster_mean: Do not compute means of each subject in each cluster.
        y_file: Specify the GLM input y file.
        centroid: Report the coordinates/annotation of the centroid instead of\
            max.
        spatial_sum: Compute the sum over voxels in the cluster rather than the\
            average.
        help_: Show the help message and exit.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriGlmfitSimOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_GLMFIT_SIM_METADATA)
    cargs = []
    cargs.append("mri_glmfit-sim")
    cargs.extend([
        "--glmdir",
        glmdir
    ])
    if cwp is not None:
        cargs.extend([
            "--cwp",
            str(cwp)
        ])
    if mczsim is not None:
        cargs.extend([
            "--mczsim",
            mczsim
        ])
    if mczsim_dir is not None:
        cargs.extend([
            "--mczsim-dir",
            mczsim_dir
        ])
    if mczsim_label is not None:
        cargs.extend([
            "--mczsim-label",
            mczsim_label
        ])
    if perm is not None:
        cargs.extend([
            "--perm",
            perm
        ])
    if perm_resid:
        cargs.append("--perm-resid")
    if perm_signflip:
        cargs.append("--perm-signflip")
    if grf is not None:
        cargs.extend([
            "--grf",
            grf
        ])
    if spaces_2:
        cargs.append("--2spaces")
    if spaces_3:
        cargs.append("--3spaces")
    if overwrite:
        cargs.append("--overwrite")
    if bg is not None:
        cargs.extend([
            "--bg",
            str(bg)
        ])
    if sleep is not None:
        cargs.extend([
            "--sleep",
            str(sleep)
        ])
    if a2009s:
        cargs.append("--a2009s")
    if annot is not None:
        cargs.extend([
            "--annot",
            annot
        ])
    if log is not None:
        cargs.extend([
            "--log",
            log
        ])
    if base is not None:
        cargs.extend([
            "--base",
            base
        ])
    if no_sim is not None:
        cargs.extend([
            "--no-sim",
            no_sim
        ])
    if seed is not None:
        cargs.extend([
            "--seed",
            str(seed)
        ])
    if fwhm_override is not None:
        cargs.extend([
            "--fwhm-override",
            str(fwhm_override)
        ])
    if fwhm_add is not None:
        cargs.extend([
            "--fwhm-add",
            str(fwhm_add)
        ])
    if uniform is not None:
        cargs.extend([
            "--uniform",
            *map(str, uniform)
        ])
    if no_out_annot:
        cargs.append("--no-out-annot")
    if no_cluster_mean:
        cargs.append("--no-cluster-mean")
    if y_file is not None:
        cargs.extend([
            "--y",
            execution.input_file(y_file)
        ])
    if centroid:
        cargs.append("--centroid")
    if spatial_sum:
        cargs.append("--spatial-sum")
    if help_:
        cargs.append("--help")
    ret = MriGlmfitSimOutputs(
        root=execution.output_file("."),
        sig_voxel_mgh=execution.output_file(base + ".sig.voxel.mgh") if (base is not None) else None,
        sig_cluster_mgh=execution.output_file(base + ".sig.cluster.mgh") if (base is not None) else None,
        sig_cluster_summary=execution.output_file(base + ".sig.cluster.summary") if (base is not None) else None,
        y_ocn_dat=execution.output_file(base + ".y.ocn.dat") if (base is not None) else None,
        sig_ocn_mgh=execution.output_file(base + ".sig.ocn.mgh") if (base is not None) else None,
        sig_ocn_annot=execution.output_file(base + ".sig.ocn.annot") if (base is not None) else None,
        sig_masked_mgh=execution.output_file(base + ".sig.masked.mgh") if (base is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_GLMFIT_SIM_METADATA",
    "MriGlmfitSimOutputs",
    "mri_glmfit_sim",
]
