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

import typing
import pathlib
from styxdefs import *

DWI2RESPONSE_METADATA = Metadata(
    id="a5bba2228d610c2212f7a54e18b1cd513bb93b58.boutiques",
    name="dwi2response",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_Dwi2responseDhollanderParamsDictNoTag = typing.TypedDict('_Dwi2responseDhollanderParamsDictNoTag', {
    "input": InputPathType,
    "out_sfwm": str,
    "out_gm": str,
    "out_csf": str,
    "erode": typing.NotRequired[int | None],
    "fa": typing.NotRequired[float | None],
    "sfwm": typing.NotRequired[float | None],
    "gm": typing.NotRequired[float | None],
    "csf": typing.NotRequired[float | None],
    "wm_algo": typing.NotRequired[typing.Literal["fa", "tax", "tournier"] | None],
})
Dwi2responseDhollanderParamsDictTagged = typing.TypedDict('Dwi2responseDhollanderParamsDictTagged', {
    "@type": typing.Literal["dhollander"],
    "input": InputPathType,
    "out_sfwm": str,
    "out_gm": str,
    "out_csf": str,
    "erode": typing.NotRequired[int | None],
    "fa": typing.NotRequired[float | None],
    "sfwm": typing.NotRequired[float | None],
    "gm": typing.NotRequired[float | None],
    "csf": typing.NotRequired[float | None],
    "wm_algo": typing.NotRequired[typing.Literal["fa", "tax", "tournier"] | None],
})
Dwi2responseDhollanderParamsDict = _Dwi2responseDhollanderParamsDictNoTag | Dwi2responseDhollanderParamsDictTagged


_Dwi2responseFaParamsDictNoTag = typing.TypedDict('_Dwi2responseFaParamsDictNoTag', {
    "input": InputPathType,
    "output": str,
    "erode": typing.NotRequired[int | None],
    "number": typing.NotRequired[int | None],
    "threshold": typing.NotRequired[float | None],
})
Dwi2responseFaParamsDictTagged = typing.TypedDict('Dwi2responseFaParamsDictTagged', {
    "@type": typing.Literal["fa"],
    "input": InputPathType,
    "output": str,
    "erode": typing.NotRequired[int | None],
    "number": typing.NotRequired[int | None],
    "threshold": typing.NotRequired[float | None],
})
Dwi2responseFaParamsDict = _Dwi2responseFaParamsDictNoTag | Dwi2responseFaParamsDictTagged


_Dwi2responseManualParamsDictNoTag = typing.TypedDict('_Dwi2responseManualParamsDictNoTag', {
    "input": InputPathType,
    "in_voxels": InputPathType,
    "output": str,
    "dirs": typing.NotRequired[InputPathType | None],
})
Dwi2responseManualParamsDictTagged = typing.TypedDict('Dwi2responseManualParamsDictTagged', {
    "@type": typing.Literal["manual"],
    "input": InputPathType,
    "in_voxels": InputPathType,
    "output": str,
    "dirs": typing.NotRequired[InputPathType | None],
})
Dwi2responseManualParamsDict = _Dwi2responseManualParamsDictNoTag | Dwi2responseManualParamsDictTagged


_Dwi2responseMsmt5ttParamsDictNoTag = typing.TypedDict('_Dwi2responseMsmt5ttParamsDictNoTag', {
    "input": InputPathType,
    "in_5tt": InputPathType,
    "out_wm": str,
    "out_gm": str,
    "out_csf": str,
    "dirs": typing.NotRequired[InputPathType | None],
    "fa": typing.NotRequired[float | None],
    "pvf": typing.NotRequired[float | None],
    "wm_algo": typing.NotRequired[typing.Literal["fa", "tax", "tournier"] | None],
    "sfwm_fa_threshold": typing.NotRequired[float | None],
})
Dwi2responseMsmt5ttParamsDictTagged = typing.TypedDict('Dwi2responseMsmt5ttParamsDictTagged', {
    "@type": typing.Literal["msmt_5tt"],
    "input": InputPathType,
    "in_5tt": InputPathType,
    "out_wm": str,
    "out_gm": str,
    "out_csf": str,
    "dirs": typing.NotRequired[InputPathType | None],
    "fa": typing.NotRequired[float | None],
    "pvf": typing.NotRequired[float | None],
    "wm_algo": typing.NotRequired[typing.Literal["fa", "tax", "tournier"] | None],
    "sfwm_fa_threshold": typing.NotRequired[float | None],
})
Dwi2responseMsmt5ttParamsDict = _Dwi2responseMsmt5ttParamsDictNoTag | Dwi2responseMsmt5ttParamsDictTagged


_Dwi2responseTaxParamsDictNoTag = typing.TypedDict('_Dwi2responseTaxParamsDictNoTag', {
    "input": InputPathType,
    "output": str,
    "peak_ratio": typing.NotRequired[float | None],
    "max_iters": typing.NotRequired[int | None],
    "convergence": typing.NotRequired[float | None],
})
Dwi2responseTaxParamsDictTagged = typing.TypedDict('Dwi2responseTaxParamsDictTagged', {
    "@type": typing.Literal["tax"],
    "input": InputPathType,
    "output": str,
    "peak_ratio": typing.NotRequired[float | None],
    "max_iters": typing.NotRequired[int | None],
    "convergence": typing.NotRequired[float | None],
})
Dwi2responseTaxParamsDict = _Dwi2responseTaxParamsDictNoTag | Dwi2responseTaxParamsDictTagged


_Dwi2responseTournierParamsDictNoTag = typing.TypedDict('_Dwi2responseTournierParamsDictNoTag', {
    "input": InputPathType,
    "output": str,
    "number": typing.NotRequired[int | None],
    "iter_voxels": typing.NotRequired[int | None],
    "dilate": typing.NotRequired[int | None],
    "max_iters": typing.NotRequired[int | None],
})
Dwi2responseTournierParamsDictTagged = typing.TypedDict('Dwi2responseTournierParamsDictTagged', {
    "@type": typing.Literal["tournier"],
    "input": InputPathType,
    "output": str,
    "number": typing.NotRequired[int | None],
    "iter_voxels": typing.NotRequired[int | None],
    "dilate": typing.NotRequired[int | None],
    "max_iters": typing.NotRequired[int | None],
})
Dwi2responseTournierParamsDict = _Dwi2responseTournierParamsDictNoTag | Dwi2responseTournierParamsDictTagged


_Dwi2responseFslgradParamsDictNoTag = typing.TypedDict('_Dwi2responseFslgradParamsDictNoTag', {
    "bvecs": InputPathType,
    "bvals": InputPathType,
})
Dwi2responseFslgradParamsDictTagged = typing.TypedDict('Dwi2responseFslgradParamsDictTagged', {
    "@type": typing.Literal["fslgrad"],
    "bvecs": InputPathType,
    "bvals": InputPathType,
})
Dwi2responseFslgradParamsDict = _Dwi2responseFslgradParamsDictNoTag | Dwi2responseFslgradParamsDictTagged


_Dwi2responseConfigParamsDictNoTag = typing.TypedDict('_Dwi2responseConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
Dwi2responseConfigParamsDictTagged = typing.TypedDict('Dwi2responseConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
Dwi2responseConfigParamsDict = _Dwi2responseConfigParamsDictNoTag | Dwi2responseConfigParamsDictTagged


_Dwi2responseParamsDictNoTag = typing.TypedDict('_Dwi2responseParamsDictNoTag', {
    "algorithm": typing.Union[Dwi2responseDhollanderParamsDictTagged, Dwi2responseFaParamsDictTagged, Dwi2responseManualParamsDictTagged, Dwi2responseMsmt5ttParamsDictTagged, Dwi2responseTaxParamsDictTagged, Dwi2responseTournierParamsDictTagged],
    "grad": typing.NotRequired[InputPathType | None],
    "fslgrad": typing.NotRequired[Dwi2responseFslgradParamsDict | None],
    "mask": typing.NotRequired[InputPathType | None],
    "voxels": typing.NotRequired[str | None],
    "shells": typing.NotRequired[list[int] | None],
    "lmax": typing.NotRequired[list[int] | None],
    "nocleanup": bool,
    "scratch": typing.NotRequired[str | None],
    "continue": typing.NotRequired[str | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[Dwi2responseConfigParamsDict] | None],
    "help": bool,
    "version": bool,
})
Dwi2responseParamsDictTagged = typing.TypedDict('Dwi2responseParamsDictTagged', {
    "@type": typing.Literal["mrtrix/dwi2response"],
    "algorithm": typing.Union[Dwi2responseDhollanderParamsDictTagged, Dwi2responseFaParamsDictTagged, Dwi2responseManualParamsDictTagged, Dwi2responseMsmt5ttParamsDictTagged, Dwi2responseTaxParamsDictTagged, Dwi2responseTournierParamsDictTagged],
    "grad": typing.NotRequired[InputPathType | None],
    "fslgrad": typing.NotRequired[Dwi2responseFslgradParamsDict | None],
    "mask": typing.NotRequired[InputPathType | None],
    "voxels": typing.NotRequired[str | None],
    "shells": typing.NotRequired[list[int] | None],
    "lmax": typing.NotRequired[list[int] | None],
    "nocleanup": bool,
    "scratch": typing.NotRequired[str | None],
    "continue": typing.NotRequired[str | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[Dwi2responseConfigParamsDict] | None],
    "help": bool,
    "version": bool,
})
Dwi2responseParamsDict = _Dwi2responseParamsDictNoTag | Dwi2responseParamsDictTagged


def dwi2response_algorithm_cargs_dyn_fn(
    t: str,
) -> typing.Any:
    """
    Get build cargs function by command type.
    
    Args:
        t: Command type.
    Returns:
        Build cargs function.
    """
    return {
        "dhollander": dwi2response_dhollander_cargs,
        "fa": dwi2response_fa_cargs,
        "manual": dwi2response_manual_cargs,
        "msmt_5tt": dwi2response_msmt_5tt_cargs,
        "tax": dwi2response_tax_cargs,
        "tournier": dwi2response_tournier_cargs,
    }.get(t)


def dwi2response_algorithm_outputs_dyn_fn(
    t: str,
) -> typing.Any:
    """
    Get build outputs function by command type.
    
    Args:
        t: Command type.
    Returns:
        Build outputs function.
    """
    return {
        "dhollander": dwi2response_dhollander_outputs,
        "fa": dwi2response_fa_outputs,
        "manual": dwi2response_manual_outputs,
        "msmt_5tt": dwi2response_msmt_5tt_outputs,
        "tax": dwi2response_tax_outputs,
        "tournier": dwi2response_tournier_outputs,
    }.get(t)


def dwi2response_algorithm_validate_dyn_fn(
    t: str,
) -> typing.Any:
    """
    Get validate params function by command type.
    
    Args:
        t: Command type.
    Returns:
        Validate params function.
    """
    return {
        "dhollander": dwi2response_dhollander_validate,
        "fa": dwi2response_fa_validate,
        "manual": dwi2response_manual_validate,
        "msmt_5tt": dwi2response_msmt_5tt_validate,
        "tax": dwi2response_tax_validate,
        "tournier": dwi2response_tournier_validate,
    }.get(t)


class Dwi2responseDhollanderOutputs(typing.NamedTuple):
    """
    Output object returned when calling `Dwi2responseDhollanderParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    out_sfwm: OutputPathType
    """Output single-fibre WM response function text file"""
    out_gm: OutputPathType
    """Output GM response function text file"""
    out_csf: OutputPathType
    """Output CSF response function text file"""


def dwi2response_dhollander(
    input_: InputPathType,
    out_sfwm: str,
    out_gm: str,
    out_csf: str,
    erode: int | None = None,
    fa: float | None = None,
    sfwm: float | None = None,
    gm: float | None = None,
    csf: float | None = None,
    wm_algo: typing.Literal["fa", "tax", "tournier"] | None = None,
) -> Dwi2responseDhollanderParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: Input DWI dataset.
        out_sfwm: Output single-fibre WM response function text file.
        out_gm: Output GM response function text file.
        out_csf: Output CSF response function text file.
        erode: Number of erosion passes to apply to initial (whole brain) mask.\
            Set to 0 to not erode the brain mask. (default: 3).
        fa: FA threshold for crude WM versus GM-CSF separation. (default: 0.2).
        sfwm: Final number of single-fibre WM voxels to select, as a percentage\
            of refined WM. (default: 0.5 per cent).
        gm: Final number of GM voxels to select, as a percentage of refined GM.\
            (default: 2 per cent).
        csf: Final number of CSF voxels to select, as a percentage of refined\
            CSF. (default: 10 per cent).
        wm_algo: Use external dwi2response algorithm for WM single-fibre voxel\
            selection (options: fa, tax, tournier) (default: built-in Dhollander\
            2019).
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "dhollander",
        "input": input_,
        "out_sfwm": out_sfwm,
        "out_gm": out_gm,
        "out_csf": out_csf,
    }
    if erode is not None:
        params["erode"] = erode
    if fa is not None:
        params["fa"] = fa
    if sfwm is not None:
        params["sfwm"] = sfwm
    if gm is not None:
        params["gm"] = gm
    if csf is not None:
        params["csf"] = csf
    if wm_algo is not None:
        params["wm_algo"] = wm_algo
    return params


def dwi2response_dhollander_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Dwi2responseDhollanderParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("input", None) is None:
        raise StyxValidationError("`input` must not be None")
    if not isinstance(params["input"], (pathlib.Path, str)):
        raise StyxValidationError(f'`input` has the wrong type: Received `{type(params.get("input", None))}` expected `InputPathType`')
    if params.get("out_sfwm", None) is None:
        raise StyxValidationError("`out_sfwm` must not be None")
    if not isinstance(params["out_sfwm"], str):
        raise StyxValidationError(f'`out_sfwm` has the wrong type: Received `{type(params.get("out_sfwm", None))}` expected `str`')
    if params.get("out_gm", None) is None:
        raise StyxValidationError("`out_gm` must not be None")
    if not isinstance(params["out_gm"], str):
        raise StyxValidationError(f'`out_gm` has the wrong type: Received `{type(params.get("out_gm", None))}` expected `str`')
    if params.get("out_csf", None) is None:
        raise StyxValidationError("`out_csf` must not be None")
    if not isinstance(params["out_csf"], str):
        raise StyxValidationError(f'`out_csf` has the wrong type: Received `{type(params.get("out_csf", None))}` expected `str`')
    if params.get("erode", None) is not None:
        if not isinstance(params["erode"], int):
            raise StyxValidationError(f'`erode` has the wrong type: Received `{type(params.get("erode", None))}` expected `int | None`')
    if params.get("fa", None) is not None:
        if not isinstance(params["fa"], (float, int)):
            raise StyxValidationError(f'`fa` has the wrong type: Received `{type(params.get("fa", None))}` expected `float | None`')
    if params.get("sfwm", None) is not None:
        if not isinstance(params["sfwm"], (float, int)):
            raise StyxValidationError(f'`sfwm` has the wrong type: Received `{type(params.get("sfwm", None))}` expected `float | None`')
    if params.get("gm", None) is not None:
        if not isinstance(params["gm"], (float, int)):
            raise StyxValidationError(f'`gm` has the wrong type: Received `{type(params.get("gm", None))}` expected `float | None`')
    if params.get("csf", None) is not None:
        if not isinstance(params["csf"], (float, int)):
            raise StyxValidationError(f'`csf` has the wrong type: Received `{type(params.get("csf", None))}` expected `float | None`')
    if params.get("wm_algo", None) is not None:
        if not isinstance(params["wm_algo"], str):
            raise StyxValidationError(f'`wm_algo` has the wrong type: Received `{type(params.get("wm_algo", None))}` expected `typing.Literal["fa", "tax", "tournier"] | None`')
        if params["wm_algo"] not in ["fa", "tax", "tournier"]:
            raise StyxValidationError("Parameter `wm_algo` must be one of [\"fa\", \"tax\", \"tournier\"]")


def dwi2response_dhollander_cargs(
    params: Dwi2responseDhollanderParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("dhollander")
    cargs.append(execution.input_file(params.get("input", None)))
    cargs.append(params.get("out_sfwm", None))
    cargs.append(params.get("out_gm", None))
    cargs.append(params.get("out_csf", None))
    if params.get("erode", None) is not None:
        cargs.extend([
            "-erode",
            str(params.get("erode", None))
        ])
    if params.get("fa", None) is not None:
        cargs.extend([
            "-fa",
            str(params.get("fa", None))
        ])
    if params.get("sfwm", None) is not None:
        cargs.extend([
            "-sfwm",
            str(params.get("sfwm", None))
        ])
    if params.get("gm", None) is not None:
        cargs.extend([
            "-gm",
            str(params.get("gm", None))
        ])
    if params.get("csf", None) is not None:
        cargs.extend([
            "-csf",
            str(params.get("csf", None))
        ])
    if params.get("wm_algo", None) is not None:
        cargs.extend([
            "-wm_algo",
            params.get("wm_algo", None)
        ])
    return cargs


def dwi2response_dhollander_outputs(
    params: Dwi2responseDhollanderParamsDict,
    execution: Execution,
) -> Dwi2responseDhollanderOutputs:
    """
    Build outputs object containing output file paths and possibly stdout/stderr.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Outputs object.
    """
    ret = Dwi2responseDhollanderOutputs(
        root=execution.output_file("."),
        out_sfwm=execution.output_file(params.get("out_sfwm", None)),
        out_gm=execution.output_file(params.get("out_gm", None)),
        out_csf=execution.output_file(params.get("out_csf", None)),
    )
    return ret


class Dwi2responseFaOutputs(typing.NamedTuple):
    """
    Output object returned when calling `Dwi2responseFaParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """The output response function text file"""


def dwi2response_fa(
    input_: InputPathType,
    output: str,
    erode: int | None = None,
    number: int | None = None,
    threshold: float | None = None,
) -> Dwi2responseFaParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: The input DWI.
        output: The output response function text file.
        erode: Number of brain mask erosion steps to apply prior to threshold\
            (not used if mask is provided manually).
        number: The number of highest-FA voxels to use.
        threshold: Apply a hard FA threshold, rather than selecting the top\
            voxels.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "fa",
        "input": input_,
        "output": output,
    }
    if erode is not None:
        params["erode"] = erode
    if number is not None:
        params["number"] = number
    if threshold is not None:
        params["threshold"] = threshold
    return params


def dwi2response_fa_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Dwi2responseFaParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("input", None) is None:
        raise StyxValidationError("`input` must not be None")
    if not isinstance(params["input"], (pathlib.Path, str)):
        raise StyxValidationError(f'`input` has the wrong type: Received `{type(params.get("input", None))}` expected `InputPathType`')
    if params.get("output", None) is None:
        raise StyxValidationError("`output` must not be None")
    if not isinstance(params["output"], str):
        raise StyxValidationError(f'`output` has the wrong type: Received `{type(params.get("output", None))}` expected `str`')
    if params.get("erode", None) is not None:
        if not isinstance(params["erode"], int):
            raise StyxValidationError(f'`erode` has the wrong type: Received `{type(params.get("erode", None))}` expected `int | None`')
    if params.get("number", None) is not None:
        if not isinstance(params["number"], int):
            raise StyxValidationError(f'`number` has the wrong type: Received `{type(params.get("number", None))}` expected `int | None`')
    if params.get("threshold", None) is not None:
        if not isinstance(params["threshold"], (float, int)):
            raise StyxValidationError(f'`threshold` has the wrong type: Received `{type(params.get("threshold", None))}` expected `float | None`')


def dwi2response_fa_cargs(
    params: Dwi2responseFaParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("fa")
    cargs.append(execution.input_file(params.get("input", None)))
    cargs.append(params.get("output", None))
    if params.get("erode", None) is not None:
        cargs.extend([
            "-erode",
            str(params.get("erode", None))
        ])
    if params.get("number", None) is not None:
        cargs.extend([
            "-number",
            str(params.get("number", None))
        ])
    if params.get("threshold", None) is not None:
        cargs.extend([
            "-threshold",
            str(params.get("threshold", None))
        ])
    return cargs


def dwi2response_fa_outputs(
    params: Dwi2responseFaParamsDict,
    execution: Execution,
) -> Dwi2responseFaOutputs:
    """
    Build outputs object containing output file paths and possibly stdout/stderr.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Outputs object.
    """
    ret = Dwi2responseFaOutputs(
        root=execution.output_file("."),
        output=execution.output_file(params.get("output", None)),
    )
    return ret


class Dwi2responseManualOutputs(typing.NamedTuple):
    """
    Output object returned when calling `Dwi2responseManualParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """Output response function text file"""


def dwi2response_manual(
    input_: InputPathType,
    in_voxels: InputPathType,
    output: str,
    dirs: InputPathType | None = None,
) -> Dwi2responseManualParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: The input DWI.
        in_voxels: Input voxel selection mask.
        output: Output response function text file.
        dirs: Manually provide the fibre direction in each voxel (a tensor fit\
            will be used otherwise).
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "manual",
        "input": input_,
        "in_voxels": in_voxels,
        "output": output,
    }
    if dirs is not None:
        params["dirs"] = dirs
    return params


def dwi2response_manual_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Dwi2responseManualParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("input", None) is None:
        raise StyxValidationError("`input` must not be None")
    if not isinstance(params["input"], (pathlib.Path, str)):
        raise StyxValidationError(f'`input` has the wrong type: Received `{type(params.get("input", None))}` expected `InputPathType`')
    if params.get("in_voxels", None) is None:
        raise StyxValidationError("`in_voxels` must not be None")
    if not isinstance(params["in_voxels"], (pathlib.Path, str)):
        raise StyxValidationError(f'`in_voxels` has the wrong type: Received `{type(params.get("in_voxels", None))}` expected `InputPathType`')
    if params.get("output", None) is None:
        raise StyxValidationError("`output` must not be None")
    if not isinstance(params["output"], str):
        raise StyxValidationError(f'`output` has the wrong type: Received `{type(params.get("output", None))}` expected `str`')
    if params.get("dirs", None) is not None:
        if not isinstance(params["dirs"], (pathlib.Path, str)):
            raise StyxValidationError(f'`dirs` has the wrong type: Received `{type(params.get("dirs", None))}` expected `InputPathType | None`')


def dwi2response_manual_cargs(
    params: Dwi2responseManualParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("manual")
    cargs.append(execution.input_file(params.get("input", None)))
    cargs.append(execution.input_file(params.get("in_voxels", None)))
    cargs.append(params.get("output", None))
    if params.get("dirs", None) is not None:
        cargs.extend([
            "-dirs",
            execution.input_file(params.get("dirs", None))
        ])
    return cargs


def dwi2response_manual_outputs(
    params: Dwi2responseManualParamsDict,
    execution: Execution,
) -> Dwi2responseManualOutputs:
    """
    Build outputs object containing output file paths and possibly stdout/stderr.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Outputs object.
    """
    ret = Dwi2responseManualOutputs(
        root=execution.output_file("."),
        output=execution.output_file(params.get("output", None)),
    )
    return ret


class Dwi2responseMsmt5ttOutputs(typing.NamedTuple):
    """
    Output object returned when calling `Dwi2responseMsmt5ttParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    out_wm: OutputPathType
    """Output WM response text file"""
    out_gm: OutputPathType
    """Output GM response text file"""
    out_csf: OutputPathType
    """Output CSF response text file"""


def dwi2response_msmt_5tt(
    input_: InputPathType,
    in_5tt: InputPathType,
    out_wm: str,
    out_gm: str,
    out_csf: str,
    dirs: InputPathType | None = None,
    fa: float | None = None,
    pvf: float | None = None,
    wm_algo: typing.Literal["fa", "tax", "tournier"] | None = None,
    sfwm_fa_threshold: float | None = None,
) -> Dwi2responseMsmt5ttParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: The input DWI.
        in_5tt: Input co-registered 5TT image.
        out_wm: Output WM response text file.
        out_gm: Output GM response text file.
        out_csf: Output CSF response text file.
        dirs: Manually provide the fibre direction in each voxel (a tensor fit\
            will be used otherwise).
        fa: Upper fractional anisotropy threshold for GM and CSF voxel\
            selection (default: 0.2).
        pvf: Partial volume fraction threshold for tissue voxel selection\
            (default: 0.95).
        wm_algo: algorithm dwi2response algorithm to use for WM single-fibre\
            voxel selection (options: fa, tax, tournier; default: tournier).
        sfwm_fa_threshold: Sets -wm_algo to fa and allows to specify a hard FA\
            threshold for single-fibre WM voxels, which is passed to the -threshold\
            option of the fa algorithm (warning: overrides -wm_algo option).
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "msmt_5tt",
        "input": input_,
        "in_5tt": in_5tt,
        "out_wm": out_wm,
        "out_gm": out_gm,
        "out_csf": out_csf,
    }
    if dirs is not None:
        params["dirs"] = dirs
    if fa is not None:
        params["fa"] = fa
    if pvf is not None:
        params["pvf"] = pvf
    if wm_algo is not None:
        params["wm_algo"] = wm_algo
    if sfwm_fa_threshold is not None:
        params["sfwm_fa_threshold"] = sfwm_fa_threshold
    return params


def dwi2response_msmt_5tt_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Dwi2responseMsmt5ttParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("input", None) is None:
        raise StyxValidationError("`input` must not be None")
    if not isinstance(params["input"], (pathlib.Path, str)):
        raise StyxValidationError(f'`input` has the wrong type: Received `{type(params.get("input", None))}` expected `InputPathType`')
    if params.get("in_5tt", None) is None:
        raise StyxValidationError("`in_5tt` must not be None")
    if not isinstance(params["in_5tt"], (pathlib.Path, str)):
        raise StyxValidationError(f'`in_5tt` has the wrong type: Received `{type(params.get("in_5tt", None))}` expected `InputPathType`')
    if params.get("out_wm", None) is None:
        raise StyxValidationError("`out_wm` must not be None")
    if not isinstance(params["out_wm"], str):
        raise StyxValidationError(f'`out_wm` has the wrong type: Received `{type(params.get("out_wm", None))}` expected `str`')
    if params.get("out_gm", None) is None:
        raise StyxValidationError("`out_gm` must not be None")
    if not isinstance(params["out_gm"], str):
        raise StyxValidationError(f'`out_gm` has the wrong type: Received `{type(params.get("out_gm", None))}` expected `str`')
    if params.get("out_csf", None) is None:
        raise StyxValidationError("`out_csf` must not be None")
    if not isinstance(params["out_csf"], str):
        raise StyxValidationError(f'`out_csf` has the wrong type: Received `{type(params.get("out_csf", None))}` expected `str`')
    if params.get("dirs", None) is not None:
        if not isinstance(params["dirs"], (pathlib.Path, str)):
            raise StyxValidationError(f'`dirs` has the wrong type: Received `{type(params.get("dirs", None))}` expected `InputPathType | None`')
    if params.get("fa", None) is not None:
        if not isinstance(params["fa"], (float, int)):
            raise StyxValidationError(f'`fa` has the wrong type: Received `{type(params.get("fa", None))}` expected `float | None`')
    if params.get("pvf", None) is not None:
        if not isinstance(params["pvf"], (float, int)):
            raise StyxValidationError(f'`pvf` has the wrong type: Received `{type(params.get("pvf", None))}` expected `float | None`')
    if params.get("wm_algo", None) is not None:
        if not isinstance(params["wm_algo"], str):
            raise StyxValidationError(f'`wm_algo` has the wrong type: Received `{type(params.get("wm_algo", None))}` expected `typing.Literal["fa", "tax", "tournier"] | None`')
        if params["wm_algo"] not in ["fa", "tax", "tournier"]:
            raise StyxValidationError("Parameter `wm_algo` must be one of [\"fa\", \"tax\", \"tournier\"]")
    if params.get("sfwm_fa_threshold", None) is not None:
        if not isinstance(params["sfwm_fa_threshold"], (float, int)):
            raise StyxValidationError(f'`sfwm_fa_threshold` has the wrong type: Received `{type(params.get("sfwm_fa_threshold", None))}` expected `float | None`')


def dwi2response_msmt_5tt_cargs(
    params: Dwi2responseMsmt5ttParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("msmt_5tt")
    cargs.append(execution.input_file(params.get("input", None)))
    cargs.append(execution.input_file(params.get("in_5tt", None)))
    cargs.append(params.get("out_wm", None))
    cargs.append(params.get("out_gm", None))
    cargs.append(params.get("out_csf", None))
    if params.get("dirs", None) is not None:
        cargs.extend([
            "-dirs",
            execution.input_file(params.get("dirs", None))
        ])
    if params.get("fa", None) is not None:
        cargs.extend([
            "-fa",
            str(params.get("fa", None))
        ])
    if params.get("pvf", None) is not None:
        cargs.extend([
            "-pvf",
            str(params.get("pvf", None))
        ])
    if params.get("wm_algo", None) is not None:
        cargs.extend([
            "-wm_algo",
            params.get("wm_algo", None)
        ])
    if params.get("sfwm_fa_threshold", None) is not None:
        cargs.extend([
            "-sfwm_fa_threshold",
            str(params.get("sfwm_fa_threshold", None))
        ])
    return cargs


def dwi2response_msmt_5tt_outputs(
    params: Dwi2responseMsmt5ttParamsDict,
    execution: Execution,
) -> Dwi2responseMsmt5ttOutputs:
    """
    Build outputs object containing output file paths and possibly stdout/stderr.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Outputs object.
    """
    ret = Dwi2responseMsmt5ttOutputs(
        root=execution.output_file("."),
        out_wm=execution.output_file(params.get("out_wm", None)),
        out_gm=execution.output_file(params.get("out_gm", None)),
        out_csf=execution.output_file(params.get("out_csf", None)),
    )
    return ret


class Dwi2responseTaxOutputs(typing.NamedTuple):
    """
    Output object returned when calling `Dwi2responseTaxParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """The output response function text file"""


def dwi2response_tax(
    input_: InputPathType,
    output: str,
    peak_ratio: float | None = None,
    max_iters: int | None = None,
    convergence: float | None = None,
) -> Dwi2responseTaxParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: The input DWI.
        output: The output response function text file.
        peak_ratio: Second-to-first-peak amplitude ratio threshold.
        max_iters: Maximum number of iterations.
        convergence: Percentile change in any RF coefficient required to\
            continue iterating.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "tax",
        "input": input_,
        "output": output,
    }
    if peak_ratio is not None:
        params["peak_ratio"] = peak_ratio
    if max_iters is not None:
        params["max_iters"] = max_iters
    if convergence is not None:
        params["convergence"] = convergence
    return params


def dwi2response_tax_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Dwi2responseTaxParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("input", None) is None:
        raise StyxValidationError("`input` must not be None")
    if not isinstance(params["input"], (pathlib.Path, str)):
        raise StyxValidationError(f'`input` has the wrong type: Received `{type(params.get("input", None))}` expected `InputPathType`')
    if params.get("output", None) is None:
        raise StyxValidationError("`output` must not be None")
    if not isinstance(params["output"], str):
        raise StyxValidationError(f'`output` has the wrong type: Received `{type(params.get("output", None))}` expected `str`')
    if params.get("peak_ratio", None) is not None:
        if not isinstance(params["peak_ratio"], (float, int)):
            raise StyxValidationError(f'`peak_ratio` has the wrong type: Received `{type(params.get("peak_ratio", None))}` expected `float | None`')
    if params.get("max_iters", None) is not None:
        if not isinstance(params["max_iters"], int):
            raise StyxValidationError(f'`max_iters` has the wrong type: Received `{type(params.get("max_iters", None))}` expected `int | None`')
    if params.get("convergence", None) is not None:
        if not isinstance(params["convergence"], (float, int)):
            raise StyxValidationError(f'`convergence` has the wrong type: Received `{type(params.get("convergence", None))}` expected `float | None`')


def dwi2response_tax_cargs(
    params: Dwi2responseTaxParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("tax")
    cargs.append(execution.input_file(params.get("input", None)))
    cargs.append(params.get("output", None))
    if params.get("peak_ratio", None) is not None:
        cargs.extend([
            "-peak_ratio",
            str(params.get("peak_ratio", None))
        ])
    if params.get("max_iters", None) is not None:
        cargs.extend([
            "-max_iters",
            str(params.get("max_iters", None))
        ])
    if params.get("convergence", None) is not None:
        cargs.extend([
            "-convergence",
            str(params.get("convergence", None))
        ])
    return cargs


def dwi2response_tax_outputs(
    params: Dwi2responseTaxParamsDict,
    execution: Execution,
) -> Dwi2responseTaxOutputs:
    """
    Build outputs object containing output file paths and possibly stdout/stderr.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Outputs object.
    """
    ret = Dwi2responseTaxOutputs(
        root=execution.output_file("."),
        output=execution.output_file(params.get("output", None)),
    )
    return ret


class Dwi2responseTournierOutputs(typing.NamedTuple):
    """
    Output object returned when calling `Dwi2responseTournierParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """The output response function text file"""


def dwi2response_tournier(
    input_: InputPathType,
    output: str,
    number: int | None = None,
    iter_voxels: int | None = None,
    dilate: int | None = None,
    max_iters: int | None = None,
) -> Dwi2responseTournierParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: The input DWI.
        output: The output response function text file.
        number: Number of single-fibre voxels to use when calculating response\
            function.
        iter_voxels: Number of single-fibre voxels to select when preparing for\
            the next iteration (default = 10 x value given in -number).
        dilate: Number of mask dilation steps to apply when deriving voxel mask\
            to test in the next iteration.
        max_iters: Maximum number of iterations.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "tournier",
        "input": input_,
        "output": output,
    }
    if number is not None:
        params["number"] = number
    if iter_voxels is not None:
        params["iter_voxels"] = iter_voxels
    if dilate is not None:
        params["dilate"] = dilate
    if max_iters is not None:
        params["max_iters"] = max_iters
    return params


def dwi2response_tournier_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Dwi2responseTournierParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("input", None) is None:
        raise StyxValidationError("`input` must not be None")
    if not isinstance(params["input"], (pathlib.Path, str)):
        raise StyxValidationError(f'`input` has the wrong type: Received `{type(params.get("input", None))}` expected `InputPathType`')
    if params.get("output", None) is None:
        raise StyxValidationError("`output` must not be None")
    if not isinstance(params["output"], str):
        raise StyxValidationError(f'`output` has the wrong type: Received `{type(params.get("output", None))}` expected `str`')
    if params.get("number", None) is not None:
        if not isinstance(params["number"], int):
            raise StyxValidationError(f'`number` has the wrong type: Received `{type(params.get("number", None))}` expected `int | None`')
    if params.get("iter_voxels", None) is not None:
        if not isinstance(params["iter_voxels"], int):
            raise StyxValidationError(f'`iter_voxels` has the wrong type: Received `{type(params.get("iter_voxels", None))}` expected `int | None`')
    if params.get("dilate", None) is not None:
        if not isinstance(params["dilate"], int):
            raise StyxValidationError(f'`dilate` has the wrong type: Received `{type(params.get("dilate", None))}` expected `int | None`')
    if params.get("max_iters", None) is not None:
        if not isinstance(params["max_iters"], int):
            raise StyxValidationError(f'`max_iters` has the wrong type: Received `{type(params.get("max_iters", None))}` expected `int | None`')


def dwi2response_tournier_cargs(
    params: Dwi2responseTournierParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("tournier")
    cargs.append(execution.input_file(params.get("input", None)))
    cargs.append(params.get("output", None))
    if params.get("number", None) is not None:
        cargs.extend([
            "-number",
            str(params.get("number", None))
        ])
    if params.get("iter_voxels", None) is not None:
        cargs.extend([
            "-iter_voxels",
            str(params.get("iter_voxels", None))
        ])
    if params.get("dilate", None) is not None:
        cargs.extend([
            "-dilate",
            str(params.get("dilate", None))
        ])
    if params.get("max_iters", None) is not None:
        cargs.extend([
            "-max_iters",
            str(params.get("max_iters", None))
        ])
    return cargs


def dwi2response_tournier_outputs(
    params: Dwi2responseTournierParamsDict,
    execution: Execution,
) -> Dwi2responseTournierOutputs:
    """
    Build outputs object containing output file paths and possibly stdout/stderr.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Outputs object.
    """
    ret = Dwi2responseTournierOutputs(
        root=execution.output_file("."),
        output=execution.output_file(params.get("output", None)),
    )
    return ret


def dwi2response_fslgrad(
    bvecs: InputPathType,
    bvals: InputPathType,
) -> Dwi2responseFslgradParamsDictTagged:
    """
    Build parameters.
    
    Args:
        bvecs: Provide the diffusion-weighted gradient scheme used in the\
            acquisition in FSL bvecs/bvals format files. If a diffusion gradient\
            scheme is present in the input image header, the data provided with\
            this option will be instead used.
        bvals: Provide the diffusion-weighted gradient scheme used in the\
            acquisition in FSL bvecs/bvals format files. If a diffusion gradient\
            scheme is present in the input image header, the data provided with\
            this option will be instead used.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "fslgrad",
        "bvecs": bvecs,
        "bvals": bvals,
    }
    return params


def dwi2response_fslgrad_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Dwi2responseFslgradParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("bvecs", None) is None:
        raise StyxValidationError("`bvecs` must not be None")
    if not isinstance(params["bvecs"], (pathlib.Path, str)):
        raise StyxValidationError(f'`bvecs` has the wrong type: Received `{type(params.get("bvecs", None))}` expected `InputPathType`')
    if params.get("bvals", None) is None:
        raise StyxValidationError("`bvals` must not be None")
    if not isinstance(params["bvals"], (pathlib.Path, str)):
        raise StyxValidationError(f'`bvals` has the wrong type: Received `{type(params.get("bvals", None))}` expected `InputPathType`')


def dwi2response_fslgrad_cargs(
    params: Dwi2responseFslgradParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("-fslgrad")
    cargs.append(execution.input_file(params.get("bvecs", None)))
    cargs.append(execution.input_file(params.get("bvals", None)))
    return cargs


def dwi2response_config(
    key: str,
    value: str,
) -> Dwi2responseConfigParamsDictTagged:
    """
    Build parameters.
    
    Args:
        key: temporarily set the value of an MRtrix config file entry.
        value: temporarily set the value of an MRtrix config file entry.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "config",
        "key": key,
        "value": value,
    }
    return params


def dwi2response_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Dwi2responseConfigParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("key", None) is None:
        raise StyxValidationError("`key` must not be None")
    if not isinstance(params["key"], str):
        raise StyxValidationError(f'`key` has the wrong type: Received `{type(params.get("key", None))}` expected `str`')
    if params.get("value", None) is None:
        raise StyxValidationError("`value` must not be None")
    if not isinstance(params["value"], str):
        raise StyxValidationError(f'`value` has the wrong type: Received `{type(params.get("value", None))}` expected `str`')


def dwi2response_config_cargs(
    params: Dwi2responseConfigParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("-config")
    cargs.append(params.get("key", None))
    cargs.append(params.get("value", None))
    return cargs


class Dwi2responseOutputs(typing.NamedTuple):
    """
    Output object returned when calling `Dwi2responseParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    algorithm: typing.Union[Dwi2responseDhollanderOutputs, Dwi2responseFaOutputs, Dwi2responseManualOutputs, Dwi2responseMsmt5ttOutputs, Dwi2responseTaxOutputs, Dwi2responseTournierOutputs]
    """Outputs from `Dwi2responseDhollanderParamsDict` or
    `Dwi2responseFaParamsDict` or `Dwi2responseManualParamsDict` or
    `Dwi2responseMsmt5ttParamsDict` or `Dwi2responseTaxParamsDict` or
    `Dwi2responseTournierParamsDict`."""


def dwi2response_params(
    algorithm: typing.Union[Dwi2responseDhollanderParamsDictTagged, Dwi2responseFaParamsDictTagged, Dwi2responseManualParamsDictTagged, Dwi2responseMsmt5ttParamsDictTagged, Dwi2responseTaxParamsDictTagged, Dwi2responseTournierParamsDictTagged],
    grad: InputPathType | None = None,
    fslgrad: Dwi2responseFslgradParamsDict | None = None,
    mask: InputPathType | None = None,
    voxels: str | None = None,
    shells: list[int] | None = None,
    lmax: list[int] | None = None,
    nocleanup: bool = False,
    scratch: str | None = None,
    continue_: str | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[Dwi2responseConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> Dwi2responseParamsDictTagged:
    """
    Build parameters.
    
    Args:
        algorithm: Select the algorithm to be used to complete the script\
            operation; additional details and options become available once an\
            algorithm is nominated. Options are: dhollander, fa, manual, msmt_5tt,\
            tax, tournier.
        grad: Provide the diffusion gradient table in MRtrix format.
        fslgrad: Provide the diffusion gradient table in FSL bvecs/bvals format.
        mask: Only process voxels within the specified binary brain mask image.
        voxels: Output an image showing the final voxel selection(s).
        shells: b-value(s) to use in response function estimation\
            (comma-separated list in case of multiple b-values, b=0 must be\
            included explicitly).
        lmax: maximum harmonic degree(s) for response function estimation\
            (comma-separated list in case of multiple b-values).
        nocleanup: do not delete intermediate files during script execution,\
            and do not delete scratch directory at script completion.
        scratch: manually specify the path in which to generate the scratch\
            directory.
        continue_: continue the script from a previous execution; must provide\
            the scratch directory path, and the name of the last\
            successfully-generated file.
        info: display information messages.
        quiet: do not display information messages or progress status;\
            alternatively, this can be achieved by setting the MRTRIX_QUIET\
            environment variable to a non-empty string.
        debug: display debugging messages.
        force: force overwrite of output files (caution: using the same file as\
            input and output might cause unexpected behaviour).
        nthreads: use this number of threads in multi-threaded applications\
            (set to 0 to disable multi-threading).
        config: temporarily set the value of an MRtrix config file entry.
        help_: display this information page and exit.
        version: display version information and exit.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "mrtrix/dwi2response",
        "algorithm": algorithm,
        "nocleanup": nocleanup,
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
    }
    if grad is not None:
        params["grad"] = grad
    if fslgrad is not None:
        params["fslgrad"] = fslgrad
    if mask is not None:
        params["mask"] = mask
    if voxels is not None:
        params["voxels"] = voxels
    if shells is not None:
        params["shells"] = shells
    if lmax is not None:
        params["lmax"] = lmax
    if scratch is not None:
        params["scratch"] = scratch
    if continue_ is not None:
        params["continue"] = continue_
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    return params


def dwi2response_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Dwi2responseParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("algorithm", None) is None:
        raise StyxValidationError("`algorithm` must not be None")
    if not isinstance(params["algorithm"], dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params["algorithm"])}\'')
    if "@type" not in params["algorithm"]:
        raise StyxValidationError("Params object is missing `@type`")
    if params["algorithm"]["@type"] not in ["dhollander", "fa", "manual", "msmt_5tt", "tax", "tournier"]:
        raise StyxValidationError("Parameter `algorithm`s `@type` must be one of [\"dhollander\", \"fa\", \"manual\", \"msmt_5tt\", \"tax\", \"tournier\"]")
    dwi2response_algorithm_validate_dyn_fn(params["algorithm"]["@type"])(params["algorithm"])
    if params.get("grad", None) is not None:
        if not isinstance(params["grad"], (pathlib.Path, str)):
            raise StyxValidationError(f'`grad` has the wrong type: Received `{type(params.get("grad", None))}` expected `InputPathType | None`')
    if params.get("fslgrad", None) is not None:
        dwi2response_fslgrad_validate(params["fslgrad"])
    if params.get("mask", None) is not None:
        if not isinstance(params["mask"], (pathlib.Path, str)):
            raise StyxValidationError(f'`mask` has the wrong type: Received `{type(params.get("mask", None))}` expected `InputPathType | None`')
    if params.get("voxels", None) is not None:
        if not isinstance(params["voxels"], str):
            raise StyxValidationError(f'`voxels` has the wrong type: Received `{type(params.get("voxels", None))}` expected `str | None`')
    if params.get("shells", None) is not None:
        if not isinstance(params["shells"], list):
            raise StyxValidationError(f'`shells` has the wrong type: Received `{type(params.get("shells", None))}` expected `list[int] | None`')
        for e in params["shells"]:
            if not isinstance(e, int):
                raise StyxValidationError(f'`shells` has the wrong type: Received `{type(params.get("shells", None))}` expected `list[int] | None`')
    if params.get("lmax", None) is not None:
        if not isinstance(params["lmax"], list):
            raise StyxValidationError(f'`lmax` has the wrong type: Received `{type(params.get("lmax", None))}` expected `list[int] | None`')
        for e in params["lmax"]:
            if not isinstance(e, int):
                raise StyxValidationError(f'`lmax` has the wrong type: Received `{type(params.get("lmax", None))}` expected `list[int] | None`')
    if params.get("nocleanup", False) is None:
        raise StyxValidationError("`nocleanup` must not be None")
    if not isinstance(params["nocleanup"], bool):
        raise StyxValidationError(f'`nocleanup` has the wrong type: Received `{type(params.get("nocleanup", False))}` expected `bool`')
    if params.get("scratch", None) is not None:
        if not isinstance(params["scratch"], str):
            raise StyxValidationError(f'`scratch` has the wrong type: Received `{type(params.get("scratch", None))}` expected `str | None`')
    if params.get("continue", None) is not None:
        if not isinstance(params["continue"], str):
            raise StyxValidationError(f'`continue` has the wrong type: Received `{type(params.get("continue", None))}` expected `str | None`')
    if params.get("info", False) is None:
        raise StyxValidationError("`info` must not be None")
    if not isinstance(params["info"], bool):
        raise StyxValidationError(f'`info` has the wrong type: Received `{type(params.get("info", False))}` expected `bool`')
    if params.get("quiet", False) is None:
        raise StyxValidationError("`quiet` must not be None")
    if not isinstance(params["quiet"], bool):
        raise StyxValidationError(f'`quiet` has the wrong type: Received `{type(params.get("quiet", False))}` expected `bool`')
    if params.get("debug", False) is None:
        raise StyxValidationError("`debug` must not be None")
    if not isinstance(params["debug"], bool):
        raise StyxValidationError(f'`debug` has the wrong type: Received `{type(params.get("debug", False))}` expected `bool`')
    if params.get("force", False) is None:
        raise StyxValidationError("`force` must not be None")
    if not isinstance(params["force"], bool):
        raise StyxValidationError(f'`force` has the wrong type: Received `{type(params.get("force", False))}` expected `bool`')
    if params.get("nthreads", None) is not None:
        if not isinstance(params["nthreads"], int):
            raise StyxValidationError(f'`nthreads` has the wrong type: Received `{type(params.get("nthreads", None))}` expected `int | None`')
    if params.get("config", None) is not None:
        if not isinstance(params["config"], list):
            raise StyxValidationError(f'`config` has the wrong type: Received `{type(params.get("config", None))}` expected `list[Dwi2responseConfigParamsDict] | None`')
        for e in params["config"]:
            dwi2response_config_validate(e)
    if params.get("help", False) is None:
        raise StyxValidationError("`help` must not be None")
    if not isinstance(params["help"], bool):
        raise StyxValidationError(f'`help` has the wrong type: Received `{type(params.get("help", False))}` expected `bool`')
    if params.get("version", False) is None:
        raise StyxValidationError("`version` must not be None")
    if not isinstance(params["version"], bool):
        raise StyxValidationError(f'`version` has the wrong type: Received `{type(params.get("version", False))}` expected `bool`')


