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

import typing
import pathlib
from styxdefs import *

ANTS_INTERMODALITY_INTRASUBJECT_SH_METADATA = Metadata(
    id="4c7c5492fcbe6ca2173159c5be98ecb63525e76c.boutiques",
    name="antsIntermodalityIntrasubject.sh",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_AntsIntermodalityIntrasubjectShParamsDictNoTag = typing.TypedDict('_AntsIntermodalityIntrasubjectShParamsDictNoTag', {
    "dimension": int,
    "anatomical_t1_image": InputPathType,
    "anatomical_reference_image": typing.NotRequired[InputPathType | None],
    "scalar_image_to_match": InputPathType,
    "anatomical_t1brainmask": InputPathType,
    "transform_type": typing.Literal[0, 1, 2, 3],
    "t1_to_template_prefix": str,
    "template_space": typing.NotRequired[str | None],
    "output_prefix": str,
    "labels_in_template_space": typing.NotRequired[InputPathType | None],
    "auxiliary_scalar_images": typing.NotRequired[InputPathType | None],
    "auxiliary_dt_image": typing.NotRequired[InputPathType | None],
})
AntsIntermodalityIntrasubjectShParamsDictTagged = typing.TypedDict('AntsIntermodalityIntrasubjectShParamsDictTagged', {
    "@type": typing.Literal["ants/antsIntermodalityIntrasubject.sh"],
    "dimension": int,
    "anatomical_t1_image": InputPathType,
    "anatomical_reference_image": typing.NotRequired[InputPathType | None],
    "scalar_image_to_match": InputPathType,
    "anatomical_t1brainmask": InputPathType,
    "transform_type": typing.Literal[0, 1, 2, 3],
    "t1_to_template_prefix": str,
    "template_space": typing.NotRequired[str | None],
    "output_prefix": str,
    "labels_in_template_space": typing.NotRequired[InputPathType | None],
    "auxiliary_scalar_images": typing.NotRequired[InputPathType | None],
    "auxiliary_dt_image": typing.NotRequired[InputPathType | None],
})
AntsIntermodalityIntrasubjectShParamsDict = _AntsIntermodalityIntrasubjectShParamsDictNoTag | AntsIntermodalityIntrasubjectShParamsDictTagged


class AntsIntermodalityIntrasubjectShOutputs(typing.NamedTuple):
    """
    Output object returned when calling `AntsIntermodalityIntrasubjectShParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_transformed_image: OutputPathType
    """Output transformed image after registration."""
    output_transform: OutputPathType
    """Transformation matrix or warp field from the registration."""
    output_warped_image: OutputPathType
    """Output warped image in the template space."""


def ants_intermodality_intrasubject_sh_params(
    dimension: int,
    anatomical_t1_image: InputPathType,
    scalar_image_to_match: InputPathType,
    anatomical_t1brainmask: InputPathType,
    transform_type: typing.Literal[0, 1, 2, 3],
    t1_to_template_prefix: str,
    output_prefix: str,
    anatomical_reference_image: InputPathType | None = None,
    template_space: str | None = None,
    labels_in_template_space: InputPathType | None = None,
    auxiliary_scalar_images: InputPathType | None = None,
    auxiliary_dt_image: InputPathType | None = None,
) -> AntsIntermodalityIntrasubjectShParamsDictTagged:
    """
    Build parameters.
    
    Args:
        dimension: Dimensionality of the image, typically 3 for 3D images.
        anatomical_t1_image: Anatomical T1 image (brain or whole-head) to align\
            to.
        scalar_image_to_match: Scalar image to be matched, such as average\
            BOLD, average DWI, etc.
        anatomical_t1brainmask: Brain mask for the anatomical T1 image, should\
            mask out regions not appearing in the scalar image.
        transform_type: Type of transform: 0=rigid, 1=affine,\
            2=rigid+small_def, 3=affine+small_def.
        t1_to_template_prefix: Prefix for T1 to template transform files.
        output_prefix: Prefix for output files.
        anatomical_reference_image: Anatomical reference image to warp to,\
            often higher resolution than the anatomical T1 image.
        template_space: Template space.
        labels_in_template_space: Labels in the template space.
        auxiliary_scalar_images: Auxiliary scalar images to warp to the\
            template.
        auxiliary_dt_image: Auxiliary DT image to warp to the template.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/antsIntermodalityIntrasubject.sh",
        "dimension": dimension,
        "anatomical_t1_image": anatomical_t1_image,
        "scalar_image_to_match": scalar_image_to_match,
        "anatomical_t1brainmask": anatomical_t1brainmask,
        "transform_type": transform_type,
        "t1_to_template_prefix": t1_to_template_prefix,
        "output_prefix": output_prefix,
    }
    if anatomical_reference_image is not None:
        params["anatomical_reference_image"] = anatomical_reference_image
    if template_space is not None:
        params["template_space"] = template_space
    if labels_in_template_space is not None:
        params["labels_in_template_space"] = labels_in_template_space
    if auxiliary_scalar_images is not None:
        params["auxiliary_scalar_images"] = auxiliary_scalar_images
    if auxiliary_dt_image is not None:
        params["auxiliary_dt_image"] = auxiliary_dt_image
    return params


