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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_COMPUTE_LAYER_FRACTIONS_METADATA = Metadata(
    id="4b975414209d034dddfda14c61a9efcc219f17d0.boutiques",
    name="mri_compute_layer_fractions",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriComputeLayerFractionsOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_compute_layer_fractions(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    layer_fractions_output: OutputPathType
    """Output file for layer fractions computation"""
    synth_output: OutputPathType
    """Synthesized output volume combining layers and aseg"""


def mri_compute_layer_fractions(
    reg_file: InputPathType,
    input_volume: InputPathType,
    output_stem: str,
    output_directory: str | None = None,
    aseg_file: InputPathType | None = None,
    target_volume: InputPathType | None = None,
    hemi_flag: bool = False,
    fs_names_flag: bool = False,
    subject_id: str | None = None,
    n_layers: float | None = None,
    synth_flag: bool = False,
    thickness: float | None = None,
    random_file: InputPathType | None = None,
    identity_file: str | None = None,
    runner: Runner | None = None,
) -> MriComputeLayerFractionsOutputs:
    """
    This program computes volumetric partial volume fractions from laminar surfaces
    using FreeSurfer.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        reg_file: Input registration file.
        input_volume: Input volume file.
        output_stem: Output stem for generated files.
        output_directory: Output directory specified by SUBJECTS_DIR.
        aseg_file: Input ASEG file for synthesis.
        target_volume: Target volume for analysis.
        hemi_flag: Specify hemisphere processing.
        fs_names_flag: Flag to use FreeSurfer names.
        subject_id: Subject ID for processing.
        n_layers: Number of layers for volume fraction computation.
        synth_flag: Flag to combine with the ASEG for a single segmentation\
            volume.
        thickness: Specify cortical thickness fraction.
        random_file: Specify random volume file.
        identity_file: Specify identity file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriComputeLayerFractionsOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_COMPUTE_LAYER_FRACTIONS_METADATA)
    cargs = []
    cargs.append("mri_compute_layer_fractions")
    cargs.append(execution.input_file(reg_file))
    cargs.append(execution.input_file(input_volume))
    cargs.append(output_stem)
    if output_directory is not None:
        cargs.extend([
            "-SDIR",
            output_directory
        ])
    if aseg_file is not None:
        cargs.extend([
            "-a",
            execution.input_file(aseg_file)
        ])
    if target_volume is not None:
        cargs.append(execution.input_file(target_volume))
    if hemi_flag:
        cargs.append("-hemi")
    if fs_names_flag:
        cargs.append("-FS_names")
    if subject_id is not None:
        cargs.extend([
            "-s",
            subject_id
        ])
    if n_layers is not None:
        cargs.extend([
            "-nlayers",
            str(n_layers)
        ])
    if synth_flag:
        cargs.append("-synth")
    if thickness is not None:
        cargs.extend([
            "-r",
            str(thickness)
        ])
    if random_file is not None:
        cargs.extend([
            "-n",
            execution.input_file(random_file)
        ])
    if identity_file is not None:
        cargs.append(identity_file)
    ret = MriComputeLayerFractionsOutputs(
        root=execution.output_file("."),
        layer_fractions_output=execution.output_file(output_stem + "_layer_fractions.mgz"),
        synth_output=execution.output_file(output_stem + "_synth.mgz"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_COMPUTE_LAYER_FRACTIONS_METADATA",
    "MriComputeLayerFractionsOutputs",
    "mri_compute_layer_fractions",
]
