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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_COMPUTE_VOLUME_FRACTIONS_METADATA = Metadata(
    id="0166823a396772941b111de738d47982e374ec28.boutiques",
    name="mri_compute_volume_fractions",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriComputeVolumeFractionsOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_compute_volume_fractions(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_cortex: OutputPathType
    """Output cortex volume file."""
    output_subcort_gm: OutputPathType
    """Output subcortical gray matter volume file."""
    output_wm: OutputPathType
    """Output white matter volume file."""
    output_csf: OutputPathType
    """Output cerebrospinal fluid volume file."""


def mri_compute_volume_fractions(
    output_stem: str,
    registration_file: InputPathType | None = None,
    regheader: str | None = None,
    usf: float | None = None,
    resolution: float | None = None,
    resmm: float | None = None,
    segmentation_file: InputPathType | None = None,
    wsurf: str | None = None,
    psurf: str | None = None,
    no_aseg: bool = False,
    stackfile: str | None = None,
    gmfile: str | None = None,
    no_fill_csf: bool = False,
    dilation: float | None = None,
    out_seg: str | None = None,
    ttseg: str | None = None,
    ttseg_ctab: str | None = None,
    mgz_format: bool = False,
    mgh_format: bool = False,
    nii_format: bool = False,
    nii_gz_format: bool = False,
    ttype_head: bool = False,
    vg_thresh: float | None = None,
    debug: bool = False,
    checkopts: bool = False,
    runner: Runner | None = None,
) -> MriComputeVolumeFractionsOutputs:
    """
    Computes partial volume fractions for cortex, subcortical GM, WM and CSF.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        output_stem: Output stem for generated files (e.g. cortex, subcort_gm,\
            wm, csf). Files will be saved with this stem in different formats based\
            on the selected flags.
        registration_file: Registration file (can be LTA or reg.dat). If using\
            reg.dat, a template volume is needed.
        regheader: Specify the subject for regheader.
        usf: Set anatomical upsample factor (default is 2).
        resolution: Resolution setting. Sets USF to round(1/res).
        resmm: Set functional upsampling resolution (default is\
            aseg->xsize/(USF)).
        segmentation_file: Use specified segmentation file instead of aseg.mgz.
        wsurf: Specify the white surface (default is 'white').
        psurf: Specify the pial surface (default is 'pial').
        no_aseg: Do not include aseg in processing (useful for testing).
        stackfile: Put cortex, subcortical GM, WM, CSF into a single\
            multi-frame file.
        gmfile: Put cortex + subcortical GM into a single-frame file.
        no_fill_csf: Do not attempt to fill voxels surrounding segmentation\
            with extracerebral CSF segmentation.
        dilation: For xCSF fill, dilate by specified number (default is 3). Use\
            -1 to fill the entire volume.
        out_seg: Save segmentation (after adding xCSF voxels).
        ttseg: Save tissue type segmentation.
        ttseg_ctab: Save tissue type segmentation color table.
        mgz_format: Use MGZ format.
        mgh_format: Use MGH format.
        nii_format: Use NII format.
        nii_gz_format: Use NII.GZ format.
        ttype_head: Use default+head instead of default tissue type info for\
            segmentation.
        vg_thresh: Threshold for 'ERROR: LTAconcat(): LTAs 0 and 1 do not\
            match'.
        debug: Turn on debugging mode.
        checkopts: Do not run anything, just check options and exit.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriComputeVolumeFractionsOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_COMPUTE_VOLUME_FRACTIONS_METADATA)
    cargs = []
    cargs.append("mri_compute_volume_fractions")
    cargs.extend([
        "--o",
        output_stem
    ])
    if registration_file is not None:
        cargs.extend([
            "--reg",
            execution.input_file(registration_file)
        ])
    if regheader is not None:
        cargs.extend([
            "--regheader",
            regheader
        ])
    if usf is not None:
        cargs.extend([
            "--usf",
            str(usf)
        ])
    if resolution is not None:
        cargs.extend([
            "--r",
            str(resolution)
        ])
    if resmm is not None:
        cargs.extend([
            "--resmm",
            str(resmm)
        ])
    if segmentation_file is not None:
        cargs.extend([
            "--seg",
            execution.input_file(segmentation_file)
        ])
    if wsurf is not None:
        cargs.extend([
            "--wsurf",
            wsurf
        ])
    if psurf is not None:
        cargs.extend([
            "--psurf",
            psurf
        ])
    if no_aseg:
        cargs.append("--no-aseg")
    if stackfile is not None:
        cargs.extend([
            "--stack",
            stackfile
        ])
    if gmfile is not None:
        cargs.extend([
            "--gm",
            gmfile
        ])
    if no_fill_csf:
        cargs.append("--no-fill-csf")
    if dilation is not None:
        cargs.extend([
            "--dil",
            str(dilation)
        ])
    if out_seg is not None:
        cargs.extend([
            "--out-seg",
            out_seg
        ])
    if ttseg is not None:
        cargs.extend([
            "--ttseg",
            ttseg
        ])
    if ttseg_ctab is not None:
        cargs.extend([
            "--ttseg-ctab",
            ttseg_ctab
        ])
    if mgz_format:
        cargs.append("--mgz")
    if mgh_format:
        cargs.append("--mgh")
    if nii_format:
        cargs.append("--nii")
    if nii_gz_format:
        cargs.append("--nii.gz")
    if ttype_head:
        cargs.append("--ttype+head")
    if vg_thresh is not None:
        cargs.extend([
            "--vg-thresh",
            str(vg_thresh)
        ])
    if debug:
        cargs.append("--debug")
    if checkopts:
        cargs.append("--checkopts")
    ret = MriComputeVolumeFractionsOutputs(
        root=execution.output_file("."),
        output_cortex=execution.output_file(output_stem + ".cortex.mgz"),
        output_subcort_gm=execution.output_file(output_stem + ".subcort_gm.mgz"),
        output_wm=execution.output_file(output_stem + ".wm.mgz"),
        output_csf=execution.output_file(output_stem + ".csf.mgz"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_COMPUTE_VOLUME_FRACTIONS_METADATA",
    "MriComputeVolumeFractionsOutputs",
    "mri_compute_volume_fractions",
]