def ants_intermodality_intrasubject_sh_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `AntsIntermodalityIntrasubjectShParamsDict` 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("dimension", None) is None:
        raise StyxValidationError("`dimension` must not be None")
    if not isinstance(params["dimension"], int):
        raise StyxValidationError(f'`dimension` has the wrong type: Received `{type(params.get("dimension", None))}` expected `int`')
    if params.get("anatomical_t1_image", None) is None:
        raise StyxValidationError("`anatomical_t1_image` must not be None")
    if not isinstance(params["anatomical_t1_image"], (pathlib.Path, str)):
        raise StyxValidationError(f'`anatomical_t1_image` has the wrong type: Received `{type(params.get("anatomical_t1_image", None))}` expected `InputPathType`')
    if params.get("anatomical_reference_image", None) is not None:
        if not isinstance(params["anatomical_reference_image"], (pathlib.Path, str)):
            raise StyxValidationError(f'`anatomical_reference_image` has the wrong type: Received `{type(params.get("anatomical_reference_image", None))}` expected `InputPathType | None`')
    if params.get("scalar_image_to_match", None) is None:
        raise StyxValidationError("`scalar_image_to_match` must not be None")
    if not isinstance(params["scalar_image_to_match"], (pathlib.Path, str)):
        raise StyxValidationError(f'`scalar_image_to_match` has the wrong type: Received `{type(params.get("scalar_image_to_match", None))}` expected `InputPathType`')
    if params.get("anatomical_t1brainmask", None) is None:
        raise StyxValidationError("`anatomical_t1brainmask` must not be None")
    if not isinstance(params["anatomical_t1brainmask"], (pathlib.Path, str)):
        raise StyxValidationError(f'`anatomical_t1brainmask` has the wrong type: Received `{type(params.get("anatomical_t1brainmask", None))}` expected `InputPathType`')
    if params.get("transform_type", None) is None:
        raise StyxValidationError("`transform_type` must not be None")
    if not isinstance(params["transform_type"], int):
        raise StyxValidationError(f'`transform_type` has the wrong type: Received `{type(params.get("transform_type", None))}` expected `typing.Literal[0, 1, 2, 3]`')
    if params["transform_type"] not in [0, 1, 2, 3]:
        raise StyxValidationError("Parameter `transform_type` must be one of [0, 1, 2, 3]")
    if params.get("t1_to_template_prefix", None) is None:
        raise StyxValidationError("`t1_to_template_prefix` must not be None")
    if not isinstance(params["t1_to_template_prefix"], str):
        raise StyxValidationError(f'`t1_to_template_prefix` has the wrong type: Received `{type(params.get("t1_to_template_prefix", None))}` expected `str`')
    if params.get("template_space", None) is not None:
        if not isinstance(params["template_space"], str):
            raise StyxValidationError(f'`template_space` has the wrong type: Received `{type(params.get("template_space", None))}` expected `str | None`')
    if params.get("output_prefix", None) is None:
        raise StyxValidationError("`output_prefix` must not be None")
    if not isinstance(params["output_prefix"], str):
        raise StyxValidationError(f'`output_prefix` has the wrong type: Received `{type(params.get("output_prefix", None))}` expected `str`')
    if params.get("labels_in_template_space", None) is not None:
        if not isinstance(params["labels_in_template_space"], (pathlib.Path, str)):
            raise StyxValidationError(f'`labels_in_template_space` has the wrong type: Received `{type(params.get("labels_in_template_space", None))}` expected `InputPathType | None`')
    if params.get("auxiliary_scalar_images", None) is not None:
        if not isinstance(params["auxiliary_scalar_images"], (pathlib.Path, str)):
            raise StyxValidationError(f'`auxiliary_scalar_images` has the wrong type: Received `{type(params.get("auxiliary_scalar_images", None))}` expected `InputPathType | None`')
    if params.get("auxiliary_dt_image", None) is not None:
        if not isinstance(params["auxiliary_dt_image"], (pathlib.Path, str)):
            raise StyxValidationError(f'`auxiliary_dt_image` has the wrong type: Received `{type(params.get("auxiliary_dt_image", None))}` expected `InputPathType | None`')


