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

import typing
import pathlib
from styxdefs import *

SURFACE_AFFINE_REGRESSION_METADATA = Metadata(
    id="250a34f2b42b75612a852d89d3d7eb774e8fa266.boutiques",
    name="surface-affine-regression",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


SurfaceAffineRegressionParameters = typing.TypedDict('SurfaceAffineRegressionParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/surface-affine-regression"]],
    "source": InputPathType,
    "target": InputPathType,
    "affine_out": str,
})
SurfaceAffineRegressionParametersTagged = typing.TypedDict('SurfaceAffineRegressionParametersTagged', {
    "@type": typing.Literal["workbench/surface-affine-regression"],
    "source": InputPathType,
    "target": InputPathType,
    "affine_out": str,
})


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


def surface_affine_regression_params(
    source: InputPathType,
    target: InputPathType,
    affine_out: str,
) -> SurfaceAffineRegressionParametersTagged:
    """
    Build parameters.
    
    Args:
        source: the surface to warp.
        target: the surface to match the coordinates of.
        affine_out: output - the output affine file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/surface-affine-regression",
        "source": source,
        "target": target,
        "affine_out": affine_out,
    }
    return params


def surface_affine_regression_cargs(
    params: SurfaceAffineRegressionParameters,
    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("-surface-affine-regression")
    cargs.append(execution.input_file(params.get("source", None)))
    cargs.append(execution.input_file(params.get("target", None)))
    cargs.append(params.get("affine_out", None))
    return cargs


def surface_affine_regression_outputs(
    params: SurfaceAffineRegressionParameters,
    execution: Execution,
) -> SurfaceAffineRegressionOutputs:
    """
    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 = SurfaceAffineRegressionOutputs(
        root=execution.output_file("."),
    )
    return ret


def surface_affine_regression_execute(
    params: SurfaceAffineRegressionParameters,
    runner: Runner | None = None,
) -> SurfaceAffineRegressionOutputs:
    """
    surface-affine-regression
    
    Regress the affine transform between surfaces on the same mesh.
    
    Use linear regression to compute an affine that minimizes the sum of squares
    of the coordinate differences between the target surface and the warped
    source surface. Note that this has a bias to shrink the surface that is
    being warped. The output is written as a NIFTI 'world' matrix, see
    -convert-affine to convert it for use in other software.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceAffineRegressionOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(SURFACE_AFFINE_REGRESSION_METADATA)
    params = execution.params(params)
    cargs = surface_affine_regression_cargs(params, execution)
    ret = surface_affine_regression_outputs(params, execution)
    execution.run(cargs)
    return ret


def surface_affine_regression(
    source: InputPathType,
    target: InputPathType,
    affine_out: str,
    runner: Runner | None = None,
) -> SurfaceAffineRegressionOutputs:
    """
    surface-affine-regression
    
    Regress the affine transform between surfaces on the same mesh.
    
    Use linear regression to compute an affine that minimizes the sum of squares
    of the coordinate differences between the target surface and the warped
    source surface. Note that this has a bias to shrink the surface that is
    being warped. The output is written as a NIFTI 'world' matrix, see
    -convert-affine to convert it for use in other software.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        source: the surface to warp.
        target: the surface to match the coordinates of.
        affine_out: output - the output affine file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceAffineRegressionOutputs`).
    """
    params = surface_affine_regression_params(
        source=source,
        target=target,
        affine_out=affine_out,
    )
    return surface_affine_regression_execute(params, runner)


__all__ = [
    "SURFACE_AFFINE_REGRESSION_METADATA",
    "SurfaceAffineRegressionOutputs",
    "surface_affine_regression",
    "surface_affine_regression_execute",
    "surface_affine_regression_params",
]
