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

import typing
import pathlib
from styxdefs import *

ANTS_APPLY_TRANSFORMS_TO_POINTS_METADATA = Metadata(
    id="e37a5b8e4d1b3bc448995c7e8c944e1559bba40f.boutiques",
    name="antsApplyTransformsToPoints",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_AntsApplyTransformsToPointsSingleTransformParamsDictNoTag = typing.TypedDict('_AntsApplyTransformsToPointsSingleTransformParamsDictNoTag', {})
AntsApplyTransformsToPointsSingleTransformParamsDictTagged = typing.TypedDict('AntsApplyTransformsToPointsSingleTransformParamsDictTagged', {
    "@type": typing.Literal["single_transform"],
})
AntsApplyTransformsToPointsSingleTransformParamsDict = _AntsApplyTransformsToPointsSingleTransformParamsDictNoTag | AntsApplyTransformsToPointsSingleTransformParamsDictTagged


_AntsApplyTransformsToPointsInverseTransformParamsDictNoTag = typing.TypedDict('_AntsApplyTransformsToPointsInverseTransformParamsDictNoTag', {
    "transform_file": InputPathType,
})
AntsApplyTransformsToPointsInverseTransformParamsDictTagged = typing.TypedDict('AntsApplyTransformsToPointsInverseTransformParamsDictTagged', {
    "@type": typing.Literal["inverse_transform"],
    "transform_file": InputPathType,
})
AntsApplyTransformsToPointsInverseTransformParamsDict = _AntsApplyTransformsToPointsInverseTransformParamsDictNoTag | AntsApplyTransformsToPointsInverseTransformParamsDictTagged


_AntsApplyTransformsToPointsParamsDictNoTag = typing.TypedDict('_AntsApplyTransformsToPointsParamsDictNoTag', {
    "dimensionality": typing.NotRequired[typing.Literal[2, 3] | None],
    "precision": typing.NotRequired[bool | None],
    "forantsr": typing.NotRequired[bool | None],
    "input": InputPathType,
    "output": str,
    "transform": typing.NotRequired[typing.Union[AntsApplyTransformsToPointsSingleTransformParamsDictTagged, AntsApplyTransformsToPointsInverseTransformParamsDictTagged] | None],
})
AntsApplyTransformsToPointsParamsDictTagged = typing.TypedDict('AntsApplyTransformsToPointsParamsDictTagged', {
    "@type": typing.Literal["ants/antsApplyTransformsToPoints"],
    "dimensionality": typing.NotRequired[typing.Literal[2, 3] | None],
    "precision": typing.NotRequired[bool | None],
    "forantsr": typing.NotRequired[bool | None],
    "input": InputPathType,
    "output": str,
    "transform": typing.NotRequired[typing.Union[AntsApplyTransformsToPointsSingleTransformParamsDictTagged, AntsApplyTransformsToPointsInverseTransformParamsDictTagged] | None],
})
AntsApplyTransformsToPointsParamsDict = _AntsApplyTransformsToPointsParamsDictNoTag | AntsApplyTransformsToPointsParamsDictTagged


def ants_apply_transforms_to_points_transform_cargs_dyn_fn(
    t: str,
) -> typing.Any:
    """
    Get build cargs function by command type.
    
    Args:
        t: Command type.
    Returns:
        Build cargs function.
    """
    return {
        "single_transform": ants_apply_transforms_to_points_single_transform_cargs,
        "inverse_transform": ants_apply_transforms_to_points_inverse_transform_cargs,
    }.get(t)


def ants_apply_transforms_to_points_transform_validate_dyn_fn(
    t: str,
) -> typing.Any:
    """
    Get validate params function by command type.
    
    Args:
        t: Command type.
    Returns:
        Validate params function.
    """
    return {
        "single_transform": ants_apply_transforms_to_points_single_transform_validate,
        "inverse_transform": ants_apply_transforms_to_points_inverse_transform_validate,
    }.get(t)


def ants_apply_transforms_to_points_single_transform(
) -> AntsApplyTransformsToPointsSingleTransformParamsDictTagged:
    """
    Build parameters.
    
    Args:
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "single_transform",
    }
    return params


def ants_apply_transforms_to_points_single_transform_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `AntsApplyTransformsToPointsSingleTransformParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')


def ants_apply_transforms_to_points_single_transform_cargs(
    params: AntsApplyTransformsToPointsSingleTransformParamsDict,
    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("[TRANSFORM]")
    return cargs


def ants_apply_transforms_to_points_inverse_transform(
    transform_file: InputPathType,
) -> AntsApplyTransformsToPointsInverseTransformParamsDictTagged:
    """
    Build parameters.
    
    Args:
        transform_file:.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "inverse_transform",
        "transform_file": transform_file,
    }
    return params


