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

import typing
import pathlib
from styxdefs import *
import dataclasses

ASL_MFREE_METADATA = Metadata(
    id="3df5c70b713c669c2cd52fa754362efc300e770e.boutiques",
    name="asl_mfree",
    package="fsl",
    container_image_tag="mcin/fsl:6.0.5",
)


class AslMfreeOutputs(typing.NamedTuple):
    """
    Output object returned when calling `asl_mfree(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    result_file: OutputPathType
    """Output results from ASL model-free analysis"""
    bat_img: OutputPathType
    """Estimated tissue BAT image file"""


def asl_mfree(
    datafile: InputPathType,
    mask: InputPathType,
    out: str,
    aif: InputPathType,
    dt: float,
    metric: InputPathType | None = None,
    mthresh: float | None = None,
    tcorrect: bool = False,
    bata: InputPathType | None = None,
    batt: InputPathType | None = None,
    bat: bool = False,
    bat_grad_thr: float | None = 0.2,
    t1: float | None = None,
    fa: float | None = None,
    std: bool = False,
    nwb: float | None = None,
    turbo_quasar: bool = False,
    shift_factor: float | None = 1,
    runner: Runner | None = None,
) -> AslMfreeOutputs:
    """
    ASL model-free analysis tool.
    
    Author: FMRIB Centre, University of Oxford
    
    Args:
        datafile: ASL data file.
        mask: Mask file.
        out: Output directory name.
        aif: Arterial input functions for deconvolution (4D volume, one aif for\
            each voxel within mask).
        dt: Temporal spacing in data (s).
        metric: Metric image file (optional).
        mthresh: Metric threshold (optional).
        tcorrect: Apply correction for timing difference between AIF and tissue\
            curve (optional).
        bata: Arterial BAT image (optional).
        batt: Tissue BAT image (optional).
        bat: Estimate tissue BAT from data and save this image (optional).
        bat_grad_thr: Edge detection gradient threshold (default: 0.2,\
            optional).
        t1: T1 (of blood) value (optional).
        fa: Flip angle (if using LL readout, optional).
        std: Calculate standard deviations on perfusion values using wild\
            bootstrapping (optional).
        nwb: Number of permutations for wild bootstrapping (optional).
        turbo_quasar: Specify this is a Turbo QUASAR Sequence (optional).
        shift_factor: Slice shifting factor in Turbo QUASAR (default value: 1,\
            optional).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AslMfreeOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(ASL_MFREE_METADATA)
    cargs = []
    cargs.append("asl_mfree")
    cargs.extend([
        "--data",
        execution.input_file(datafile)
    ])
    cargs.extend([
        "--mask",
        execution.input_file(mask)
    ])
    cargs.extend([
        "--out",
        out
    ])
    cargs.extend([
        "--aif",
        execution.input_file(aif)
    ])
    cargs.extend([
        "--dt",
        str(dt)
    ])
    if metric is not None:
        cargs.extend([
            "--metric",
            execution.input_file(metric)
        ])
    if mthresh is not None:
        cargs.extend([
            "--mthresh",
            str(mthresh)
        ])
    if tcorrect:
        cargs.append("--tcorrect")
    if bata is not None:
        cargs.extend([
            "--bata",
            execution.input_file(bata)
        ])
    if batt is not None:
        cargs.extend([
            "--batt",
            execution.input_file(batt)
        ])
    if bat:
        cargs.append("--bat")
    if bat_grad_thr is not None:
        cargs.extend([
            "--bat_grad_thr",
            str(bat_grad_thr)
        ])
    if t1 is not None:
        cargs.extend([
            "--t1",
            str(t1)
        ])
    if fa is not None:
        cargs.extend([
            "--fa",
            str(fa)
        ])
    if std:
        cargs.append("--std")
    if nwb is not None:
        cargs.extend([
            "--nwb",
            str(nwb)
        ])
    if turbo_quasar:
        cargs.append("--turbo_quasar")
    if shift_factor is not None:
        cargs.extend([
            "--shift_factor",
            str(shift_factor)
        ])
    cargs.append("--verbose")
    ret = AslMfreeOutputs(
        root=execution.output_file("."),
        result_file=execution.output_file(out + "/results.nii.gz"),
        bat_img=execution.output_file(out + "/bat.nii.gz"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "ASL_MFREE_METADATA",
    "AslMfreeOutputs",
    "asl_mfree",
]
