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

import typing
import pathlib
from styxdefs import *

ANTS_CORTICAL_THICKNESS_SH_METADATA = Metadata(
    id="1af08fb76713108fbe119513e0ee5dea823c10df.boutiques",
    name="antsCorticalThickness.sh",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


AntsCorticalThicknessShParameters = typing.TypedDict('AntsCorticalThicknessShParameters', {
    "__STYX_TYPE__": typing.Literal["antsCorticalThickness.sh"],
    "image_dimension": typing.Literal[2, 3],
    "anatomical_image": InputPathType,
    "brain_template": InputPathType,
    "brain_extraction_probability_mask": InputPathType,
    "brain_segmentation_priors": str,
    "output_prefix": str,
    "image_file_suffix": typing.NotRequired[str | None],
    "template_for_t1_registration": typing.NotRequired[InputPathType | None],
    "extraction_registration_mask": typing.NotRequired[InputPathType | None],
    "keep_temporary_files": typing.NotRequired[typing.Literal[0, 1] | None],
    "denoise_anatomical_images": typing.NotRequired[typing.Literal[0, 1] | None],
    "max_iterations_for_registration": typing.NotRequired[str | None],
    "atropos_prior_segmentation_weight": typing.NotRequired[float | None],
    "number_of_segmentation_iterations": typing.NotRequired[int | None],
    "posterior_formulation": typing.NotRequired[str | None],
    "use_floating_point_precision": typing.NotRequired[typing.Literal[0, 1] | None],
    "use_random_seeding": typing.NotRequired[typing.Literal[0, 1] | None],
    "use_b_spline_smoothing": typing.NotRequired[typing.Literal[0, 1] | None],
    "cortical_thickness_prior_image": typing.NotRequired[InputPathType | None],
    "label_propagation": typing.NotRequired[str | None],
    "additional_priors_for_thickness": typing.NotRequired[str | None],
    "use_quick_registration_parameters": typing.NotRequired[typing.Literal[0, 1] | None],
    "atropos_iterations": typing.NotRequired[int | None],
    "script_stage_to_run": typing.NotRequired[int | None],
    "test_debug_mode": typing.NotRequired[int | None],
})


def dyn_cargs(
    t: str,
) -> typing.Any:
    """
    Get build cargs function by command type.
    
    Args:
        t: Command type.
    Returns:
        Build cargs function.
    """
    return {
        "antsCorticalThickness.sh": ants_cortical_thickness_sh_cargs,
    }.get(t)


def dyn_outputs(
    t: str,
) -> typing.Any:
    """
    Get build outputs function by command type.
    
    Args:
        t: Command type.
    Returns:
        Build outputs function.
    """
    return {
        "antsCorticalThickness.sh": ants_cortical_thickness_sh_outputs,
    }.get(t)


class AntsCorticalThicknessShOutputs(typing.NamedTuple):
    """
    Output object returned when calling `ants_cortical_thickness_sh(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    cortical_thickness: OutputPathType
    """The output cortical thickness map."""
    brain_extraction_mask: OutputPathType
    """The brain extraction mask."""
    brain_segmentation: OutputPathType
    """The brain segmentation image."""
    segmentation_posteriors: OutputPathType
    """The segmentation posteriors for different tissue classes."""


def ants_cortical_thickness_sh_params(
    image_dimension: typing.Literal[2, 3],
    anatomical_image: InputPathType,
    brain_template: InputPathType,
    brain_extraction_probability_mask: InputPathType,
    brain_segmentation_priors: str,
    output_prefix: str,
    image_file_suffix: str | None = None,
    template_for_t1_registration: InputPathType | None = None,
    extraction_registration_mask: InputPathType | None = None,
    keep_temporary_files: typing.Literal[0, 1] | None = None,
    denoise_anatomical_images: typing.Literal[0, 1] | None = None,
    max_iterations_for_registration: str | None = None,
    atropos_prior_segmentation_weight: float | None = None,
    number_of_segmentation_iterations: int | None = None,
    posterior_formulation: str | None = None,
    use_floating_point_precision: typing.Literal[0, 1] | None = None,
    use_random_seeding: typing.Literal[0, 1] | None = None,
    use_b_spline_smoothing: typing.Literal[0, 1] | None = None,
    cortical_thickness_prior_image: InputPathType | None = None,
    label_propagation: str | None = None,
    additional_priors_for_thickness: str | None = None,
    use_quick_registration_parameters: typing.Literal[0, 1] | None = None,
    atropos_iterations: int | None = None,
    script_stage_to_run: int | None = None,
    test_debug_mode: int | None = None,
) -> AntsCorticalThicknessShParameters:
    """
    Build parameters.
    
    Args:
        image_dimension: 2 or 3 for 2- or 3-dimensional image.
        anatomical_image: Structural intensity image, typically T1.
        brain_template: Anatomical intensity template. This template is not\
            skull-stripped.
        brain_extraction_probability_mask: Brain probability mask in the\
            segmentation template space. A binary mask is acceptable.
        brain_segmentation_priors: Tissue probability priors corresponding to\
            the template image specified with the -e option. At least four priors\
            must exist, corresponding to CSF, Cortical GM, WM, Subcortical GM.
        output_prefix: Output prefix for the generated filenames.
        image_file_suffix: Any of the standard ITK IO formats e.g. nrrd, nii.gz\
            (default), mhd.
        template_for_t1_registration: Anatomical intensity template. This\
            template must be skull-stripped.
        extraction_registration_mask: Binary metric mask defined in the\
            segmentation template space (-e). Only used in brain extraction\
            registration.
        keep_temporary_files: Keep brain extraction/segmentation warps, etc\
            (default = 0).
        denoise_anatomical_images: Denoise anatomical images (default = 0).
        max_iterations_for_registration: ANTS registration max iterations\
            (default = 100x100x70x20).
        atropos_prior_segmentation_weight: Atropos spatial prior probability\
            weight for the segmentation (default = 0.25).
        number_of_segmentation_iterations: N4 -> Atropos -> N4 iterations\
            during segmentation (default = 3).
        posterior_formulation: Atropos posterior formulation and whether or not\
            to use mixture model proportions. e.g 'Socrates[ 1 ]' (default) or\
            'Aristotle[ 1 ]'.
        use_floating_point_precision: Use single float precision in\
            registrations (default = 0).
        use_random_seeding: Use random number generated from system clock\
            (default = 1).
        use_b_spline_smoothing: Use B-spline SyN for registrations and B-spline\
            exponential mapping in DiReCT (default = 0).
        cortical_thickness_prior_image: Cortical thickness prior image in the\
            template space, with an estimated upper limit of cortical thickness at\
            each voxel.
        label_propagation: Incorporate a distance prior on the posterior\
            formulation.
        additional_priors_for_thickness: Add segmentation classes for thickness\
            estimation.
        use_quick_registration_parameters: Use antsRegistrationSyNQuick.sh for\
            registrations (default = 0).
        atropos_iterations: Number of iterations within Atropos (default = 5).
        script_stage_to_run: Which stage of ACT to run (default = 0, run all).
        test_debug_mode: If > 0, runs a faster version of the script. Only for\
            testing (default = 0).
    Returns:
        Parameter dictionary
    """
    params = {
        "__STYXTYPE__": "antsCorticalThickness.sh",
        "image_dimension": image_dimension,
        "anatomical_image": anatomical_image,
        "brain_template": brain_template,
        "brain_extraction_probability_mask": brain_extraction_probability_mask,
        "brain_segmentation_priors": brain_segmentation_priors,
        "output_prefix": output_prefix,
    }
    if image_file_suffix is not None:
        params["image_file_suffix"] = image_file_suffix
    if template_for_t1_registration is not None:
        params["template_for_t1_registration"] = template_for_t1_registration
    if extraction_registration_mask is not None:
        params["extraction_registration_mask"] = extraction_registration_mask
    if keep_temporary_files is not None:
        params["keep_temporary_files"] = keep_temporary_files
    if denoise_anatomical_images is not None:
        params["denoise_anatomical_images"] = denoise_anatomical_images
    if max_iterations_for_registration is not None:
        params["max_iterations_for_registration"] = max_iterations_for_registration
    if atropos_prior_segmentation_weight is not None:
        params["atropos_prior_segmentation_weight"] = atropos_prior_segmentation_weight
    if number_of_segmentation_iterations is not None:
        params["number_of_segmentation_iterations"] = number_of_segmentation_iterations
    if posterior_formulation is not None:
        params["posterior_formulation"] = posterior_formulation
    if use_floating_point_precision is not None:
        params["use_floating_point_precision"] = use_floating_point_precision
    if use_random_seeding is not None:
        params["use_random_seeding"] = use_random_seeding
    if use_b_spline_smoothing is not None:
        params["use_b_spline_smoothing"] = use_b_spline_smoothing
    if cortical_thickness_prior_image is not None:
        params["cortical_thickness_prior_image"] = cortical_thickness_prior_image
    if label_propagation is not None:
        params["label_propagation"] = label_propagation
    if additional_priors_for_thickness is not None:
        params["additional_priors_for_thickness"] = additional_priors_for_thickness
    if use_quick_registration_parameters is not None:
        params["use_quick_registration_parameters"] = use_quick_registration_parameters
    if atropos_iterations is not None:
        params["atropos_iterations"] = atropos_iterations
    if script_stage_to_run is not None:
        params["script_stage_to_run"] = script_stage_to_run
    if test_debug_mode is not None:
        params["test_debug_mode"] = test_debug_mode
    return params


def ants_cortical_thickness_sh_cargs(
    params: AntsCorticalThicknessShParameters,
    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("antsCorticalThickness.sh")
    cargs.extend([
        "-d",
        str(params.get("image_dimension"))
    ])
    cargs.extend([
        "-a",
        execution.input_file(params.get("anatomical_image"))
    ])
    cargs.extend([
        "-e",
        execution.input_file(params.get("brain_template"))
    ])
    cargs.extend([
        "-m",
        execution.input_file(params.get("brain_extraction_probability_mask"))
    ])
    cargs.extend([
        "-p",
        params.get("brain_segmentation_priors")
    ])
    cargs.extend([
        "-o",
        params.get("output_prefix")
    ])
    if params.get("image_file_suffix") is not None:
        cargs.extend([
            "-s",
            params.get("image_file_suffix")
        ])
    if params.get("template_for_t1_registration") is not None:
        cargs.extend([
            "-t",
            execution.input_file(params.get("template_for_t1_registration"))
        ])
    if params.get("extraction_registration_mask") is not None:
        cargs.extend([
            "-f",
            execution.input_file(params.get("extraction_registration_mask"))
        ])
    if params.get("keep_temporary_files") is not None:
        cargs.extend([
            "-k",
            str(params.get("keep_temporary_files"))
        ])
    if params.get("denoise_anatomical_images") is not None:
        cargs.extend([
            "-g",
            str(params.get("denoise_anatomical_images"))
        ])
    if params.get("max_iterations_for_registration") is not None:
        cargs.extend([
            "-i",
            params.get("max_iterations_for_registration")
        ])
    if params.get("atropos_prior_segmentation_weight") is not None:
        cargs.extend([
            "-w",
            str(params.get("atropos_prior_segmentation_weight"))
        ])
    if params.get("number_of_segmentation_iterations") is not None:
        cargs.extend([
            "-n",
            str(params.get("number_of_segmentation_iterations"))
        ])
    if params.get("posterior_formulation") is not None:
        cargs.extend([
            "-b",
            params.get("posterior_formulation")
        ])
    if params.get("use_floating_point_precision") is not None:
        cargs.extend([
            "-j",
            str(params.get("use_floating_point_precision"))
        ])
    if params.get("use_random_seeding") is not None:
        cargs.extend([
            "-u",
            str(params.get("use_random_seeding"))
        ])
    if params.get("use_b_spline_smoothing") is not None:
        cargs.extend([
            "-v",
            str(params.get("use_b_spline_smoothing"))
        ])
    if params.get("cortical_thickness_prior_image") is not None:
        cargs.extend([
            "-r",
            execution.input_file(params.get("cortical_thickness_prior_image"))
        ])
    if params.get("label_propagation") is not None:
        cargs.extend([
            "-l",
            params.get("label_propagation")
        ])
    if params.get("additional_priors_for_thickness") is not None:
        cargs.extend([
            "-c",
            params.get("additional_priors_for_thickness")
        ])
    if params.get("use_quick_registration_parameters") is not None:
        cargs.extend([
            "-q",
            str(params.get("use_quick_registration_parameters"))
        ])
    if params.get("atropos_iterations") is not None:
        cargs.extend([
            "-x",
            str(params.get("atropos_iterations"))
        ])
    if params.get("script_stage_to_run") is not None:
        cargs.extend([
            "-y",
            str(params.get("script_stage_to_run"))
        ])
    if params.get("test_debug_mode") is not None:
        cargs.extend([
            "-z",
            str(params.get("test_debug_mode"))
        ])
    return cargs


def ants_cortical_thickness_sh_outputs(
    params: AntsCorticalThicknessShParameters,
    execution: Execution,
) -> AntsCorticalThicknessShOutputs:
    """
    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 = AntsCorticalThicknessShOutputs(
        root=execution.output_file("."),
        cortical_thickness=execution.output_file(params.get("output_prefix") + "CorticalThickness.nii.gz"),
        brain_extraction_mask=execution.output_file(params.get("output_prefix") + "BrainExtractionMask.nii.gz"),
        brain_segmentation=execution.output_file(params.get("output_prefix") + "BrainSegmentation.nii.gz"),
        segmentation_posteriors=execution.output_file(params.get("output_prefix") + "BrainSegmentationPosteriors*.nii.gz"),
    )
    return ret


def ants_cortical_thickness_sh_execute(
    params: AntsCorticalThicknessShParameters,
    execution: Execution,
) -> AntsCorticalThicknessShOutputs:
    """
    This script performs T1 anatomical brain processing including brain extraction,
    brain n-tissue segmentation, cortical thickness estimation, and optional
    registration to a template.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        execution: The execution object.
    Returns:
        NamedTuple of outputs (described in `AntsCorticalThicknessShOutputs`).
    """
    params = execution.params(params)
    cargs = ants_cortical_thickness_sh_cargs(params, execution)
    ret = ants_cortical_thickness_sh_outputs(params, execution)
    execution.run(cargs)
    return ret


def ants_cortical_thickness_sh(
    image_dimension: typing.Literal[2, 3],
    anatomical_image: InputPathType,
    brain_template: InputPathType,
    brain_extraction_probability_mask: InputPathType,
    brain_segmentation_priors: str,
    output_prefix: str,
    image_file_suffix: str | None = None,
    template_for_t1_registration: InputPathType | None = None,
    extraction_registration_mask: InputPathType | None = None,
    keep_temporary_files: typing.Literal[0, 1] | None = None,
    denoise_anatomical_images: typing.Literal[0, 1] | None = None,
    max_iterations_for_registration: str | None = None,
    atropos_prior_segmentation_weight: float | None = None,
    number_of_segmentation_iterations: int | None = None,
    posterior_formulation: str | None = None,
    use_floating_point_precision: typing.Literal[0, 1] | None = None,
    use_random_seeding: typing.Literal[0, 1] | None = None,
    use_b_spline_smoothing: typing.Literal[0, 1] | None = None,
    cortical_thickness_prior_image: InputPathType | None = None,
    label_propagation: str | None = None,
    additional_priors_for_thickness: str | None = None,
    use_quick_registration_parameters: typing.Literal[0, 1] | None = None,
    atropos_iterations: int | None = None,
    script_stage_to_run: int | None = None,
    test_debug_mode: int | None = None,
    runner: Runner | None = None,
) -> AntsCorticalThicknessShOutputs:
    """
    This script performs T1 anatomical brain processing including brain extraction,
    brain n-tissue segmentation, cortical thickness estimation, and optional
    registration to a template.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        image_dimension: 2 or 3 for 2- or 3-dimensional image.
        anatomical_image: Structural intensity image, typically T1.
        brain_template: Anatomical intensity template. This template is not\
            skull-stripped.
        brain_extraction_probability_mask: Brain probability mask in the\
            segmentation template space. A binary mask is acceptable.
        brain_segmentation_priors: Tissue probability priors corresponding to\
            the template image specified with the -e option. At least four priors\
            must exist, corresponding to CSF, Cortical GM, WM, Subcortical GM.
        output_prefix: Output prefix for the generated filenames.
        image_file_suffix: Any of the standard ITK IO formats e.g. nrrd, nii.gz\
            (default), mhd.
        template_for_t1_registration: Anatomical intensity template. This\
            template must be skull-stripped.
        extraction_registration_mask: Binary metric mask defined in the\
            segmentation template space (-e). Only used in brain extraction\
            registration.
        keep_temporary_files: Keep brain extraction/segmentation warps, etc\
            (default = 0).
        denoise_anatomical_images: Denoise anatomical images (default = 0).
        max_iterations_for_registration: ANTS registration max iterations\
            (default = 100x100x70x20).
        atropos_prior_segmentation_weight: Atropos spatial prior probability\
            weight for the segmentation (default = 0.25).
        number_of_segmentation_iterations: N4 -> Atropos -> N4 iterations\
            during segmentation (default = 3).
        posterior_formulation: Atropos posterior formulation and whether or not\
            to use mixture model proportions. e.g 'Socrates[ 1 ]' (default) or\
            'Aristotle[ 1 ]'.
        use_floating_point_precision: Use single float precision in\
            registrations (default = 0).
        use_random_seeding: Use random number generated from system clock\
            (default = 1).
        use_b_spline_smoothing: Use B-spline SyN for registrations and B-spline\
            exponential mapping in DiReCT (default = 0).
        cortical_thickness_prior_image: Cortical thickness prior image in the\
            template space, with an estimated upper limit of cortical thickness at\
            each voxel.
        label_propagation: Incorporate a distance prior on the posterior\
            formulation.
        additional_priors_for_thickness: Add segmentation classes for thickness\
            estimation.
        use_quick_registration_parameters: Use antsRegistrationSyNQuick.sh for\
            registrations (default = 0).
        atropos_iterations: Number of iterations within Atropos (default = 5).
        script_stage_to_run: Which stage of ACT to run (default = 0, run all).
        test_debug_mode: If > 0, runs a faster version of the script. Only for\
            testing (default = 0).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsCorticalThicknessShOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(ANTS_CORTICAL_THICKNESS_SH_METADATA)
    params = ants_cortical_thickness_sh_params(
        image_dimension=image_dimension,
        anatomical_image=anatomical_image,
        brain_template=brain_template,
        brain_extraction_probability_mask=brain_extraction_probability_mask,
        brain_segmentation_priors=brain_segmentation_priors,
        output_prefix=output_prefix,
        image_file_suffix=image_file_suffix,
        template_for_t1_registration=template_for_t1_registration,
        extraction_registration_mask=extraction_registration_mask,
        keep_temporary_files=keep_temporary_files,
        denoise_anatomical_images=denoise_anatomical_images,
        max_iterations_for_registration=max_iterations_for_registration,
        atropos_prior_segmentation_weight=atropos_prior_segmentation_weight,
        number_of_segmentation_iterations=number_of_segmentation_iterations,
        posterior_formulation=posterior_formulation,
        use_floating_point_precision=use_floating_point_precision,
        use_random_seeding=use_random_seeding,
        use_b_spline_smoothing=use_b_spline_smoothing,
        cortical_thickness_prior_image=cortical_thickness_prior_image,
        label_propagation=label_propagation,
        additional_priors_for_thickness=additional_priors_for_thickness,
        use_quick_registration_parameters=use_quick_registration_parameters,
        atropos_iterations=atropos_iterations,
        script_stage_to_run=script_stage_to_run,
        test_debug_mode=test_debug_mode,
    )
    return ants_cortical_thickness_sh_execute(params, execution)


__all__ = [
    "ANTS_CORTICAL_THICKNESS_SH_METADATA",
    "AntsCorticalThicknessShOutputs",
    "AntsCorticalThicknessShParameters",
    "ants_cortical_thickness_sh",
    "ants_cortical_thickness_sh_params",
]
