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

import typing
import pathlib
from styxdefs import *

CREATE_DTICOHORT_METADATA = Metadata(
    id="b6d3b7b7d3095a9db5e406c42360be21bbfd0ce5.boutiques",
    name="CreateDTICohort",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


CreateDticohortParameters = typing.TypedDict('CreateDticohortParameters', {
    "__STYX_TYPE__": typing.Literal["CreateDTICohort"],
    "image_dimensionality": typing.NotRequired[typing.Literal[2, 3] | None],
    "dti_atlas": InputPathType,
    "label_mask_image": typing.NotRequired[str | None],
    "noise_sigma": typing.NotRequired[float | None],
    "pathology": typing.NotRequired[str | None],
    "dwi_parameters": str,
    "registered_population": typing.NotRequired[InputPathType | None],
    "output": str,
})


def dyn_cargs(
    t: str,
) -> typing.Any:
    """
    Get build cargs function by command type.
    
    Args:
        t: Command type.
    Returns:
        Build cargs function.
    """
    return {
        "CreateDTICohort": create_dticohort_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 {
        "CreateDTICohort": create_dticohort_outputs,
    }.get(t)


class CreateDticohortOutputs(typing.NamedTuple):
    """
    Output object returned when calling `create_dticohort(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_directory: OutputPathType
    """The directory where the output data will be stored."""
    filename_series: OutputPathType
    """Root name for the series of output files."""


def create_dticohort_params(
    dti_atlas: InputPathType,
    dwi_parameters: str,
    output: str,
    image_dimensionality: typing.Literal[2, 3] | None = None,
    label_mask_image: str | None = None,
    noise_sigma: float | None = None,
    pathology: str | None = None,
    registered_population: InputPathType | None = None,
) -> CreateDticohortParameters:
    """
    Build parameters.
    
    Args:
        dti_atlas: A diffusion tensor atlas image is required input for\
            creating the cohort.
        dwi_parameters: This option specifies the parameters of the output\
            diffusion-weighted images, including the directions and b-values.\
            Directions can be specified using a direction file or scheme file.
        output: The output consists of a set of diffusion-weighted images for\
            each subject. Control and experimental subject numbers can be\
            specified.
        image_dimensionality: This option forces the image to be treated as a\
            specified-dimensional image. If not specified, the program tries to\
            infer the dimensionality from the input image.
        label_mask_image: A mask image can be specified which determines the\
            region(s) to which the simulated pathology operations are applied. If\
            no mask is specified one is created by thresholding the atlas FA map at\
            0.2 unless a lower threshold is specified.
        noise_sigma: This parameter characterizes the Rician noise in the\
            original DWI images. Default value is 18.
        pathology: The user can specify the simulated pathology in a given area\
            using a label mask. Pathology is simulated by changing the eigenvalues.\
            One can specify the number of voxels affected in each region or the\
            proportion of voxels affected. Change is specified as a proportion of\
            the current eigenvalues.
        registered_population: To introduce inter-subject variability, a\
            registered DTI population to the DTI atlas is required. This is modeled\
            by PCA decomposition.
    Returns:
        Parameter dictionary
    """
    params = {
        "__STYXTYPE__": "CreateDTICohort",
        "dti_atlas": dti_atlas,
        "dwi_parameters": dwi_parameters,
        "output": output,
    }
    if image_dimensionality is not None:
        params["image_dimensionality"] = image_dimensionality
    if label_mask_image is not None:
        params["label_mask_image"] = label_mask_image
    if noise_sigma is not None:
        params["noise_sigma"] = noise_sigma
    if pathology is not None:
        params["pathology"] = pathology
    if registered_population is not None:
        params["registered_population"] = registered_population
    return params


def create_dticohort_cargs(
    params: CreateDticohortParameters,
    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("CreateDTICohort")
    if params.get("image_dimensionality") is not None:
        cargs.extend([
            "--image-dimensionality",
            str(params.get("image_dimensionality"))
        ])
    cargs.extend([
        "--dti-atlas",
        execution.input_file(params.get("dti_atlas"))
    ])
    if params.get("label_mask_image") is not None:
        cargs.extend([
            "--label-mask-image",
            params.get("label_mask_image")
        ])
    if params.get("noise_sigma") is not None:
        cargs.extend([
            "--noise-sigma",
            str(params.get("noise_sigma"))
        ])
    if params.get("pathology") is not None:
        cargs.extend([
            "--pathology",
            params.get("pathology")
        ])
    cargs.extend([
        "--dwi-parameters",
        params.get("dwi_parameters")
    ])
    if params.get("registered_population") is not None:
        cargs.extend([
            "--registered-population",
            execution.input_file(params.get("registered_population"))
        ])
    cargs.extend([
        "--output",
        params.get("output")
    ])
    return cargs


def create_dticohort_outputs(
    params: CreateDticohortParameters,
    execution: Execution,
) -> CreateDticohortOutputs:
    """
    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 = CreateDticohortOutputs(
        root=execution.output_file("."),
        output_directory=execution.output_file("[OUTPUT_DIRECTORY]"),
        filename_series=execution.output_file("[OUTPUT_DIRECTORY]/[FILENAME_SERIES_ROOT_NAME]_*.nii"),
    )
    return ret


def create_dticohort_execute(
    params: CreateDticohortParameters,
    execution: Execution,
) -> CreateDticohortOutputs:
    """
    CreateDTICohort implements the work of Van Hecke et al. to create simulated DTI
    data sets. The only difference is that all registrations (both for the input
    population and for the output population) are assumed to take place outside of
    this program.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        execution: The execution object.
    Returns:
        NamedTuple of outputs (described in `CreateDticohortOutputs`).
    """
    params = execution.params(params)
    cargs = create_dticohort_cargs(params, execution)
    ret = create_dticohort_outputs(params, execution)
    execution.run(cargs)
    return ret


def create_dticohort(
    dti_atlas: InputPathType,
    dwi_parameters: str,
    output: str,
    image_dimensionality: typing.Literal[2, 3] | None = None,
    label_mask_image: str | None = None,
    noise_sigma: float | None = None,
    pathology: str | None = None,
    registered_population: InputPathType | None = None,
    runner: Runner | None = None,
) -> CreateDticohortOutputs:
    """
    CreateDTICohort implements the work of Van Hecke et al. to create simulated DTI
    data sets. The only difference is that all registrations (both for the input
    population and for the output population) are assumed to take place outside of
    this program.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        dti_atlas: A diffusion tensor atlas image is required input for\
            creating the cohort.
        dwi_parameters: This option specifies the parameters of the output\
            diffusion-weighted images, including the directions and b-values.\
            Directions can be specified using a direction file or scheme file.
        output: The output consists of a set of diffusion-weighted images for\
            each subject. Control and experimental subject numbers can be\
            specified.
        image_dimensionality: This option forces the image to be treated as a\
            specified-dimensional image. If not specified, the program tries to\
            infer the dimensionality from the input image.
        label_mask_image: A mask image can be specified which determines the\
            region(s) to which the simulated pathology operations are applied. If\
            no mask is specified one is created by thresholding the atlas FA map at\
            0.2 unless a lower threshold is specified.
        noise_sigma: This parameter characterizes the Rician noise in the\
            original DWI images. Default value is 18.
        pathology: The user can specify the simulated pathology in a given area\
            using a label mask. Pathology is simulated by changing the eigenvalues.\
            One can specify the number of voxels affected in each region or the\
            proportion of voxels affected. Change is specified as a proportion of\
            the current eigenvalues.
        registered_population: To introduce inter-subject variability, a\
            registered DTI population to the DTI atlas is required. This is modeled\
            by PCA decomposition.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CreateDticohortOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(CREATE_DTICOHORT_METADATA)
    params = create_dticohort_params(
        image_dimensionality=image_dimensionality,
        dti_atlas=dti_atlas,
        label_mask_image=label_mask_image,
        noise_sigma=noise_sigma,
        pathology=pathology,
        dwi_parameters=dwi_parameters,
        registered_population=registered_population,
        output=output,
    )
    return create_dticohort_execute(params, execution)


__all__ = [
    "CREATE_DTICOHORT_METADATA",
    "CreateDticohortOutputs",
    "CreateDticohortParameters",
    "create_dticohort",
    "create_dticohort_params",
]
