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

import typing
import pathlib
from styxdefs import *
import dataclasses

GCA_APPLY_METADATA = Metadata(
    id="004863971f906d9a0b7892c9101381a0f012a5c2.boutiques",
    name="gca-apply",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class GcaApplyOutputs(typing.NamedTuple):
    """
    Output object returned when calling `gca_apply(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_lta: OutputPathType | None
    """Output LTA file"""
    output_m3z: OutputPathType | None
    """Output M3Z file"""
    normalized_gca: OutputPathType | None
    """Normalized GCA base MGZ file"""
    segmented_gca: OutputPathType | None
    """Segmented GCA base MGZ file"""
    stats_output: OutputPathType | None
    """Statistical output file"""


def gca_apply(
    gcafile: InputPathType,
    subject: str,
    nthreads: float | None = None,
    base: str | None = None,
    no_segstats: bool = False,
    subjects_dir: str | None = None,
    dice_seg: str | None = None,
    dice_file: str | None = None,
    lta: InputPathType | None = None,
    norm: InputPathType | None = None,
    input_mgz: InputPathType | None = None,
    brainmask: InputPathType | None = None,
    output_dir: str | None = None,
    no_v6labopts: bool = False,
    m3z_file: InputPathType | None = None,
    gca_rb_2016: bool = False,
    force_update: bool = False,
    gcareg_iters: float | None = None,
    runner: Runner | None = None,
) -> GcaApplyOutputs:
    """
    Applies a GCA, performing the steps of mri_em_register, mri_ca_normalize,
    mri_ca_register, and mri_ca_label. This script replicates the stages in
    recon-all without overwriting files.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        gcafile: GCA file.
        subject: Subject.
        nthreads: Number of OMP threads.
        base: Use gcabase for naming output files (default is basename gcafile).
        no_segstats: Do not compute segstats.
        subjects_dir: Subjects directory.
        dice_seg: Specify dice coefficient computation parameters.
        dice_file: Specify dice coefficient computation file.
        lta: Use SrcLTA instead of running mri_em_register.
        norm: Use SrcNorm instead of running mri_ca_normalize.
        input_mgz: Input file, default is nu.mgz.
        brainmask: Brainmask file, default is brainmask.mgz.
        output_dir: Output directory (default: SUBJECTS_DIR/subject).
        no_v6labopts: Do not include v6 command line options.
        m3z_file: M3Z file.
        gca_rb_2016: Use RB_all_2016-05-10.vc700.gca.
        force_update: Force recreation of a file even if it is younger than its\
            parents.
        gcareg_iters: Set to 1, only for testing.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `GcaApplyOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(GCA_APPLY_METADATA)
    cargs = []
    cargs.extend([
        "-apply",
        "gca" + execution.input_file(gcafile)
    ])
    cargs.append(subject)
    if nthreads is not None:
        cargs.extend([
            "--nthreads",
            str(nthreads)
        ])
    if base is not None:
        cargs.extend([
            "--base",
            base
        ])
    if no_segstats:
        cargs.append("--no-segstats")
    if subjects_dir is not None:
        cargs.extend([
            "--sd",
            subjects_dir
        ])
    if dice_seg is not None:
        cargs.extend([
            "--dice",
            dice_seg
        ])
    if dice_file is not None:
        cargs.append(dice_file)
    if lta is not None:
        cargs.extend([
            "--lta",
            execution.input_file(lta)
        ])
    if norm is not None:
        cargs.extend([
            "--norm",
            execution.input_file(norm)
        ])
    if input_mgz is not None:
        cargs.extend([
            "--input",
            execution.input_file(input_mgz)
        ])
    if brainmask is not None:
        cargs.extend([
            "--brainmask",
            execution.input_file(brainmask)
        ])
    if output_dir is not None:
        cargs.extend([
            "--o",
            output_dir
        ])
    if no_v6labopts:
        cargs.append("--no-v6labopts")
    if m3z_file is not None:
        cargs.extend([
            "--m3z",
            execution.input_file(m3z_file)
        ])
    if gca_rb_2016:
        cargs.append("--gca-rb-2016")
    if force_update:
        cargs.append("--force-update")
    if gcareg_iters is not None:
        cargs.extend([
            "--gcareg-iters",
            str(gcareg_iters)
        ])
    ret = GcaApplyOutputs(
        root=execution.output_file("."),
        output_lta=execution.output_file(base + ".lta") if (base is not None) else None,
        output_m3z=execution.output_file(base + ".m3z") if (base is not None) else None,
        normalized_gca=execution.output_file("norm." + base + ".mgz") if (base is not None) else None,
        segmented_gca=execution.output_file(base + ".aseg.mgz") if (base is not None) else None,
        stats_output=execution.output_file(base + ".stats") if (base is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "GCA_APPLY_METADATA",
    "GcaApplyOutputs",
    "gca_apply",
]
