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

import typing
import pathlib
from styxdefs import *
import dataclasses

V_5TTGEN_METADATA = Metadata(
    id="e1c8721cf951c39ed38887df51b196592e09eda2.boutiques",
    name="5ttgen",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


class V5ttgenFreesurferOutputs(typing.NamedTuple):
    """
    Output object returned when calling `V5ttgenFreesurfer(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """The output 5TT image"""


@dataclasses.dataclass
class V5ttgenFreesurfer:
    """
    Generate the 5TT image based on a FreeSurfer parcellation image.
    """
    input_: InputPathType
    """The input FreeSurfer parcellation image (any image containing 'aseg' in
    its name)"""
    output: InputPathType
    """The output 5TT image"""
    lut: InputPathType | None = None
    """Manually provide path to the lookup table on which the input parcellation
    image is based (e.g. FreeSurferColorLUT.txt)"""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("freesurfer")
        cargs.append(execution.input_file(self.input_))
        cargs.append(execution.input_file(self.output))
        if self.lut is not None:
            cargs.extend([
                "-lut",
                execution.input_file(self.lut)
            ])
        return cargs
    
    def outputs(
        self,
        execution: Execution,
    ) -> V5ttgenFreesurferOutputs:
        """
        Collect output file paths.
        
        Args:
            execution: The execution object.
        Returns:
            NamedTuple of outputs (described in `V5ttgenFreesurferOutputs`).
        """
        ret = V5ttgenFreesurferOutputs(
            root=execution.output_file("."),
            output=execution.output_file(pathlib.Path(self.output).name),
        )
        return ret


class V5ttgenFslOutputs(typing.NamedTuple):
    """
    Output object returned when calling `V5ttgenFsl(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """The output 5TT image"""


@dataclasses.dataclass
class V5ttgenFsl:
    """
    Use FSL commands to generate the 5TT image based on a T1-weighted image.
    """
    input_: InputPathType
    """The input T1-weighted image"""
    output: InputPathType
    """The output 5TT image"""
    t2: InputPathType | None = None
    """Provide a T2-weighted image in addition to the default T1-weighted image;
    this will be used as a second input to FSL FAST"""
    mask: InputPathType | None = None
    """Manually provide a brain mask, rather than deriving one in the script"""
    premasked: bool = False
    """Indicate that brain masking has already been applied to the input
    image"""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("fsl")
        cargs.append(execution.input_file(self.input_))
        cargs.append(execution.input_file(self.output))
        if self.t2 is not None:
            cargs.extend([
                "-t2",
                execution.input_file(self.t2)
            ])
        if self.mask is not None:
            cargs.extend([
                "-mask",
                execution.input_file(self.mask)
            ])
        if self.premasked:
            cargs.append("-premasked")
        return cargs
    
    def outputs(
        self,
        execution: Execution,
    ) -> V5ttgenFslOutputs:
        """
        Collect output file paths.
        
        Args:
            execution: The execution object.
        Returns:
            NamedTuple of outputs (described in `V5ttgenFslOutputs`).
        """
        ret = V5ttgenFslOutputs(
            root=execution.output_file("."),
            output=execution.output_file(pathlib.Path(self.output).name),
        )
        return ret


class V5ttgenGifOutputs(typing.NamedTuple):
    """
    Output object returned when calling `V5ttgenGif(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """The output 5TT image"""


@dataclasses.dataclass
class V5ttgenGif:
    """
    Generate the 5TT image based on a Geodesic Information Flow (GIF)
    segmentation image.
    """
    input_: InputPathType
    """The input Geodesic Information Flow (GIF) segmentation image"""
    output: InputPathType
    """The output 5TT image"""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("gif")
        cargs.append(execution.input_file(self.input_))
        cargs.append(execution.input_file(self.output))
        return cargs
    
    def outputs(
        self,
        execution: Execution,
    ) -> V5ttgenGifOutputs:
        """
        Collect output file paths.
        
        Args:
            execution: The execution object.
        Returns:
            NamedTuple of outputs (described in `V5ttgenGifOutputs`).
        """
        ret = V5ttgenGifOutputs(
            root=execution.output_file("."),
            output=execution.output_file(pathlib.Path(self.output).name),
        )
        return ret


class V5ttgenHsvsOutputs(typing.NamedTuple):
    """
    Output object returned when calling `V5ttgenHsvs(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """The output 5TT image"""


@dataclasses.dataclass
class V5ttgenHsvs:
    """
    Generate a 5TT image based on Hybrid Surface and Volume Segmentation (HSVS),
    using FreeSurfer and FSL tools.
    """
    input_: InputPathType
    """The input FreeSurfer subject directory"""
    output: InputPathType
    """The output 5TT image"""
    template: InputPathType | None = None
    """Provide an image that will form the template for the generated 5TT
    image"""
    hippocampi: typing.Literal["subfields", "first", "aseg"] | None = None
    """Select method to be used for hippocampi (& amygdalae) segmentation;
    options are: subfields,first,aseg"""
    thalami: typing.Literal["nuclei", "first", "aseg"] | None = None
    """Select method to be used for thalamic segmentation; options are:
    nuclei,first,aseg"""
    white_stem: bool = False
    """Classify the brainstem as white matter"""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("hsvs")
        cargs.append(execution.input_file(self.input_))
        cargs.append(execution.input_file(self.output))
        if self.template is not None:
            cargs.extend([
                "-template",
                execution.input_file(self.template)
            ])
        if self.hippocampi is not None:
            cargs.append(self.hippocampi)
        if self.thalami is not None:
            cargs.append(self.thalami)
        if self.white_stem:
            cargs.append("-white_stem")
        return cargs
    
    def outputs(
        self,
        execution: Execution,
    ) -> V5ttgenHsvsOutputs:
        """
        Collect output file paths.
        
        Args:
            execution: The execution object.
        Returns:
            NamedTuple of outputs (described in `V5ttgenHsvsOutputs`).
        """
        ret = V5ttgenHsvsOutputs(
            root=execution.output_file("."),
            output=execution.output_file(pathlib.Path(self.output).name),
        )
        return ret


@dataclasses.dataclass
class V5ttgenConfig:
    """
    temporarily set the value of an MRtrix config file entry.
    """
    key: str
    """temporarily set the value of an MRtrix config file entry."""
    value: str
    """temporarily set the value of an MRtrix config file entry."""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("-config")
        cargs.append(self.key)
        cargs.append(self.value)
        return cargs


class V5ttgenOutputs(typing.NamedTuple):
    """
    Output object returned when calling `v_5ttgen(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    algorithm: typing.Union[V5ttgenFreesurferOutputs, V5ttgenFslOutputs, V5ttgenGifOutputs, V5ttgenHsvsOutputs]
    """Outputs from `V5ttgenFreesurfer` or `V5ttgenFsl` or `V5ttgenGif` or
    `V5ttgenHsvs`."""


def v_5ttgen(
    algorithm: typing.Union[V5ttgenFreesurfer, V5ttgenFsl, V5ttgenGif, V5ttgenHsvs],
    nocrop: bool = False,
    sgm_amyg_hipp: bool = False,
    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[V5ttgenConfig] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> V5ttgenOutputs:
    """
    Generate a 5TT image suitable for ACT.
    
    5ttgen acts as a 'master' script for generating a five-tissue-type (5TT)
    segmented tissue image suitable for use in Anatomically-Constrained
    Tractography (ACT). A range of different algorithms are available for
    completing this task. When using this script, the name of the algorithm to
    be used must appear as the first argument on the command-line after
    '5ttgen'. The subsequent compulsory arguments and options available depend
    on the particular algorithm being invoked.
    Each algorithm available also has its own help page, including necessary
    references; e.g. to see the help page of the 'fsl' algorithm, type '5ttgen
    fsl'.
    
    Author: Robert E. Smith (robert.smith@florey.edu.au)
    
    URL: https://mrtrix.readthedocs.io/en/3.0.4/reference/commands/5ttgen.html
    
    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: freesurfer, fsl, gif, hsvs.
        nocrop: Do NOT crop the resulting 5TT image to reduce its size (keep\
            the same dimensions as the input image).
        sgm_amyg_hipp: Represent the amygdalae and hippocampi as sub-cortical\
            grey matter in the 5TT image.
        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 `V5ttgenOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(V_5TTGEN_METADATA)
    cargs = []
    cargs.append("5ttgen")
    cargs.extend(algorithm.run(execution))
    if nocrop:
        cargs.append("-nocrop")
    if sgm_amyg_hipp:
        cargs.append("-sgm_amyg_hipp")
    if nocleanup:
        cargs.append("-nocleanup")
    if scratch is not None:
        cargs.extend([
            "-scratch",
            scratch
        ])
    if continue_ is not None:
        cargs.extend([
            "-continue",
            continue_
        ])
    if info:
        cargs.append("-info")
    if quiet:
        cargs.append("-quiet")
    if debug:
        cargs.append("-debug")
    if force:
        cargs.append("-force")
    if nthreads is not None:
        cargs.extend([
            "-nthreads",
            str(nthreads)
        ])
    if config is not None:
        cargs.extend([a for c in [s.run(execution) for s in config] for a in c])
    if help_:
        cargs.append("-help")
    if version:
        cargs.append("-version")
    ret = V5ttgenOutputs(
        root=execution.output_file("."),
        algorithm=algorithm.outputs(execution),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "V5ttgenConfig",
    "V5ttgenFreesurfer",
    "V5ttgenFreesurferOutputs",
    "V5ttgenFsl",
    "V5ttgenFslOutputs",
    "V5ttgenGif",
    "V5ttgenGifOutputs",
    "V5ttgenHsvs",
    "V5ttgenHsvsOutputs",
    "V5ttgenOutputs",
    "V_5TTGEN_METADATA",
    "v_5ttgen",
]
