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

import typing
import pathlib
from styxdefs import *
import dataclasses

FSL_REGFILT_METADATA = Metadata(
    id="c358956cca1d2a0a95737c27fdb8da975b6c0db6.boutiques",
    name="fsl_regfilt",
    package="fsl",
    container_image_tag="brainlife/fsl:6.0.4-patched2",
)


class FslRegfiltOutputs(typing.NamedTuple):
    """
    Output object returned when calling `fsl_regfilt(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    filtered_data: OutputPathType
    """Filtered data output"""
    preprocessed_data: OutputPathType | None
    """Pre-processed data output"""
    mixing_matrix: OutputPathType | None
    """New mixing matrix output"""
    vnscales: OutputPathType | None
    """Variance normalisation scaling factors output"""


def fsl_regfilt(
    infile: InputPathType,
    designfile: InputPathType,
    outfile: str,
    maskfile: InputPathType | None = None,
    filter_: str | None = None,
    freq_filter_flag: bool = False,
    freq_ic_flag: bool = False,
    freq_ic_smooth: float | None = None,
    fthresh: float | None = 0.15,
    fthresh2: float | None = 0.02,
    vn_flag: bool = False,
    verbose_flag: bool = False,
    aggressive_flag: bool = False,
    help_flag: bool = False,
    out_data: str | None = None,
    out_mix: str | None = None,
    out_vnscales: str | None = None,
    runner: Runner | None = None,
) -> FslRegfiltOutputs:
    """
    Data de-noising by regressing out part of a design matrix using simple OLS
    regression on 4D images.
    
    Author: FMRIB Analysis Group, University of Oxford
    
    URL: https://fsl.fmrib.ox.ac.uk/fsl/fslwiki
    
    Args:
        infile: Input file name (4D image).
        designfile: File name of the matrix with time courses (e.g. GLM design\
            or MELODIC mixing matrix).
        outfile: Output file name for the filtered data.
        maskfile: Mask image file name.
        filter_: Filter out part of the regression model, e.g., -f "1,2,3".
        freq_filter_flag: Filter out components based on high vs. low frequency\
            content.
        freq_ic_flag: Switch off IC Z-stats filtering as part of frequency\
            filtering.
        freq_ic_smooth: Smoothing width for IC Z-stats filtering as part of\
            frequency filtering.
        fthresh: Frequency threshold ratio; default: 0.15.
        fthresh2: Frequency filter score threshold; default: 0.02.
        vn_flag: Perform variance-normalisation on data.
        verbose_flag: Switch on diagnostic messages.
        aggressive_flag: Switch on aggressive filtering (full instead of\
            partial regression).
        help_flag: Display help text.
        out_data: Output file name for pre-processed data (prior to denoising).
        out_mix: Output file name for new mixing matrix.
        out_vnscales: Output file name for scaling factors from variance\
            normalisation.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `FslRegfiltOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(FSL_REGFILT_METADATA)
    cargs = []
    cargs.append("fsl_regfilt")
    cargs.extend([
        "-i",
        execution.input_file(infile)
    ])
    cargs.extend([
        "-d",
        execution.input_file(designfile)
    ])
    cargs.extend([
        "-o",
        outfile
    ])
    if maskfile is not None:
        cargs.extend([
            "-m",
            execution.input_file(maskfile)
        ])
    if filter_ is not None:
        cargs.extend([
            "-f",
            filter_
        ])
    if freq_filter_flag:
        cargs.append("-F")
    if freq_ic_flag:
        cargs.append("--freq_ic")
    if freq_ic_smooth is not None:
        cargs.extend([
            "--freq_ic_smooth",
            str(freq_ic_smooth)
        ])
    if fthresh is not None:
        cargs.extend([
            "--fthresh",
            str(fthresh)
        ])
    if fthresh2 is not None:
        cargs.extend([
            "--fthresh2",
            str(fthresh2)
        ])
    if vn_flag:
        cargs.append("--vn")
    if verbose_flag:
        cargs.append("-v")
    if aggressive_flag:
        cargs.append("-a")
    if help_flag:
        cargs.append("-h")
    if out_data is not None:
        cargs.extend([
            "--out_data",
            out_data
        ])
    if out_mix is not None:
        cargs.extend([
            "--out_mix",
            out_mix
        ])
    if out_vnscales is not None:
        cargs.extend([
            "--out_vnscales",
            out_vnscales
        ])
    ret = FslRegfiltOutputs(
        root=execution.output_file("."),
        filtered_data=execution.output_file(outfile + ".nii.gz"),
        preprocessed_data=execution.output_file(out_data + ".nii.gz") if (out_data is not None) else None,
        mixing_matrix=execution.output_file(out_mix + ".nii.gz") if (out_mix is not None) else None,
        vnscales=execution.output_file(out_vnscales + ".nii.gz") if (out_vnscales is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "FSL_REGFILT_METADATA",
    "FslRegfiltOutputs",
    "fsl_regfilt",
]
