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

import typing
import pathlib
from styxdefs import *
import dataclasses

V_3D_RANKIZER_METADATA = Metadata(
    id="e854a99a853a99ed471d7da08fb007bec90426d2.boutiques",
    name="3dRankizer",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class V3dRankizerOutputs(typing.NamedTuple):
    """
    Output object returned when calling `v_3d_rankizer(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_dataset: OutputPathType
    """Output float-format dataset containing ranked voxel values"""


def v_3d_rankizer(
    dataset: InputPathType,
    prefix: str,
    base_rank: float | None = None,
    mask: InputPathType | None = None,
    percentize: bool = False,
    percentize_mask: bool = False,
    runner: Runner | None = None,
) -> V3dRankizerOutputs:
    """
    Tool to rank each voxel as sorted into increasing value. Ties get the average
    rank.
    
    Author: AFNI Developers
    
    URL: https://afni.nimh.nih.gov/
    
    Args:
        dataset: Input MRI dataset.
        prefix: Write results into float-format output dataset.
        base_rank: Set the 'base' rank instead of 1.
        mask: Use the specified dataset as a mask. Only voxels with nonzero\
            values in this mask will be used from the input dataset. Voxels outside\
            the mask will get rank 0.
        percentize: Divide rank by the number of voxels in the dataset and\
            multiply by 100.0.
        percentize_mask: Divide rank by the number of voxels in the mask and\
            multiply by 100.0.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `V3dRankizerOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(V_3D_RANKIZER_METADATA)
    cargs = []
    cargs.append("3dRankizer")
    cargs.append(execution.input_file(dataset))
    if base_rank is not None:
        cargs.extend([
            "-brank",
            str(base_rank)
        ])
    if mask is not None:
        cargs.extend([
            "-mask",
            execution.input_file(mask)
        ])
    cargs.extend([
        "-prefix",
        prefix
    ])
    if percentize:
        cargs.append("-percentize")
    if percentize_mask:
        cargs.append("-percentize_mask")
    ret = V3dRankizerOutputs(
        root=execution.output_file("."),
        output_dataset=execution.output_file(prefix + "+tlrc.HEAD"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "V3dRankizerOutputs",
    "V_3D_RANKIZER_METADATA",
    "v_3d_rankizer",
]