def ants_apply_transforms_to_points_inverse_transform_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `AntsApplyTransformsToPointsInverseTransformParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("transform_file", None) is None:
        raise StyxValidationError("`transform_file` must not be None")
    if not isinstance(params["transform_file"], (pathlib.Path, str)):
        raise StyxValidationError(f'`transform_file` has the wrong type: Received `{type(params.get("transform_file", None))}` expected `InputPathType`')


def ants_apply_transforms_to_points_inverse_transform_cargs(
    params: AntsApplyTransformsToPointsInverseTransformParamsDict,
    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(execution.input_file(params.get("transform_file", None)) + ",1")
    return cargs


class AntsApplyTransformsToPointsOutputs(typing.NamedTuple):
    """
    Output object returned when calling `AntsApplyTransformsToPointsParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    warped_points: OutputPathType
    """The output is the CSV file containing warped points."""


def ants_apply_transforms_to_points_params(
    input_: InputPathType,
    output: str,
    dimensionality: typing.Literal[2, 3] | None = None,
    precision: bool | None = None,
    forantsr: bool | None = None,
    transform: typing.Union[AntsApplyTransformsToPointsSingleTransformParamsDictTagged, AntsApplyTransformsToPointsInverseTransformParamsDictTagged] | None = None,
) -> AntsApplyTransformsToPointsParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: Input CSV file with columns including x,y,z,t headers that\
            define the points in physical space, or a 2D .mha binary image file.
        output: Output the warped points to a CSV file.
        dimensionality: This option forces the points to be treated as a\
            specified-dimensionality.
        precision: Use double precision.
        forantsr: Set true for ANTsR IO.
        transform: Transform file(s) to apply to the input points. Uses an\
            inverse transform if specified as [transformFileName,1].
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/antsApplyTransformsToPoints",
        "input": input_,
        "output": output,
    }
    if dimensionality is not None:
        params["dimensionality"] = dimensionality
    if precision is not None:
        params["precision"] = precision
    if forantsr is not None:
        params["forantsr"] = forantsr
    if transform is not None:
        params["transform"] = transform
    return params


