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

import typing
import pathlib
from styxdefs import *

FIXELREORIENT_METADATA = Metadata(
    id="c2bf37ec8d7ea2da68c628776a8974d1b5351f66.boutiques",
    name="fixelreorient",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


FixelreorientConfigParameters = typing.TypedDict('FixelreorientConfigParameters', {
    "@type": typing.NotRequired[typing.Literal["config"]],
    "key": str,
    "value": str,
})
FixelreorientConfigParametersTagged = typing.TypedDict('FixelreorientConfigParametersTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})


FixelreorientParameters = typing.TypedDict('FixelreorientParameters', {
    "@type": typing.NotRequired[typing.Literal["mrtrix/fixelreorient"]],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[FixelreorientConfigParameters] | None],
    "help": bool,
    "version": bool,
    "fixel_in": InputPathType,
    "warp": InputPathType,
    "fixel_out": str,
})
FixelreorientParametersTagged = typing.TypedDict('FixelreorientParametersTagged', {
    "@type": typing.Literal["mrtrix/fixelreorient"],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[FixelreorientConfigParameters] | None],
    "help": bool,
    "version": bool,
    "fixel_in": InputPathType,
    "warp": InputPathType,
    "fixel_out": str,
})


def fixelreorient_config_params(
    key: str,
    value: str,
) -> FixelreorientConfigParametersTagged:
    """
    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 fixelreorient_config_cargs(
    params: FixelreorientConfigParameters,
    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 FixelreorientOutputs(typing.NamedTuple):
    """
    Output object returned when calling `FixelreorientParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    fixel_out: OutputPathType
    """the output fixel directory. If the the input and output directories are
    the same, the existing directions file will be replaced (providing the
    -force option is supplied). If a new directory is supplied then the fixel
    directions and all other fixel data will be copied to the new directory."""


def fixelreorient_params(
    fixel_in: InputPathType,
    warp: InputPathType,
    fixel_out: str,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[FixelreorientConfigParameters] | None = None,
    help_: bool = False,
    version: bool = False,
) -> FixelreorientParametersTagged:
    """
    Build parameters.
    
    Args:
        fixel_in: the input fixel directory.
        warp: a 4D deformation field used to perform reorientation.\
            Reorientation is performed by applying the Jacobian affine transform in\
            each voxel in the warp, then re-normalising the vector representing the\
            fixel direction.
        fixel_out: the output fixel directory. If the the input and output\
            directories are the same, the existing directions file will be replaced\
            (providing the -force option is supplied). If a new directory is\
            supplied then the fixel directions and all other fixel data will be\
            copied to the new directory.
        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/fixelreorient",
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "fixel_in": fixel_in,
        "warp": warp,
        "fixel_out": fixel_out,
    }
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    return params


def fixelreorient_cargs(
    params: FixelreorientParameters,
    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("fixelreorient")
    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 [fixelreorient_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")
    cargs.append(execution.input_file(params.get("fixel_in", None)))
    cargs.append(execution.input_file(params.get("warp", None)))
    cargs.append(params.get("fixel_out", None))
    return cargs


def fixelreorient_outputs(
    params: FixelreorientParameters,
    execution: Execution,
) -> FixelreorientOutputs:
    """
    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 = FixelreorientOutputs(
        root=execution.output_file("."),
        fixel_out=execution.output_file(params.get("fixel_out", None)),
    )
    return ret


def fixelreorient_execute(
    params: FixelreorientParameters,
    runner: Runner | None = None,
) -> FixelreorientOutputs:
    """
    fixelreorient
    
    Reorient fixel directions.
    
    Reorientation is performed by transforming the vector representing the fixel
    direction with the Jacobian (local affine transform) computed at each voxel
    in the warp, then re-normalising the vector.
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `FixelreorientOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(FIXELREORIENT_METADATA)
    params = execution.params(params)
    cargs = fixelreorient_cargs(params, execution)
    ret = fixelreorient_outputs(params, execution)
    execution.run(cargs)
    return ret


def fixelreorient(
    fixel_in: InputPathType,
    warp: InputPathType,
    fixel_out: str,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[FixelreorientConfigParameters] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> FixelreorientOutputs:
    """
    fixelreorient
    
    Reorient fixel directions.
    
    Reorientation is performed by transforming the vector representing the fixel
    direction with the Jacobian (local affine transform) computed at each voxel
    in the warp, then re-normalising the vector.
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        fixel_in: the input fixel directory.
        warp: a 4D deformation field used to perform reorientation.\
            Reorientation is performed by applying the Jacobian affine transform in\
            each voxel in the warp, then re-normalising the vector representing the\
            fixel direction.
        fixel_out: the output fixel directory. If the the input and output\
            directories are the same, the existing directions file will be replaced\
            (providing the -force option is supplied). If a new directory is\
            supplied then the fixel directions and all other fixel data will be\
            copied to the new directory.
        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 `FixelreorientOutputs`).
    """
    params = fixelreorient_params(
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        fixel_in=fixel_in,
        warp=warp,
        fixel_out=fixel_out,
    )
    return fixelreorient_execute(params, runner)


__all__ = [
    "FIXELREORIENT_METADATA",
    "FixelreorientOutputs",
    "fixelreorient",
    "fixelreorient_config_params",
    "fixelreorient_execute",
    "fixelreorient_params",
]
