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

import typing
import pathlib
from styxdefs import *

VOLUME_TFCE_METADATA = Metadata(
    id="00af94a3601fb72ac5202dedc89a1c5c427cb460.boutiques",
    name="volume-tfce",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


VolumeTfcePresmoothParameters = typing.TypedDict('VolumeTfcePresmoothParameters', {
    "@type": typing.NotRequired[typing.Literal["presmooth"]],
    "kernel": float,
    "opt_fwhm": bool,
})
VolumeTfcePresmoothParametersTagged = typing.TypedDict('VolumeTfcePresmoothParametersTagged', {
    "@type": typing.Literal["presmooth"],
    "kernel": float,
    "opt_fwhm": bool,
})


VolumeTfceParametersParameters = typing.TypedDict('VolumeTfceParametersParameters', {
    "@type": typing.NotRequired[typing.Literal["parameters"]],
    "e": float,
    "h": float,
})
VolumeTfceParametersParametersTagged = typing.TypedDict('VolumeTfceParametersParametersTagged', {
    "@type": typing.Literal["parameters"],
    "e": float,
    "h": float,
})


VolumeTfceParameters = typing.TypedDict('VolumeTfceParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/volume-tfce"]],
    "volume_in": InputPathType,
    "volume_out": str,
    "presmooth": typing.NotRequired[VolumeTfcePresmoothParameters | None],
    "opt_roi_roi_volume": typing.NotRequired[InputPathType | None],
    "parameters": typing.NotRequired[VolumeTfceParametersParameters | None],
    "opt_subvolume_subvolume": typing.NotRequired[str | None],
})
VolumeTfceParametersTagged = typing.TypedDict('VolumeTfceParametersTagged', {
    "@type": typing.Literal["workbench/volume-tfce"],
    "volume_in": InputPathType,
    "volume_out": str,
    "presmooth": typing.NotRequired[VolumeTfcePresmoothParameters | None],
    "opt_roi_roi_volume": typing.NotRequired[InputPathType | None],
    "parameters": typing.NotRequired[VolumeTfceParametersParameters | None],
    "opt_subvolume_subvolume": typing.NotRequired[str | None],
})


def volume_tfce_presmooth_params(
    kernel: float,
    opt_fwhm: bool = False,
) -> VolumeTfcePresmoothParametersTagged:
    """
    Build parameters.
    
    Args:
        kernel: the size of the gaussian smoothing kernel in mm, as sigma by\
            default.
        opt_fwhm: smoothing kernel size is FWHM, not sigma.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "presmooth",
        "kernel": kernel,
        "opt_fwhm": opt_fwhm,
    }
    return params


def volume_tfce_presmooth_cargs(
    params: VolumeTfcePresmoothParameters,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("-presmooth")
    cargs.append(str(params.get("kernel", None)))
    if params.get("opt_fwhm", False):
        cargs.append("-fwhm")
    return cargs


def volume_tfce_parameters_params(
    e: float,
    h: float,
) -> VolumeTfceParametersParametersTagged:
    """
    Build parameters.
    
    Args:
        e: exponent for cluster volume (default 0.5).
        h: exponent for threshold value (default 2.0).
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "parameters",
        "e": e,
        "h": h,
    }
    return params


def volume_tfce_parameters_cargs(
    params: VolumeTfceParametersParameters,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("-parameters")
    cargs.append(str(params.get("e", None)))
    cargs.append(str(params.get("h", None)))
    return cargs


class VolumeTfceOutputs(typing.NamedTuple):
    """
    Output object returned when calling `VolumeTfceParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    volume_out: OutputPathType
    """the output volume"""


def volume_tfce_params(
    volume_in: InputPathType,
    volume_out: str,
    presmooth: VolumeTfcePresmoothParameters | None = None,
    opt_roi_roi_volume: InputPathType | None = None,
    parameters: VolumeTfceParametersParameters | None = None,
    opt_subvolume_subvolume: str | None = None,
) -> VolumeTfceParametersTagged:
    """
    Build parameters.
    
    Args:
        volume_in: the volume to run TFCE on.
        volume_out: the output volume.
        presmooth: smooth the volume before running TFCE.
        opt_roi_roi_volume: select a region of interest to run TFCE on: the\
            area to run TFCE on, as a volume.
        parameters: set parameters for TFCE integral.
        opt_subvolume_subvolume: select a single subvolume: the subvolume\
            number or name.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/volume-tfce",
        "volume_in": volume_in,
        "volume_out": volume_out,
    }
    if presmooth is not None:
        params["presmooth"] = presmooth
    if opt_roi_roi_volume is not None:
        params["opt_roi_roi_volume"] = opt_roi_roi_volume
    if parameters is not None:
        params["parameters"] = parameters
    if opt_subvolume_subvolume is not None:
        params["opt_subvolume_subvolume"] = opt_subvolume_subvolume
    return params


