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

import typing
import pathlib
from styxdefs import *

CIFTI_LABEL_ADJACENCY_METADATA = Metadata(
    id="bcb2ac9510f2329e36c8dab72f902febc2c62123.boutiques",
    name="cifti-label-adjacency",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


CiftiLabelAdjacencyParameters = typing.TypedDict('CiftiLabelAdjacencyParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/cifti-label-adjacency"]],
    "label_in": InputPathType,
    "adjacency_out": str,
    "opt_left_surface_surface": typing.NotRequired[InputPathType | None],
    "opt_right_surface_surface": typing.NotRequired[InputPathType | None],
    "opt_cerebellum_surface_surface": typing.NotRequired[InputPathType | None],
})
CiftiLabelAdjacencyParametersTagged = typing.TypedDict('CiftiLabelAdjacencyParametersTagged', {
    "@type": typing.Literal["workbench/cifti-label-adjacency"],
    "label_in": InputPathType,
    "adjacency_out": str,
    "opt_left_surface_surface": typing.NotRequired[InputPathType | None],
    "opt_right_surface_surface": typing.NotRequired[InputPathType | None],
    "opt_cerebellum_surface_surface": typing.NotRequired[InputPathType | None],
})


class CiftiLabelAdjacencyOutputs(typing.NamedTuple):
    """
    Output object returned when calling `CiftiLabelAdjacencyParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    adjacency_out: OutputPathType
    """the output cifti pconn adjacency matrix"""


def cifti_label_adjacency_params(
    label_in: InputPathType,
    adjacency_out: str,
    opt_left_surface_surface: InputPathType | None = None,
    opt_right_surface_surface: InputPathType | None = None,
    opt_cerebellum_surface_surface: InputPathType | None = None,
) -> CiftiLabelAdjacencyParametersTagged:
    """
    Build parameters.
    
    Args:
        label_in: the input cifti label file.
        adjacency_out: the output cifti pconn adjacency matrix.
        opt_left_surface_surface: specify the left surface to use: the left\
            surface file.
        opt_right_surface_surface: specify the right surface to use: the right\
            surface file.
        opt_cerebellum_surface_surface: specify the cerebellum surface to use:\
            the cerebellum surface file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-label-adjacency",
        "label_in": label_in,
        "adjacency_out": adjacency_out,
    }
    if opt_left_surface_surface is not None:
        params["opt_left_surface_surface"] = opt_left_surface_surface
    if opt_right_surface_surface is not None:
        params["opt_right_surface_surface"] = opt_right_surface_surface
    if opt_cerebellum_surface_surface is not None:
        params["opt_cerebellum_surface_surface"] = opt_cerebellum_surface_surface
    return params


def cifti_label_adjacency_cargs(
    params: CiftiLabelAdjacencyParameters,
    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("-cifti-label-adjacency")
    cargs.append(execution.input_file(params.get("label_in", None)))
    cargs.append(params.get("adjacency_out", None))
    if params.get("opt_left_surface_surface", None) is not None:
        cargs.extend([
            "-left-surface",
            execution.input_file(params.get("opt_left_surface_surface", None))
        ])
    if params.get("opt_right_surface_surface", None) is not None:
        cargs.extend([
            "-right-surface",
            execution.input_file(params.get("opt_right_surface_surface", None))
        ])
    if params.get("opt_cerebellum_surface_surface", None) is not None:
        cargs.extend([
            "-cerebellum-surface",
            execution.input_file(params.get("opt_cerebellum_surface_surface", None))
        ])
    return cargs


def cifti_label_adjacency_outputs(
    params: CiftiLabelAdjacencyParameters,
    execution: Execution,
) -> CiftiLabelAdjacencyOutputs:
    """
    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 = CiftiLabelAdjacencyOutputs(
        root=execution.output_file("."),
        adjacency_out=execution.output_file(params.get("adjacency_out", None)),
    )
    return ret


def cifti_label_adjacency_execute(
    params: CiftiLabelAdjacencyParameters,
    runner: Runner | None = None,
) -> CiftiLabelAdjacencyOutputs:
    """
    cifti-label-adjacency
    
    Make adjacency matrix of a cifti label file.
    
    Find face-adjacent voxels and connected vertices that have different label
    values, and count them for each pair. Put the resulting counts into a
    parcellated connectivity file, with the diagonal being zero. This gives a
    rough estimate of how long or expansive the border between two labels is.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiLabelAdjacencyOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_LABEL_ADJACENCY_METADATA)
    params = execution.params(params)
    cargs = cifti_label_adjacency_cargs(params, execution)
    ret = cifti_label_adjacency_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_label_adjacency(
    label_in: InputPathType,
    adjacency_out: str,
    opt_left_surface_surface: InputPathType | None = None,
    opt_right_surface_surface: InputPathType | None = None,
    opt_cerebellum_surface_surface: InputPathType | None = None,
    runner: Runner | None = None,
) -> CiftiLabelAdjacencyOutputs:
    """
    cifti-label-adjacency
    
    Make adjacency matrix of a cifti label file.
    
    Find face-adjacent voxels and connected vertices that have different label
    values, and count them for each pair. Put the resulting counts into a
    parcellated connectivity file, with the diagonal being zero. This gives a
    rough estimate of how long or expansive the border between two labels is.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        label_in: the input cifti label file.
        adjacency_out: the output cifti pconn adjacency matrix.
        opt_left_surface_surface: specify the left surface to use: the left\
            surface file.
        opt_right_surface_surface: specify the right surface to use: the right\
            surface file.
        opt_cerebellum_surface_surface: specify the cerebellum surface to use:\
            the cerebellum surface file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiLabelAdjacencyOutputs`).
    """
    params = cifti_label_adjacency_params(
        label_in=label_in,
        adjacency_out=adjacency_out,
        opt_left_surface_surface=opt_left_surface_surface,
        opt_right_surface_surface=opt_right_surface_surface,
        opt_cerebellum_surface_surface=opt_cerebellum_surface_surface,
    )
    return cifti_label_adjacency_execute(params, runner)


__all__ = [
    "CIFTI_LABEL_ADJACENCY_METADATA",
    "CiftiLabelAdjacencyOutputs",
    "cifti_label_adjacency",
    "cifti_label_adjacency_execute",
    "cifti_label_adjacency_params",
]
