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

import typing
import pathlib
from styxdefs import *
import dataclasses

VOLUME_WEIGHTED_STATS_METADATA = Metadata(
    id="da2eeba1fe23ffefb27247087cb14abe89c34b0c.boutiques",
    name="volume-weighted-stats",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


@dataclasses.dataclass
class VolumeWeightedStatsWeightVolume:
    """
    use weights from a volume file.
    """
    weight_volume: InputPathType
    """volume file containing the weights"""
    opt_match_maps: bool = False
    """each subvolume of input uses the corresponding subvolume from the weights
    file"""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("-weight-volume")
        cargs.append(execution.input_file(self.weight_volume))
        if self.opt_match_maps:
            cargs.append("-match-maps")
        return cargs


@dataclasses.dataclass
class VolumeWeightedStatsRoi:
    """
    only consider data inside an roi.
    """
    roi_volume: InputPathType
    """the roi, as a volume file"""
    opt_match_maps: bool = False
    """each subvolume of input uses the corresponding subvolume from the roi
    file"""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("-roi")
        cargs.append(execution.input_file(self.roi_volume))
        if self.opt_match_maps:
            cargs.append("-match-maps")
        return cargs


@dataclasses.dataclass
class VolumeWeightedStatsStdev:
    """
    compute weighted standard deviation.
    """
    opt_sample: bool = False
    """estimate population stdev from the sample"""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("-stdev")
        if self.opt_sample:
            cargs.append("-sample")
        return cargs


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


def volume_weighted_stats(
    volume_in: InputPathType,
    weight_volume: VolumeWeightedStatsWeightVolume | None = None,
    opt_subvolume_subvolume: str | None = None,
    roi: VolumeWeightedStatsRoi | None = None,
    opt_mean: bool = False,
    stdev: VolumeWeightedStatsStdev | None = None,
    opt_percentile_percent: float | None = None,
    opt_sum: bool = False,
    opt_show_map_name: bool = False,
    runner: Runner | None = None,
) -> VolumeWeightedStatsOutputs:
    """
    Weighted spatial statistics on a volume file.
    
    For each subvolume of the input, a line of text is printed, resulting from
    the specified operation. If -weight-volume is not specified, each voxel's
    volume is used. Use -subvolume to only give output for a single subvolume.
    If the -roi option is used without -match-maps, then each line will contain
    as many numbers as there are maps in the ROI file, separated by tab
    characters. Exactly one of -mean, -stdev, -percentile or -sum must be
    specified.
    
    Using -sum without -weight-volume is equivalent to integrating with respect
    to volume.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        volume_in: the input volume.
        weight_volume: use weights from a volume file.
        opt_subvolume_subvolume: only display output for one subvolume: the\
            subvolume number or name.
        roi: only consider data inside an roi.
        opt_mean: compute weighted mean.
        stdev: compute weighted standard deviation.
        opt_percentile_percent: compute weighted percentile: the percentile to\
            find, must be between 0 and 100.
        opt_sum: compute weighted sum.
        opt_show_map_name: print map index and name before each output.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeWeightedStatsOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(VOLUME_WEIGHTED_STATS_METADATA)
    cargs = []
    cargs.append("wb_command")
    cargs.append("-volume-weighted-stats")
    cargs.append(execution.input_file(volume_in))
    if weight_volume is not None:
        cargs.extend(weight_volume.run(execution))
    if opt_subvolume_subvolume is not None:
        cargs.extend([
            "-subvolume",
            opt_subvolume_subvolume
        ])
    if roi is not None:
        cargs.extend(roi.run(execution))
    if opt_mean:
        cargs.append("-mean")
    if stdev is not None:
        cargs.extend(stdev.run(execution))
    if opt_percentile_percent is not None:
        cargs.extend([
            "-percentile",
            str(opt_percentile_percent)
        ])
    if opt_sum:
        cargs.append("-sum")
    if opt_show_map_name:
        cargs.append("-show-map-name")
    ret = VolumeWeightedStatsOutputs(
        root=execution.output_file("."),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "VOLUME_WEIGHTED_STATS_METADATA",
    "VolumeWeightedStatsOutputs",
    "VolumeWeightedStatsRoi",
    "VolumeWeightedStatsStdev",
    "VolumeWeightedStatsWeightVolume",
    "volume_weighted_stats",
]
