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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_FDR_METADATA = Metadata(
    id="c6df1fc3c682e8d10bc8100c6ca38bb1d5015a85.boutiques",
    name="mri_fdr",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriFdrOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_fdr(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_corrected: OutputPathType
    """Output after applying FDR correction"""
    output_threshold: OutputPathType
    """Threshold written to text file"""


def mri_fdr(
    input_files: list[str],
    fdr_value: float,
    default_frame: int | None = None,
    positive_only: bool = False,
    negative_only: bool = False,
    all_voxels: bool = False,
    raw_p_values: bool = False,
    threshold_file: str | None = None,
    debug: bool = False,
    check_options: bool = False,
    runner: Runner | None = None,
) -> MriFdrOutputs:
    """
    A program that performs False Discovery Rate correction.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        input_files: Input source volume or surface overlay. Specify mask,\
            output, and frame as needed.
        fdr_value: FDR value between 0 and 1, typically .05.
        default_frame: Use input frame when not specifying frame in --i.
        positive_only: Only consider positive voxels.
        negative_only: Only consider negative voxels.
        all_voxels: Consider all voxels regardless of sign (default).
        raw_p_values: Input is raw p-values, not -log10(p).
        threshold_file: Write threshold to text file.
        debug: Turn on debugging.
        check_options: Don't run anything, just check options and exit.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriFdrOutputs`).
    """
    if not (1 <= len(input_files)): 
        raise ValueError(f"Length of 'input_files' must be greater than 1 but was {len(input_files)}")
    if not (0 <= fdr_value <= 1): 
        raise ValueError(f"'fdr_value' must be between 0 <= x <= 1 but was {fdr_value}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_FDR_METADATA)
    cargs = []
    cargs.append("mri_fdr")
    cargs.extend([
        "--i",
        *input_files
    ])
    cargs.extend([
        "--fdr",
        str(fdr_value)
    ])
    if default_frame is not None:
        cargs.extend([
            "--f",
            str(default_frame)
        ])
    if positive_only:
        cargs.append("--pos")
    if negative_only:
        cargs.append("--neg")
    if all_voxels:
        cargs.append("--abs")
    if raw_p_values:
        cargs.append("--no-log10p")
    if threshold_file is not None:
        cargs.extend([
            "--thfile",
            threshold_file
        ])
    if debug:
        cargs.append("--debug")
    if check_options:
        cargs.append("--checkopts")
    ret = MriFdrOutputs(
        root=execution.output_file("."),
        output_corrected=execution.output_file("<output>.mgh"),
        output_threshold=execution.output_file("<output>_threshold.txt"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_FDR_METADATA",
    "MriFdrOutputs",
    "mri_fdr",
]
