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

import typing
import pathlib
from styxdefs import *
import dataclasses

TBSS_SKELETON_METADATA = Metadata(
    id="25571f737489a24f1ca40f7027b3aa2c256d8dc2.boutiques",
    name="tbss_skeleton",
    package="fsl",
    container_image_tag="brainlife/fsl:6.0.4-patched2",
)


class TbssSkeletonOutputs(typing.NamedTuple):
    """
    Output object returned when calling `tbss_skeleton(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_image_file: OutputPathType | None
    """Output skeleton image"""
    projected_4d_file: OutputPathType
    """Projected 4D data"""
    alt_4d_file: OutputPathType | None
    """Alternative 4D data"""
    alt_skeleton_file: OutputPathType | None
    """Alternative skeleton image"""
    debug2_image_outputs: OutputPathType | None
    """De-projected skelpoints points on skeleton back to all_FA space"""


def tbss_skeleton(
    input_image: InputPathType,
    output_image: str | None = None,
    skeleton_params: list[str] | None = None,
    alt_4d: InputPathType | None = None,
    alt_skeleton: InputPathType | None = None,
    debug_flag: bool = False,
    debug2_flag: InputPathType | None = None,
    runner: Runner | None = None,
) -> TbssSkeletonOutputs:
    """
    A tool for defining a 'skeleton' of white matter tracts in the brain to help
    compare them across subjects.
    
    Author: FMRIB Analysis Group, University of Oxford
    
    URL: https://fsl.fmrib.ox.ac.uk/fsl/fslwiki
    
    Args:
        input_image: Input image.
        output_image: Output skeleton image.
        skeleton_params: Skeletonization parameters: <skel_thresh>\
            <distancemap> <search_rule_mask> <4Ddata> <projected_4Ddata>.
        alt_4d: Alternative 4D data (e.g., L1).
        alt_skeleton: Alternative skeleton.
        debug_flag: Switch on debugging image outputs.
        debug2_flag: De-project skelpoints points on skeleton back to all_FA\
            space.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `TbssSkeletonOutputs`).
    """
    if skeleton_params is not None and (len(skeleton_params) != 5): 
        raise ValueError(f"Length of 'skeleton_params' must be 5 but was {len(skeleton_params)}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(TBSS_SKELETON_METADATA)
    cargs = []
    cargs.append("tbss_skeleton")
    cargs.extend([
        "-i",
        execution.input_file(input_image)
    ])
    if output_image is not None:
        cargs.extend([
            "-o",
            output_image
        ])
    if skeleton_params is not None:
        cargs.extend([
            "-p",
            *skeleton_params
        ])
    if alt_4d is not None:
        cargs.extend([
            "-a",
            execution.input_file(alt_4d)
        ])
    if alt_skeleton is not None:
        cargs.extend([
            "-s",
            execution.input_file(alt_skeleton)
        ])
    if debug_flag:
        cargs.append("-d")
    if debug2_flag is not None:
        cargs.extend([
            "-D",
            execution.input_file(debug2_flag)
        ])
    ret = TbssSkeletonOutputs(
        root=execution.output_file("."),
        output_image_file=execution.output_file(output_image) if (output_image is not None) else None,
        projected_4d_file=execution.output_file("[PROJECTED_4D]"),
        alt_4d_file=execution.output_file(pathlib.Path(alt_4d).name) if (alt_4d is not None) else None,
        alt_skeleton_file=execution.output_file(pathlib.Path(alt_skeleton).name) if (alt_skeleton is not None) else None,
        debug2_image_outputs=execution.output_file(pathlib.Path(debug2_flag).name) if (debug2_flag is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "TBSS_SKELETON_METADATA",
    "TbssSkeletonOutputs",
    "tbss_skeleton",
]