def dwi2response_cargs(
    params: Dwi2responseParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("dwi2response")
    cargs.extend(dwi2response_algorithm_cargs_dyn_fn(params.get("algorithm", None)["@type"])(params.get("algorithm", None), execution))
    if params.get("grad", None) is not None:
        cargs.extend([
            "-grad",
            execution.input_file(params.get("grad", None))
        ])
    if params.get("fslgrad", None) is not None:
        cargs.extend(dwi2response_fslgrad_cargs(params.get("fslgrad", None), execution))
    if params.get("mask", None) is not None:
        cargs.extend([
            "-mask",
            execution.input_file(params.get("mask", None))
        ])
    if params.get("voxels", None) is not None:
        cargs.extend([
            "-voxels",
            params.get("voxels", None)
        ])
    if params.get("shells", None) is not None:
        cargs.extend([
            "-shells",
            ",".join(map(str, params.get("shells", None)))
        ])
    if params.get("lmax", None) is not None:
        cargs.extend([
            "-lmax",
            ",".join(map(str, params.get("lmax", None)))
        ])
    if params.get("nocleanup", False):
        cargs.append("-nocleanup")
    if params.get("scratch", None) is not None:
        cargs.extend([
            "-scratch",
            params.get("scratch", None)
        ])
    if params.get("continue", None) is not None:
        cargs.extend([
            "-continue",
            params.get("continue", None)
        ])
    if params.get("info", False):
        cargs.append("-info")
    if params.get("quiet", False):
        cargs.append("-quiet")
    if params.get("debug", False):
        cargs.append("-debug")
    if params.get("force", False):
        cargs.append("-force")
    if params.get("nthreads", None) is not None:
        cargs.extend([
            "-nthreads",
            str(params.get("nthreads", None))
        ])
    if params.get("config", None) is not None:
        cargs.extend([a for c in [dwi2response_config_cargs(s, execution) for s in params.get("config", None)] for a in c])
    if params.get("help", False):
        cargs.append("-help")
    if params.get("version", False):
        cargs.append("-version")
    return cargs


def dwi2response_outputs(
    params: Dwi2responseParamsDict,
    execution: Execution,
) -> Dwi2responseOutputs:
    """
    Build outputs object containing output file paths and possibly stdout/stderr.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Outputs object.
    """
    ret = Dwi2responseOutputs(
        root=execution.output_file("."),
        algorithm=dwi2response_algorithm_outputs_dyn_fn(params.get("algorithm")["@type"])(params.get("algorithm"), execution),
    )
    return ret


def dwi2response_execute(
    params: Dwi2responseParamsDict,
    runner: Runner | None = None,
) -> Dwi2responseOutputs:
    """
    dwi2response
    
    Estimate response function(s) for spherical deconvolution.
    dwi2response offers different algorithms for performing various types of
    response function estimation. The name of the algorithm must appear as the
    first argument on the command-line after â€˜dwi2responseâ€™. The subsequent
    arguments and options depend on the particular algorithm being invoked.
    Each algorithm available has its own help page, including necessary
    references; e.g. to see the help page of the 'fa' algorithm, type
    'dwi2response fa'.
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `Dwi2responseOutputs`).
    """
    dwi2response_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(DWI2RESPONSE_METADATA)
    params = execution.params(params)
    cargs = dwi2response_cargs(params, execution)
    ret = dwi2response_outputs(params, execution)
    execution.run(cargs)
    return ret


def dwi2response(
    algorithm: typing.Union[Dwi2responseDhollanderParamsDictTagged, Dwi2responseFaParamsDictTagged, Dwi2responseManualParamsDictTagged, Dwi2responseMsmt5ttParamsDictTagged, Dwi2responseTaxParamsDictTagged, Dwi2responseTournierParamsDictTagged],
    grad: InputPathType | None = None,
    fslgrad: Dwi2responseFslgradParamsDict | None = None,
    mask: InputPathType | None = None,
    voxels: str | None = None,
    shells: list[int] | None = None,
    lmax: list[int] | None = None,
    nocleanup: bool = False,
    scratch: str | None = None,
    continue_: str | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[Dwi2responseConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> Dwi2responseOutputs:
    """
    dwi2response
    
    Estimate response function(s) for spherical deconvolution.
    dwi2response offers different algorithms for performing various types of
    response function estimation. The name of the algorithm must appear as the
    first argument on the command-line after â€˜dwi2responseâ€™. The subsequent
    arguments and options depend on the particular algorithm being invoked.
    Each algorithm available has its own help page, including necessary
    references; e.g. to see the help page of the 'fa' algorithm, type
    'dwi2response fa'.
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        algorithm: Select the algorithm to be used to complete the script\
            operation; additional details and options become available once an\
            algorithm is nominated. Options are: dhollander, fa, manual, msmt_5tt,\
            tax, tournier.
        grad: Provide the diffusion gradient table in MRtrix format.
        fslgrad: Provide the diffusion gradient table in FSL bvecs/bvals format.
        mask: Only process voxels within the specified binary brain mask image.
        voxels: Output an image showing the final voxel selection(s).
        shells: b-value(s) to use in response function estimation\
            (comma-separated list in case of multiple b-values, b=0 must be\
            included explicitly).
        lmax: maximum harmonic degree(s) for response function estimation\
            (comma-separated list in case of multiple b-values).
        nocleanup: do not delete intermediate files during script execution,\
            and do not delete scratch directory at script completion.
        scratch: manually specify the path in which to generate the scratch\
            directory.
        continue_: continue the script from a previous execution; must provide\
            the scratch directory path, and the name of the last\
            successfully-generated file.
        info: display information messages.
        quiet: do not display information messages or progress status;\
            alternatively, this can be achieved by setting the MRTRIX_QUIET\
            environment variable to a non-empty string.
        debug: display debugging messages.
        force: force overwrite of output files (caution: using the same file as\
            input and output might cause unexpected behaviour).
        nthreads: use this number of threads in multi-threaded applications\
            (set to 0 to disable multi-threading).
        config: temporarily set the value of an MRtrix config file entry.
        help_: display this information page and exit.
        version: display version information and exit.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `Dwi2responseOutputs`).
    """
    params = dwi2response_params(
        algorithm=algorithm,
        grad=grad,
        fslgrad=fslgrad,
        mask=mask,
        voxels=voxels,
        shells=shells,
        lmax=lmax,
        nocleanup=nocleanup,
        scratch=scratch,
        continue_=continue_,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
    )
    return dwi2response_execute(params, runner)


__all__ = [
    "DWI2RESPONSE_METADATA",
    "Dwi2responseConfigParamsDict",
    "Dwi2responseConfigParamsDictTagged",
    "Dwi2responseDhollanderOutputs",
    "Dwi2responseDhollanderParamsDict",
    "Dwi2responseDhollanderParamsDictTagged",
    "Dwi2responseFaOutputs",
    "Dwi2responseFaParamsDict",
    "Dwi2responseFaParamsDictTagged",
    "Dwi2responseFslgradParamsDict",
    "Dwi2responseFslgradParamsDictTagged",
    "Dwi2responseManualOutputs",
    "Dwi2responseManualParamsDict",
    "Dwi2responseManualParamsDictTagged",
    "Dwi2responseMsmt5ttOutputs",
    "Dwi2responseMsmt5ttParamsDict",
    "Dwi2responseMsmt5ttParamsDictTagged",
    "Dwi2responseOutputs",
    "Dwi2responseParamsDict",
    "Dwi2responseParamsDictTagged",
    "Dwi2responseTaxOutputs",
    "Dwi2responseTaxParamsDict",
    "Dwi2responseTaxParamsDictTagged",
    "Dwi2responseTournierOutputs",
    "Dwi2responseTournierParamsDict",
    "Dwi2responseTournierParamsDictTagged",
    "dwi2response",
    "dwi2response_config",
    "dwi2response_dhollander",
    "dwi2response_execute",
    "dwi2response_fa",
    "dwi2response_fslgrad",
    "dwi2response_manual",
    "dwi2response_msmt_5tt",
    "dwi2response_params",
    "dwi2response_tax",
    "dwi2response_tournier",
]