def ants_intermodality_intrasubject_sh_cargs(
    params: AntsIntermodalityIntrasubjectShParamsDict,
    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("antsIntermodalityIntrasubject.sh")
    cargs.extend([
        "-d",
        str(params.get("dimension", None))
    ])
    cargs.extend([
        "-r",
        execution.input_file(params.get("anatomical_t1_image", None))
    ])
    if params.get("anatomical_reference_image", None) is not None:
        cargs.extend([
            "-R",
            execution.input_file(params.get("anatomical_reference_image", None))
        ])
    cargs.extend([
        "-i",
        execution.input_file(params.get("scalar_image_to_match", None))
    ])
    cargs.extend([
        "-x",
        execution.input_file(params.get("anatomical_t1brainmask", None))
    ])
    cargs.extend([
        "-t",
        str(params.get("transform_type", None))
    ])
    cargs.extend([
        "-w",
        params.get("t1_to_template_prefix", None)
    ])
    if params.get("template_space", None) is not None:
        cargs.extend([
            "-T",
            params.get("template_space", None)
        ])
    cargs.extend([
        "-o",
        params.get("output_prefix", None)
    ])
    if params.get("labels_in_template_space", None) is not None:
        cargs.extend([
            "-l",
            execution.input_file(params.get("labels_in_template_space", None))
        ])
    if params.get("auxiliary_scalar_images", None) is not None:
        cargs.extend([
            "-a",
            execution.input_file(params.get("auxiliary_scalar_images", None))
        ])
    if params.get("auxiliary_dt_image", None) is not None:
        cargs.extend([
            "-b",
            execution.input_file(params.get("auxiliary_dt_image", None))
        ])
    return cargs


def ants_intermodality_intrasubject_sh_outputs(
    params: AntsIntermodalityIntrasubjectShParamsDict,
    execution: Execution,
) -> AntsIntermodalityIntrasubjectShOutputs:
    """
    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 = AntsIntermodalityIntrasubjectShOutputs(
        root=execution.output_file("."),
        output_transformed_image=execution.output_file(params.get("output_prefix", None) + "Transformed.nii.gz"),
        output_transform=execution.output_file(params.get("output_prefix", None) + "Transform.mat"),
        output_warped_image=execution.output_file(params.get("output_prefix", None) + "Warped.nii.gz"),
    )
    return ret


def ants_intermodality_intrasubject_sh_execute(
    params: AntsIntermodalityIntrasubjectShParamsDict,
    runner: Runner | None = None,
) -> AntsIntermodalityIntrasubjectShOutputs:
    """
    antsIntermodalityIntrasubject.sh
    
    Performs registration between a scalar image and a T1 image.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsIntermodalityIntrasubjectShOutputs`).
    """
    ants_intermodality_intrasubject_sh_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(ANTS_INTERMODALITY_INTRASUBJECT_SH_METADATA)
    params = execution.params(params)
    cargs = ants_intermodality_intrasubject_sh_cargs(params, execution)
    ret = ants_intermodality_intrasubject_sh_outputs(params, execution)
    execution.run(cargs)
    return ret


def ants_intermodality_intrasubject_sh(
    dimension: int,
    anatomical_t1_image: InputPathType,
    scalar_image_to_match: InputPathType,
    anatomical_t1brainmask: InputPathType,
    transform_type: typing.Literal[0, 1, 2, 3],
    t1_to_template_prefix: str,
    output_prefix: str,
    anatomical_reference_image: InputPathType | None = None,
    template_space: str | None = None,
    labels_in_template_space: InputPathType | None = None,
    auxiliary_scalar_images: InputPathType | None = None,
    auxiliary_dt_image: InputPathType | None = None,
    runner: Runner | None = None,
) -> AntsIntermodalityIntrasubjectShOutputs:
    """
    antsIntermodalityIntrasubject.sh
    
    Performs registration between a scalar image and a T1 image.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        dimension: Dimensionality of the image, typically 3 for 3D images.
        anatomical_t1_image: Anatomical T1 image (brain or whole-head) to align\
            to.
        scalar_image_to_match: Scalar image to be matched, such as average\
            BOLD, average DWI, etc.
        anatomical_t1brainmask: Brain mask for the anatomical T1 image, should\
            mask out regions not appearing in the scalar image.
        transform_type: Type of transform: 0=rigid, 1=affine,\
            2=rigid+small_def, 3=affine+small_def.
        t1_to_template_prefix: Prefix for T1 to template transform files.
        output_prefix: Prefix for output files.
        anatomical_reference_image: Anatomical reference image to warp to,\
            often higher resolution than the anatomical T1 image.
        template_space: Template space.
        labels_in_template_space: Labels in the template space.
        auxiliary_scalar_images: Auxiliary scalar images to warp to the\
            template.
        auxiliary_dt_image: Auxiliary DT image to warp to the template.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsIntermodalityIntrasubjectShOutputs`).
    """
    params = ants_intermodality_intrasubject_sh_params(
        dimension=dimension,
        anatomical_t1_image=anatomical_t1_image,
        anatomical_reference_image=anatomical_reference_image,
        scalar_image_to_match=scalar_image_to_match,
        anatomical_t1brainmask=anatomical_t1brainmask,
        transform_type=transform_type,
        t1_to_template_prefix=t1_to_template_prefix,
        template_space=template_space,
        output_prefix=output_prefix,
        labels_in_template_space=labels_in_template_space,
        auxiliary_scalar_images=auxiliary_scalar_images,
        auxiliary_dt_image=auxiliary_dt_image,
    )
    return ants_intermodality_intrasubject_sh_execute(params, runner)


__all__ = [
    "ANTS_INTERMODALITY_INTRASUBJECT_SH_METADATA",
    "AntsIntermodalityIntrasubjectShOutputs",
    "AntsIntermodalityIntrasubjectShParamsDict",
    "AntsIntermodalityIntrasubjectShParamsDictTagged",
    "ants_intermodality_intrasubject_sh",
    "ants_intermodality_intrasubject_sh_execute",
    "ants_intermodality_intrasubject_sh_params",
]
