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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_LABEL_VOLUME_METADATA = Metadata(
    id="c74d81eab6ea4f91d999a3f527f7e857de7b9442.boutiques",
    name="mri_label_volume",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriLabelVolumeOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_label_volume(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_volume_results: OutputPathType
    """Computed volume results."""
    output_log_results: OutputPathType
    """Log file if -l option is used."""


def mri_label_volume(
    volume: InputPathType,
    labels: list[str],
    partial_volume_effects: InputPathType | None = None,
    intracranial_volume: InputPathType | None = None,
    spreadsheet_subject: str | None = None,
    non_zero_voxels: bool = False,
    replace_label_in: str | None = None,
    replace_label_out: str | None = None,
    brain_volume: InputPathType | None = None,
    percentage: bool = False,
    log_results: InputPathType | None = None,
    atlas_transform_file: InputPathType | None = None,
    atlas_scalefactor: float | None = None,
    etiv_transform_file: InputPathType | None = None,
    etiv_scalefactor: float | None = None,
    etiv_subject: str | None = None,
    runner: Runner | None = None,
) -> MriLabelVolumeOutputs:
    """
    A tool to compute volumes of labeled voxels within MRI images, often used in
    conjunction with FreeSurfer processed data.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        volume: Volume file (e.g., volume.mgz) to analyze.
        labels: Labels to compute volume for.
        partial_volume_effects: Compute partial volume effects using intensity\
            volume.
        intracranial_volume: Normalize by the intracranial volume in provided\
            file.
        spreadsheet_subject: Output in spreadsheet mode, including subject name.
        non_zero_voxels: Compute volume of all non-zero voxels (e.g. for\
            computing brain volume).
        replace_label_in: Replace label <in> with label <out>.
        replace_label_out: Label to replace with.
        brain_volume: Compute the brain volume from provided brain volume file\
            and normalize by it.
        percentage: Compute volume as a percentage of all non-zero labels.
        log_results: Log results to provided file.
        atlas_transform_file: Specify LTA or XFM atlas transform file and scale\
            factor to use for ICV correction.
        atlas_scalefactor: Scale factor for ICV correction.
        etiv_transform_file: Same as -atlas_icv.
        etiv_scalefactor: eTIV scale factor.
        etiv_subject: Same as -eTIV, and generate MATLAB data appending subject\
            to structure.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriLabelVolumeOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_LABEL_VOLUME_METADATA)
    cargs = []
    cargs.append("mri_label_volume")
    cargs.append(execution.input_file(volume))
    cargs.extend(labels)
    if partial_volume_effects is not None:
        cargs.extend([
            "-pv",
            execution.input_file(partial_volume_effects)
        ])
    if intracranial_volume is not None:
        cargs.extend([
            "-icv",
            execution.input_file(intracranial_volume)
        ])
    if spreadsheet_subject is not None:
        cargs.extend([
            "-s",
            spreadsheet_subject
        ])
    if non_zero_voxels:
        cargs.append("-a")
    if replace_label_in is not None:
        cargs.extend([
            "-t",
            replace_label_in
        ])
    if replace_label_out is not None:
        cargs.append(replace_label_out)
    if brain_volume is not None:
        cargs.extend([
            "-b",
            execution.input_file(brain_volume)
        ])
    if percentage:
        cargs.append("-p")
    if log_results is not None:
        cargs.extend([
            "-l",
            execution.input_file(log_results)
        ])
    if atlas_transform_file is not None:
        cargs.extend([
            "-atlas_icv",
            execution.input_file(atlas_transform_file)
        ])
    if atlas_scalefactor is not None:
        cargs.append(str(atlas_scalefactor))
    if etiv_transform_file is not None:
        cargs.extend([
            "-eTIV",
            execution.input_file(etiv_transform_file)
        ])
    if etiv_scalefactor is not None:
        cargs.append(str(etiv_scalefactor))
    if etiv_subject is not None:
        cargs.extend([
            "-eTIV_matdat",
            etiv_subject
        ])
    ret = MriLabelVolumeOutputs(
        root=execution.output_file("."),
        output_volume_results=execution.output_file("volume_label_results.txt"),
        output_log_results=execution.output_file("volume_log.txt"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_LABEL_VOLUME_METADATA",
    "MriLabelVolumeOutputs",
    "mri_label_volume",
]
