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

import typing
import pathlib
from styxdefs import *
import dataclasses

FIND_VARIANCE_LINES_METADATA = Metadata(
    id="400a7e1ff61116676091a1736a0b5ffb08f0a496.boutiques",
    name="find_variance_lines",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class FindVarianceLinesOutputs(typing.NamedTuple):
    """
    Output object returned when calling `find_variance_lines(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    variance_maps: OutputPathType | None
    """Variance maps per run"""
    scaled_variance_maps: OutputPathType | None
    """Scaled variance maps per run"""
    cluster_reports: OutputPathType | None
    """Cluster reports"""
    jpeg_images: OutputPathType | None
    """JPEG images showing locations of high variance"""


def find_variance_lines(
    input_files: list[InputPathType],
    mask: str | None = None,
    min_cvox: int | None = None,
    min_nt: int | None = None,
    nerode: int | None = None,
    nfirst: int | None = None,
    percentile: int | None = None,
    polort: str | None = None,
    output_dir: str | None = None,
    do_clean: int | None = None,
    do_img: int | None = None,
    echo: bool = False,
    help_: bool = False,
    hist: bool = False,
    ver: bool = False,
    runner: Runner | None = None,
) -> FindVarianceLinesOutputs:
    """
    Look for bars of high variance that might suggest scanner interference in EPI
    datasets.
    
    Author: AFNI Developers
    
    URL: https://afni.nimh.nih.gov/
    
    Args:
        input_files: Input EPI datasets.
        mask: Mask for computations (default=AUTO).
        min_cvox: Minimum voxels for valid mask column (default=5).
        min_nt: Minimum number of time points required (default=10).
        nerode: How much to erode input or auto-mask (default=0).
        nfirst: Discard the first VAL time points (default=0).
        percentile: Percentile of variance values to scale to (default=90).
        polort: Polynomial detrending degree (default=A).
        output_dir: Name of the output directory (default=vlines.result).
        do_clean: Do we clean up a little? (default=1).
        do_img: Make vline images? (default=1).
        echo: Run script with shell 'echo' set (default=no).
        help_: Show this help.
        hist: Show the version history.
        ver: Show the current version.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `FindVarianceLinesOutputs`).
    """
    if percentile is not None and not (0 <= percentile <= 99): 
        raise ValueError(f"'percentile' must be between 0 <= x <= 99 but was {percentile}")
    if do_clean is not None and not (0 <= do_clean <= 1): 
        raise ValueError(f"'do_clean' must be between 0 <= x <= 1 but was {do_clean}")
    if do_img is not None and not (0 <= do_img <= 1): 
        raise ValueError(f"'do_img' must be between 0 <= x <= 1 but was {do_img}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(FIND_VARIANCE_LINES_METADATA)
    cargs = []
    cargs.append("find_variance_lines.tcsh")
    cargs.extend([execution.input_file(f) for f in input_files])
    if mask is not None:
        cargs.extend([
            "-mask",
            mask
        ])
    if min_cvox is not None:
        cargs.extend([
            "-min_cvox",
            str(min_cvox)
        ])
    if min_nt is not None:
        cargs.extend([
            "-min_nt",
            str(min_nt)
        ])
    if nerode is not None:
        cargs.extend([
            "-nerode",
            str(nerode)
        ])
    if nfirst is not None:
        cargs.extend([
            "-nfirst",
            str(nfirst)
        ])
    if percentile is not None:
        cargs.extend([
            "-perc",
            str(percentile)
        ])
    if polort is not None:
        cargs.extend([
            "-polort",
            polort
        ])
    if output_dir is not None:
        cargs.extend([
            "-rdir",
            output_dir
        ])
    if do_clean is not None:
        cargs.extend([
            "-do_clean",
            str(do_clean)
        ])
    if do_img is not None:
        cargs.extend([
            "-do_img",
            str(do_img)
        ])
    if echo:
        cargs.append("-echo")
    if help_:
        cargs.append("-help")
    if hist:
        cargs.append("-hist")
    if ver:
        cargs.append("-ver")
    ret = FindVarianceLinesOutputs(
        root=execution.output_file("."),
        variance_maps=execution.output_file(output_dir + "/variance_map_run*.nii.gz") if (output_dir is not None) else None,
        scaled_variance_maps=execution.output_file(output_dir + "/scaled_variance_map_run*.nii.gz") if (output_dir is not None) else None,
        cluster_reports=execution.output_file(output_dir + "/cluster_report_run*.txt") if (output_dir is not None) else None,
        jpeg_images=execution.output_file(output_dir + "/*.jpg") if (output_dir is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "FIND_VARIANCE_LINES_METADATA",
    "FindVarianceLinesOutputs",
    "find_variance_lines",
]
