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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_GTMSEG_METADATA = Metadata(
    id="2c164b92c884894655aa369148327d84b308bec1.boutiques",
    name="mri_gtmseg",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriGtmsegOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_gtmseg(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""


def mri_gtmseg(
    output_volume: str,
    source_subject: str,
    internal_usf: float | None = None,
    apas_file: InputPathType | None = None,
    context_annotation: list[str] | None = None,
    subseg_wm: bool = False,
    wm_annotation: list[str] | None = None,
    dmax: float | None = None,
    keep_hypo: bool = False,
    keep_cc: bool = False,
    ctab: InputPathType | None = None,
    lhminmax: list[float] | None = None,
    rhminmax: list[float] | None = None,
    output_usf: float | None = None,
    threads: float | None = None,
    threads_max: bool = False,
    threads_max_1: bool = False,
    debug: bool = False,
    check_opts: bool = False,
    runner: Runner | None = None,
) -> MriGtmsegOutputs:
    """
    Creates a segmentation that can be used with the geometric transfer matrix
    (GTM).
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        output_volume: Output volume (output will be subject/mri/outvol).
        source_subject: Source subject.
        internal_usf: Upsampling factor (default 2).
        apas_file: Defines extra-cerebral and subcortical segmentations\
            (apas+head.mgz).
        context_annotation: Use annotation to segment cortex\
            (aparc.annot,1000,2000).
        subseg_wm: Turn on segmenting of WM into smaller parts (off by default).
        wm_annotation: Use annotation to subsegment white matter.
        dmax: Distance from cortex for white matter segmentation to be\
            considered 'unsegmented' (default 5.000000).
        keep_hypo: Do not convert white matter hypointensities to a white\
            matter label.
        keep_cc: Do not convert corpus callosum to a white matter label.
        ctab: Copy items in ctab.lut into master ctab merging or overwriting\
            what is there.
        lhminmax: For defining left hemisphere ribbon in APAS (default: 1000\
            1900).
        rhminmax: For defining right hemisphere ribbon in APAS (default: 2000\
            2900).
        output_usf: Set actual output resolution. Default is to be the same as\
            the --internal-usf.
        threads: Use N threads (with Open MP).
        threads_max: Use the maximum allowable number of threads for this\
            computer.
        threads_max_1: Use one less than the maximum allowable number of\
            threads for this computer.
        debug: Turn on debugging.
        check_opts: Don't run anything, just check options and exit.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriGtmsegOutputs`).
    """
    if context_annotation is not None and (len(context_annotation) != 3): 
        raise ValueError(f"Length of 'context_annotation' must be 3 but was {len(context_annotation)}")
    if wm_annotation is not None and (len(wm_annotation) != 3): 
        raise ValueError(f"Length of 'wm_annotation' must be 3 but was {len(wm_annotation)}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_GTMSEG_METADATA)
    cargs = []
    cargs.append("mri_gtmseg")
    cargs.extend([
        "--o",
        output_volume
    ])
    cargs.extend([
        "--s",
        source_subject
    ])
    if internal_usf is not None:
        cargs.extend([
            "--internal-usf",
            str(internal_usf)
        ])
    if apas_file is not None:
        cargs.extend([
            "--apas",
            execution.input_file(apas_file)
        ])
    if context_annotation is not None:
        cargs.extend([
            "--ctx-annot",
            *context_annotation
        ])
    if subseg_wm:
        cargs.append("--subseg-wm")
    if wm_annotation is not None:
        cargs.extend([
            "--wm-annot",
            *wm_annotation
        ])
    if dmax is not None:
        cargs.extend([
            "--dmax",
            str(dmax)
        ])
    if keep_hypo:
        cargs.append("--keep-hypo")
    if keep_cc:
        cargs.append("--keep-cc")
    if ctab is not None:
        cargs.extend([
            "--ctab",
            execution.input_file(ctab)
        ])
    if lhminmax is not None:
        cargs.extend([
            "--lhminmax",
            *map(str, lhminmax)
        ])
    if rhminmax is not None:
        cargs.extend([
            "--rhminmax",
            *map(str, rhminmax)
        ])
    if output_usf is not None:
        cargs.extend([
            "--output-usf",
            str(output_usf)
        ])
    if threads is not None:
        cargs.extend([
            "--threads",
            str(threads)
        ])
    if threads_max:
        cargs.append("--threads-max")
    if threads_max_1:
        cargs.append("--threads-max-1")
    if debug:
        cargs.append("--debug")
    if check_opts:
        cargs.append("--checkopts")
    ret = MriGtmsegOutputs(
        root=execution.output_file("."),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_GTMSEG_METADATA",
    "MriGtmsegOutputs",
    "mri_gtmseg",
]
