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

import typing
import pathlib
from styxdefs import *
import dataclasses

VOL2SEGAVG_METADATA = Metadata(
    id="9d9d31cfe51a606166834e1114b170012714797f.boutiques",
    name="vol2segavg",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class Vol2segavgOutputs(typing.NamedTuple):
    """
    Output object returned when calling `vol2segavg(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_file: OutputPathType
    """Output file containing the computed average"""


def vol2segavg(
    output_file: str,
    input_volume: InputPathType,
    registration: str,
    segmentation_file: InputPathType,
    aparc_aseg_flag: bool = False,
    subject_id: str | None = None,
    segmentation_id: list[float] | None = None,
    multiply_value: float | None = None,
    no_bb_flag: bool = False,
    erode_value: float | None = None,
    dilate_value: float | None = None,
    wm_flag: bool = False,
    vcsf_flag: bool = False,
    xcsf_flag: bool = False,
    remove_mean_flag: bool = False,
    runner: Runner | None = None,
) -> Vol2segavgOutputs:
    """
    Computes the average of a volume inside a given segment of a segmentation
    resampling the input volume to the segmentation space.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        output_file: Output file, can be .txt or a binary (e.g., .nii, .mgh).
        input_volume: Input volume file (e.g., vol.nii).
        registration: Registration file, can be reg.dat or use --regheader.
        segmentation_file: Segmentation file (e.g., seg.mgz).
        aparc_aseg_flag: Use aparc+aseg flag.
        subject_id: Subject ID, may be needed if --reg not supplied.
        segmentation_id: Segmentation ID(s). Multiple IDs can be supplied.
        multiply_value: Multiply input by MulVal.
        no_bb_flag: Do not use bounding box.
        erode_value: Erode segmentation.
        dilate_value: Dilate segmentation.
        wm_flag: Sets segid to 2, 41, 7, 46, 251, 252, 253, 254, 255, 77, 78,\
            79 and use aparc+aseg.
        vcsf_flag: Sets segid to 4, 5, 43, 44, 31, 63 and use aparc+aseg.
        xcsf_flag: Sets segid to 257 and use apas+head.
        remove_mean_flag: Remove mean from time course.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `Vol2segavgOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(VOL2SEGAVG_METADATA)
    cargs = []
    cargs.append("vol2segavg")
    cargs.extend([
        "--o",
        output_file
    ])
    cargs.extend([
        "--i",
        execution.input_file(input_volume)
    ])
    cargs.extend([
        "--reg",
        registration
    ])
    cargs.extend([
        "--seg",
        execution.input_file(segmentation_file)
    ])
    if aparc_aseg_flag:
        cargs.append("--aparc+aseg")
    if subject_id is not None:
        cargs.extend([
            "--s",
            subject_id
        ])
    if segmentation_id is not None:
        cargs.extend([
            "--segid",
            *map(str, segmentation_id)
        ])
    if multiply_value is not None:
        cargs.extend([
            "--mul",
            str(multiply_value)
        ])
    if no_bb_flag:
        cargs.append("--no-bb")
    if erode_value is not None:
        cargs.extend([
            "--erode",
            str(erode_value)
        ])
    if dilate_value is not None:
        cargs.extend([
            "--dilate",
            str(dilate_value)
        ])
    if wm_flag:
        cargs.append("--wm")
    if vcsf_flag:
        cargs.append("--vcsf")
    if xcsf_flag:
        cargs.append("--xcsf")
    if remove_mean_flag:
        cargs.append("--remove-mean")
    ret = Vol2segavgOutputs(
        root=execution.output_file("."),
        output_file=execution.output_file(output_file),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "VOL2SEGAVG_METADATA",
    "Vol2segavgOutputs",
    "vol2segavg",
]
