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

import typing
import pathlib
from styxdefs import *
import dataclasses

V__ANIMAL_WARPER_METADATA = Metadata(
    id="f373bc7e1633539a38d1306872d0f169bc4fc59c.boutiques",
    name="@animal_warper",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class VAnimalWarperOutputs(typing.NamedTuple):
    """
    Output object returned when calling `v__animal_warper(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    warp2std: OutputPathType
    """input dataset nonlinearly warped to template"""
    qc_image_initial: OutputPathType
    """initial QC image montage showing overlap of source and base dataset"""
    qc_image_initial_sh: OutputPathType
    """initial QC image montage after shifting centers of source and base
    dataset"""
    dset_followers_out: OutputPathType
    """copy(s) of -dset_followers mapped to template space"""
    roidset_followers_out: OutputPathType
    """copy(s) of -roidset_followers mapped to template space"""
    animal_outs_guide: OutputPathType
    """guide to data in output directory"""


def v__animal_warper(
    input_file: InputPathType,
    base_template: InputPathType,
    output_dir: str,
    brainmask: InputPathType | None = None,
    atlases: list[InputPathType] | None = None,
    atlas_followers: list[InputPathType] | None = None,
    seg_followers: list[InputPathType] | None = None,
    template_followers: list[InputPathType] | None = None,
    dset_followers: list[InputPathType] | None = None,
    roidset_followers: list[InputPathType] | None = None,
    input_abbrev: str | None = None,
    base_abbrev: str | None = None,
    atlas_abbrevs: list[str] | None = None,
    template_abbrevs: list[str] | None = None,
    seg_abbrevs: list[str] | None = None,
    dset_abbrevs: list[str] | None = None,
    roidset_abbrevs: list[str] | None = None,
    align_centers_meth: str | None = None,
    aff_move_opt: str | None = None,
    cost: str | None = None,
    maxlev: float | None = None,
    no_surfaces: bool = False,
    feature_size: float | None = None,
    supersize: bool = False,
    init_scale: float | None = None,
    mode_smooth_size: float | None = None,
    mode_smooth_replacement_off: bool = False,
    center_out: str | None = None,
    align_type: str | None = None,
    extra_qw_opts: str | None = None,
    keep_temp: bool = False,
    version: bool = False,
    ok_to_exist: bool = False,
    echo: bool = False,
    runner: Runner | None = None,
) -> VAnimalWarperOutputs:
    """
    Align a subject structural dataset to a template and perform several
    post-alignment operations.
    
    Author: AFNI Team
    
    URL: https://afni.nimh.nih.gov/pub/dist/doc/program_help/@animal_warper.html
    
    Args:
        input_file: input dataset to align to base template.
        base_template: base dataset (template) to align with.
        output_dir: output directory where all processing will be performed.
        brainmask: provide a brainmask in the base template space.
        atlases: one or more atlas datasets in the base volume space.
        atlas_followers: one or more atlas datasets in the base volume space.
        seg_followers: one or more segmentation datasets in the base volume\
            space.
        template_followers: one or more datasets in the template volume space.
        dset_followers: one or more datasets in the input volume space.
        roidset_followers: one or more (int-valued) datasets in the input\
            volume space.
        input_abbrev: specify abbreviation for input dataset.
        base_abbrev: specify abbreviation for base dataset.
        atlas_abbrevs: specify an abbreviation for each atlas follower dataset.
        template_abbrevs: specify an abbreviation for each template follower\
            dataset.
        seg_abbrevs: specify an abbreviation for each segmentation follower\
            dataset.
        dset_abbrevs: specify an abbreviation for each dataset follower dataset.
        roidset_abbrevs: specify an abbreviation for each ROI dataset follower\
            dataset.
        align_centers_meth: center alignment method to use.
        aff_move_opt: alignment movement options for affine alignment step.
        cost: cost function for affine and nonlinear alignment.
        maxlev: Max level for nonlinear warping. Final patch size is determined\
            based on this value.
        no_surfaces: Do not make surfaces for atlas regions in native space.
        feature_size: Set feature size for affine alignment (in mm).
        supersize: Allow up to 50% size difference between subject and template.
        init_scale: Approximate length ratio of input to template for initial\
            scaling.
        mode_smooth_size: Modal smoothing kernel size in voxels.
        mode_smooth_replacement_off: Turn off replacement in modal smoothing.
        center_out: Center native-space output to native original space or\
            template space center-shifted.
        align_type: Specify level of alignment.
        extra_qw_opts: Additional options to add to existing options for\
            3dQwarp.
        keep_temp: Keep temporary files including awpy directory and other\
            intermediate datasets.
        version: Display the program version.
        ok_to_exist: Reuse and do not overwrite existing datasets.
        echo: Copy all commands being run into the terminal.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VAnimalWarperOutputs`).
    """
    if maxlev is not None and not (0 <= maxlev <= 11): 
        raise ValueError(f"'maxlev' must be between 0 <= x <= 11 but was {maxlev}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(V__ANIMAL_WARPER_METADATA)
    cargs = []
    cargs.append("animal_warper")
    cargs.append(execution.input_file(input_file))
    cargs.append(execution.input_file(base_template))
    cargs.append(output_dir)
    if brainmask is not None:
        cargs.append(execution.input_file(brainmask))
    if atlases is not None:
        cargs.extend([
            "-atlas",
            *[execution.input_file(f) for f in atlases]
        ])
    if atlas_followers is not None:
        cargs.extend([
            "-atlas_followers",
            *[execution.input_file(f) for f in atlas_followers]
        ])
    if seg_followers is not None:
        cargs.extend([
            "-seg_followers",
            *[execution.input_file(f) for f in seg_followers]
        ])
    if template_followers is not None:
        cargs.extend([
            "-template_followers",
            *[execution.input_file(f) for f in template_followers]
        ])
    if dset_followers is not None:
        cargs.extend([
            "-dset_followers",
            *[execution.input_file(f) for f in dset_followers]
        ])
    if roidset_followers is not None:
        cargs.extend([
            "-roidset_followers",
            *[execution.input_file(f) for f in roidset_followers]
        ])
    if input_abbrev is not None:
        cargs.extend([
            "-input_abbrev",
            input_abbrev
        ])
    if base_abbrev is not None:
        cargs.extend([
            "-base_abbrev",
            base_abbrev
        ])
    if atlas_abbrevs is not None:
        cargs.extend([
            "-atlas_abbrevs",
            *atlas_abbrevs
        ])
    if template_abbrevs is not None:
        cargs.extend([
            "-template_abbrevs",
            *template_abbrevs
        ])
    if seg_abbrevs is not None:
        cargs.extend([
            "-seg_abbrevs",
            *seg_abbrevs
        ])
    if dset_abbrevs is not None:
        cargs.extend([
            "-dset_abbrevs",
            *dset_abbrevs
        ])
    if roidset_abbrevs is not None:
        cargs.extend([
            "-roidset_abbrevs",
            *roidset_abbrevs
        ])
    if align_centers_meth is not None:
        cargs.extend([
            "-align_centers_meth",
            align_centers_meth
        ])
    if aff_move_opt is not None:
        cargs.extend([
            "-aff_move_opt",
            aff_move_opt
        ])
    if cost is not None:
        cargs.extend([
            "-cost",
            cost
        ])
    if maxlev is not None:
        cargs.extend([
            "-maxlev",
            str(maxlev)
        ])
    if no_surfaces:
        cargs.append("-no_surfaces")
    if feature_size is not None:
        cargs.extend([
            "-feature_size",
            str(feature_size)
        ])
    if supersize:
        cargs.append("-supersize")
    if init_scale is not None:
        cargs.extend([
            "-init_scale",
            str(init_scale)
        ])
    if mode_smooth_size is not None:
        cargs.extend([
            "-mode_smooth_size",
            str(mode_smooth_size)
        ])
    if mode_smooth_replacement_off:
        cargs.append("-mode_smooth_replacement_off")
    if center_out is not None:
        cargs.extend([
            "-center_out",
            center_out
        ])
    if align_type is not None:
        cargs.extend([
            "-align_type",
            align_type
        ])
    if extra_qw_opts is not None:
        cargs.extend([
            "-extra_qw_opts",
            extra_qw_opts
        ])
    if keep_temp:
        cargs.append("-keep_temp")
    if version:
        cargs.append("-ver")
    if ok_to_exist:
        cargs.append("-ok_to_exist")
    if echo:
        cargs.append("-echo")
    ret = VAnimalWarperOutputs(
        root=execution.output_file("."),
        warp2std=execution.output_file("aw_results/" + pathlib.Path(input_file).name + "_warp2std.nii.gz"),
        qc_image_initial=execution.output_file("aw_results/init_qc_00.input+base*.jpg"),
        qc_image_initial_sh=execution.output_file("aw_results/init_qc_01.input_sh+base*.jpg"),
        dset_followers_out=execution.output_file("aw_results/DSET_FOLL.nii.gz"),
        roidset_followers_out=execution.output_file("aw_results/ROIDSET_FOLL.nii.gz"),
        animal_outs_guide=execution.output_file("aw_results/animal_outs.txt"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "VAnimalWarperOutputs",
    "V__ANIMAL_WARPER_METADATA",
    "v__animal_warper",
]
