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

import typing
import pathlib
from styxdefs import *
import dataclasses

MAKE_FOLDING_ATLAS_METADATA = Metadata(
    id="cd742cf69eb865650042165331953a619d588ea9.boutiques",
    name="make_folding_atlas",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MakeFoldingAtlasOutputs(typing.NamedTuple):
    """
    Output object returned when calling `make_folding_atlas(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    average_subject_folder: OutputPathType | None
    """Average subject folder that contains the atlas files for each
    iteration."""


def make_folding_atlas(
    subjlistfile: InputPathType | None = None,
    fsgdfile: InputPathType | None = None,
    subjects: list[str] | None = None,
    output_base: str | None = None,
    max_iterations: float | None = None,
    xhemi: bool = False,
    init_surf_reg: str | None = None,
    init_subject: str | None = None,
    no_annot_template: bool = False,
    right_hemisphere: bool = False,
    lhrh: bool = False,
    ico_order: float | None = None,
    no_vol_on_last: bool = False,
    vol: bool = False,
    init: bool = False,
    short_sleep: bool = False,
    no_template_only: bool = False,
    threads: float | None = None,
    slurm_account: str | None = None,
    runner: Runner | None = None,
) -> MakeFoldingAtlasOutputs:
    """
    Script to iteratively create a cortical folding atlas.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        subjlistfile: Subject list file.
        fsgdfile: FS Gradient Design file.
        subjects: Subjects to be included.
        output_base: Output base; the subject will be named based on this.
        max_iterations: Maximum number of iterations.
        xhemi: Do xhemi (sets hemilist to lh only, use --lhrh after if both are\
            wanted).
        init_surf_reg: Registration used to make template on first iteration\
            (default sphere.reg).
        init_subject: Create first atlas from subject instead of all subjects.
        no_annot_template: Disable annotation template (good for monkeys).
        right_hemisphere: Process right hemisphere.
        lhrh: Process both left and right hemispheres (default).
        ico_order: Icosahedron order; default is 7.
        no_vol_on_last: Do not run make_average_volume on the last iteration.
        vol: Run make_average_volume on each iteration.
        init: Use previous iteration registration to initialize\
            mris_register/surfreg.
        short_sleep: Sleep for a shorter time before polling.
        no_template_only: Make average surface files even with a single hemi or\
            --no-vol.
        threads: Number of threads to use.
        slurm_account: SLURM account or set FS_BATCH_ACCOUNT environment\
            variable.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MakeFoldingAtlasOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MAKE_FOLDING_ATLAS_METADATA)
    cargs = []
    cargs.append("make_folding_atlas")
    if subjlistfile is not None:
        cargs.extend([
            "--f",
            execution.input_file(subjlistfile)
        ])
    if fsgdfile is not None:
        cargs.extend([
            "--fsgd",
            execution.input_file(fsgdfile)
        ])
    if subjects is not None:
        cargs.extend([
            "--s",
            *subjects
        ])
    if output_base is not None:
        cargs.extend([
            "--b",
            output_base
        ])
    if max_iterations is not None:
        cargs.extend([
            "--nmax",
            str(max_iterations)
        ])
    if xhemi:
        cargs.append("--xhemi")
    if init_surf_reg is not None:
        cargs.extend([
            "--init-surf-reg",
            init_surf_reg
        ])
    if init_subject is not None:
        cargs.extend([
            "--init-subject",
            init_subject
        ])
    if no_annot_template:
        cargs.append("--no-annot-template")
    if right_hemisphere:
        cargs.append("--rh")
    if lhrh:
        cargs.append("--lhrh")
    if ico_order is not None:
        cargs.extend([
            "--ico",
            str(ico_order)
        ])
    if no_vol_on_last:
        cargs.append("--no-vol-on-last")
    if vol:
        cargs.append("--vol")
    if init:
        cargs.append("--init")
    if short_sleep:
        cargs.append("--short-sleep")
    if no_template_only:
        cargs.append("--no-template-only")
    if threads is not None:
        cargs.extend([
            "--threads",
            str(threads)
        ])
    if slurm_account is not None:
        cargs.extend([
            "--account",
            slurm_account
        ])
    ret = MakeFoldingAtlasOutputs(
        root=execution.output_file("."),
        average_subject_folder=execution.output_file(output_base + ".i*") if (output_base is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MAKE_FOLDING_ATLAS_METADATA",
    "MakeFoldingAtlasOutputs",
    "make_folding_atlas",
]