def ants_apply_transforms_to_points_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `AntsApplyTransformsToPointsParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("dimensionality", None) is not None:
        if not isinstance(params["dimensionality"], int):
            raise StyxValidationError(f'`dimensionality` has the wrong type: Received `{type(params.get("dimensionality", None))}` expected `typing.Literal[2, 3] | None`')
        if params["dimensionality"] not in [2, 3]:
            raise StyxValidationError("Parameter `dimensionality` must be one of [2, 3]")
    if params.get("precision", None) is not None:
        if not isinstance(params["precision"], bool):
            raise StyxValidationError(f'`precision` has the wrong type: Received `{type(params.get("precision", None))}` expected `bool | None`')
    if params.get("forantsr", None) is not None:
        if not isinstance(params["forantsr"], bool):
            raise StyxValidationError(f'`forantsr` has the wrong type: Received `{type(params.get("forantsr", None))}` expected `bool | None`')
    if params.get("input", None) is None:
        raise StyxValidationError("`input` must not be None")
    if not isinstance(params["input"], (pathlib.Path, str)):
        raise StyxValidationError(f'`input` has the wrong type: Received `{type(params.get("input", None))}` expected `InputPathType`')
    if params.get("output", None) is None:
        raise StyxValidationError("`output` must not be None")
    if not isinstance(params["output"], str):
        raise StyxValidationError(f'`output` has the wrong type: Received `{type(params.get("output", None))}` expected `str`')
    if params.get("transform", None) is not None:
        if not isinstance(params["transform"], dict):
            raise StyxValidationError(f'Params object has the wrong type \'{type(params["transform"])}\'')
        if "@type" not in params["transform"]:
            raise StyxValidationError("Params object is missing `@type`")
        if params["transform"]["@type"] not in ["single_transform", "inverse_transform"]:
            raise StyxValidationError("Parameter `transform`s `@type` must be one of [\"single_transform\", \"inverse_transform\"]")
        ants_apply_transforms_to_points_transform_validate_dyn_fn(params["transform"]["@type"])(params["transform"])


def ants_apply_transforms_to_points_cargs(
    params: AntsApplyTransformsToPointsParamsDict,
    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("antsApplyTransformsToPoints")
    if params.get("dimensionality", None) is not None:
        cargs.extend([
            "--dimensionality",
            str(params.get("dimensionality", None))
        ])
    if params.get("precision", None) is not None:
        cargs.extend([
            "--precision",
            ("1" if params.get("precision", None) else "0")
        ])
    if params.get("forantsr", None) is not None:
        cargs.extend([
            "--forantsr",
            ("1" if params.get("forantsr", None) else "0")
        ])
    cargs.extend([
        "-i",
        execution.input_file(params.get("input", None))
    ])
    cargs.extend([
        "-o",
        params.get("output", None)
    ])
    if params.get("transform", None) is not None:
        cargs.extend([
            "-t",
            *ants_apply_transforms_to_points_transform_cargs_dyn_fn(params.get("transform", None)["@type"])(params.get("transform", None), execution)
        ])
    return cargs


def ants_apply_transforms_to_points_outputs(
    params: AntsApplyTransformsToPointsParamsDict,
    execution: Execution,
) -> AntsApplyTransformsToPointsOutputs:
    """
    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 = AntsApplyTransformsToPointsOutputs(
        root=execution.output_file("."),
        warped_points=execution.output_file(params.get("output", None)),
    )
    return ret


def ants_apply_transforms_to_points_execute(
    params: AntsApplyTransformsToPointsParamsDict,
    runner: Runner | None = None,
) -> AntsApplyTransformsToPointsOutputs:
    """
    antsApplyTransformsToPoints
    
    antsApplyTransformsToPoints, applied to an input image, transforms it
    according to a reference image and a transform (or a set of transforms). It
    reads in a CSV file with the first D columns defining the spatial location
    where the spatial location is defined in physical coordinates. The CSV file
    should have a header row.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsApplyTransformsToPointsOutputs`).
    """
    ants_apply_transforms_to_points_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(ANTS_APPLY_TRANSFORMS_TO_POINTS_METADATA)
    params = execution.params(params)
    cargs = ants_apply_transforms_to_points_cargs(params, execution)
    ret = ants_apply_transforms_to_points_outputs(params, execution)
    execution.run(cargs)
    return ret


def ants_apply_transforms_to_points(
    input_: InputPathType,
    output: str,
    dimensionality: typing.Literal[2, 3] | None = None,
    precision: bool | None = None,
    forantsr: bool | None = None,
    transform: typing.Union[AntsApplyTransformsToPointsSingleTransformParamsDictTagged, AntsApplyTransformsToPointsInverseTransformParamsDictTagged] | None = None,
    runner: Runner | None = None,
) -> AntsApplyTransformsToPointsOutputs:
    """
    antsApplyTransformsToPoints
    
    antsApplyTransformsToPoints, applied to an input image, transforms it
    according to a reference image and a transform (or a set of transforms). It
    reads in a CSV file with the first D columns defining the spatial location
    where the spatial location is defined in physical coordinates. The CSV file
    should have a header row.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        input_: Input CSV file with columns including x,y,z,t headers that\
            define the points in physical space, or a 2D .mha binary image file.
        output: Output the warped points to a CSV file.
        dimensionality: This option forces the points to be treated as a\
            specified-dimensionality.
        precision: Use double precision.
        forantsr: Set true for ANTsR IO.
        transform: Transform file(s) to apply to the input points. Uses an\
            inverse transform if specified as [transformFileName,1].
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsApplyTransformsToPointsOutputs`).
    """
    params = ants_apply_transforms_to_points_params(
        dimensionality=dimensionality,
        precision=precision,
        forantsr=forantsr,
        input_=input_,
        output=output,
        transform=transform,
    )
    return ants_apply_transforms_to_points_execute(params, runner)


__all__ = [
    "ANTS_APPLY_TRANSFORMS_TO_POINTS_METADATA",
    "AntsApplyTransformsToPointsInverseTransformParamsDict",
    "AntsApplyTransformsToPointsInverseTransformParamsDictTagged",
    "AntsApplyTransformsToPointsOutputs",
    "AntsApplyTransformsToPointsParamsDict",
    "AntsApplyTransformsToPointsParamsDictTagged",
    "AntsApplyTransformsToPointsSingleTransformParamsDict",
    "AntsApplyTransformsToPointsSingleTransformParamsDictTagged",
    "ants_apply_transforms_to_points",
    "ants_apply_transforms_to_points_execute",
    "ants_apply_transforms_to_points_inverse_transform",
    "ants_apply_transforms_to_points_params",
    "ants_apply_transforms_to_points_single_transform",
]