def volume_tfce_cargs(
    params: VolumeTfceParameters,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("wb_command")
    cargs.append("-volume-tfce")
    cargs.append(execution.input_file(params.get("volume_in", None)))
    cargs.append(params.get("volume_out", None))
    if params.get("presmooth", None) is not None:
        cargs.extend(volume_tfce_presmooth_cargs(params.get("presmooth", None), execution))
    if params.get("opt_roi_roi_volume", None) is not None:
        cargs.extend([
            "-roi",
            execution.input_file(params.get("opt_roi_roi_volume", None))
        ])
    if params.get("parameters", None) is not None:
        cargs.extend(volume_tfce_parameters_cargs(params.get("parameters", None), execution))
    if params.get("opt_subvolume_subvolume", None) is not None:
        cargs.extend([
            "-subvolume",
            params.get("opt_subvolume_subvolume", None)
        ])
    return cargs


def volume_tfce_outputs(
    params: VolumeTfceParameters,
    execution: Execution,
) -> VolumeTfceOutputs:
    """
    Build outputs object containing output file paths and possibly stdout/stderr.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Outputs object.
    """
    ret = VolumeTfceOutputs(
        root=execution.output_file("."),
        volume_out=execution.output_file(params.get("volume_out", None)),
    )
    return ret


def volume_tfce_execute(
    params: VolumeTfceParameters,
    runner: Runner | None = None,
) -> VolumeTfceOutputs:
    """
    volume-tfce
    
    Do tfce on a volume file.
    
    This command does not do any statistical analysis. Please use something like
    PALM if you are just trying to do statistics on your data.
    
    Threshold-free cluster enhancement is a method to increase the relative
    value of regions that would form clusters in a standard thresholding test.
    This is accomplished by evaluating the integral of:
    
    e(h, p)^E * h^H * dh
    
    at each voxel p, where h ranges from 0 to the maximum value in the data, and
    e(h, p) is the extent of the cluster containing voxel p at threshold h.
    Negative values are similarly enhanced by negating the data, running the
    same process, and negating the result.
    
    This method is explained in: Smith SM, Nichols TE., "Threshold-free cluster
    enhancement: addressing problems of smoothing, threshold dependence and
    localisation in cluster inference." Neuroimage. 2009 Jan 1;44(1):83-98.
    PMID: 18501637.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeTfceOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(VOLUME_TFCE_METADATA)
    params = execution.params(params)
    cargs = volume_tfce_cargs(params, execution)
    ret = volume_tfce_outputs(params, execution)
    execution.run(cargs)
    return ret


def volume_tfce(
    volume_in: InputPathType,
    volume_out: str,
    presmooth: VolumeTfcePresmoothParameters | None = None,
    opt_roi_roi_volume: InputPathType | None = None,
    parameters: VolumeTfceParametersParameters | None = None,
    opt_subvolume_subvolume: str | None = None,
    runner: Runner | None = None,
) -> VolumeTfceOutputs:
    """
    volume-tfce
    
    Do tfce on a volume file.
    
    This command does not do any statistical analysis. Please use something like
    PALM if you are just trying to do statistics on your data.
    
    Threshold-free cluster enhancement is a method to increase the relative
    value of regions that would form clusters in a standard thresholding test.
    This is accomplished by evaluating the integral of:
    
    e(h, p)^E * h^H * dh
    
    at each voxel p, where h ranges from 0 to the maximum value in the data, and
    e(h, p) is the extent of the cluster containing voxel p at threshold h.
    Negative values are similarly enhanced by negating the data, running the
    same process, and negating the result.
    
    This method is explained in: Smith SM, Nichols TE., "Threshold-free cluster
    enhancement: addressing problems of smoothing, threshold dependence and
    localisation in cluster inference." Neuroimage. 2009 Jan 1;44(1):83-98.
    PMID: 18501637.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        volume_in: the volume to run TFCE on.
        volume_out: the output volume.
        presmooth: smooth the volume before running TFCE.
        opt_roi_roi_volume: select a region of interest to run TFCE on: the\
            area to run TFCE on, as a volume.
        parameters: set parameters for TFCE integral.
        opt_subvolume_subvolume: select a single subvolume: the subvolume\
            number or name.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeTfceOutputs`).
    """
    params = volume_tfce_params(
        volume_in=volume_in,
        volume_out=volume_out,
        presmooth=presmooth,
        opt_roi_roi_volume=opt_roi_roi_volume,
        parameters=parameters,
        opt_subvolume_subvolume=opt_subvolume_subvolume,
    )
    return volume_tfce_execute(params, runner)


__all__ = [
    "VOLUME_TFCE_METADATA",
    "VolumeTfceOutputs",
    "volume_tfce",
    "volume_tfce_execute",
    "volume_tfce_parameters_params",
    "volume_tfce_params",
    "volume_tfce_presmooth_params",
]
