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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_CVS_REGISTER_METADATA = Metadata(
    id="bb0813a0151b53cc7fd810cb07043b52e37cd609.boutiques",
    name="mri_cvs_register",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriCvsRegisterOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_cvs_register(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    final_cvs_morph: OutputPathType | None
    """The final morph that combines correspondences recovered in all
    registration steps."""
    final_cvs_morphed_norm: OutputPathType | None
    """The CVS morphed norm.mgz file; final result of CVS with all registration
    steps contributions."""
    final_cvs_morphed_aseg: OutputPathType | None
    """The CVS morphed aseg.mgz file with all registration steps
    contributions."""
    step1_morphed_aseg: OutputPathType | None
    """Morphed aseg.mgz file result of CVS up to step (3)(i) and contains elatic
    morph and aseg-based nonlinear registration."""
    step1_morphed_norm: OutputPathType | None
    """Morphed norm.mgz file result of CVS up to step (3)(i) and contains elatic
    morph and aseg-based nonlinear registration."""


def mri_cvs_register(
    mov_subjid: str,
    template_subjid: str | None = None,
    templatedir: str | None = None,
    mni_flag: bool = False,
    outdir: str | None = None,
    asegfname: str | None = None,
    voltype: str | None = None,
    step1_flag: bool = False,
    step2_flag: bool = False,
    step3_flag: bool = False,
    noaseg_flag: bool = False,
    nointensity_flag: bool = False,
    hemi_flag: bool = False,
    masktargethemi_flag: bool = False,
    maskmovinghemi_flag: bool = False,
    nocleanup_flag: bool = False,
    keepelreg_flag: bool = False,
    keepallm3z_flag: bool = False,
    cleanall_flag: bool = False,
    cleansurfreg_flag: bool = False,
    cleanelreg_flag: bool = False,
    cleanvolreg_flag: bool = False,
    m3d_flag: bool = False,
    openmp: int | None = None,
    nolog_flag: bool = False,
    version_flag: bool = False,
    help_flag: bool = False,
    runner: Runner | None = None,
) -> MriCvsRegisterOutputs:
    """
    Combined Volume and Surface Registration.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        mov_subjid: FreeSurfer subject name as found in $SUBJECTS_DIR. This\
            identifies the subject that is to be moved / registered to the target.
        template_subjid: FreeSurfer subject name as found in $SUBJECTS_DIR (or\
            --templatedir). This identifies the subject that is to be kept fixed\
            (template).
        templatedir: Directory of the template subject's SUBJECTS_DIR if\
            different from that of the moving subject.
        mni_flag: Use the CVS atlas in MNI152 space as a target for\
            registration.
        outdir: Name of the output directory where all the registration results\
            are written.
        asegfname: Name of the segmentation volume used in volumetric\
            registration step. Do not use the file extension.
        voltype: Changes the input from norm.mgz to voltype.mgz.
        step1_flag: Only do step 1 (spherical registration).
        step2_flag: Only do step 2 (elastic registration).
        step3_flag: Only do step 3 (volumetric registration).
        noaseg_flag: Do not use aseg volumes in the volumetric registration\
            pipeline.
        nointensity_flag: Do not use intensity volumes in the volumetric\
            registration pipeline.
        hemi_flag: Run CVS registration only on one hemisphere.
        masktargethemi_flag: Use with --hemi when hemi is registered to full\
            brain target.
        maskmovinghemi_flag: Use with --hemi when full brain is registered to\
            single hemi target.
        nocleanup_flag: Do not delete temporary files.
        keepelreg_flag: Do not delete elastic registration outcomes.
        keepallm3z_flag: Do not delete m3z morph files computed during CVS.
        cleanall_flag: Overwrite / recompute all CVS-related morphs.
        cleansurfreg_flag: Overwrite/recompute CVS-related surface registration\
            morphs.
        cleanelreg_flag: Overwrite / recompute CVS-related elastic registration\
            morph.
        cleanvolreg_flag: Overwrite / recompute CVS-related volumetric morphs.
        m3d_flag: Use m3d instead of m3z for registration morphs.
        openmp: Assign the number of nodes for openmp runs.
        nolog_flag: Do not produce a log file.
        version_flag: Print version and exit.
        help_flag: Print help and exit.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriCvsRegisterOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_CVS_REGISTER_METADATA)
    cargs = []
    cargs.append("mri_cvs_register")
    cargs.extend([
        "--mov",
        mov_subjid
    ])
    if template_subjid is not None:
        cargs.extend([
            "--template",
            template_subjid
        ])
    if templatedir is not None:
        cargs.extend([
            "--templatedir",
            templatedir
        ])
    if mni_flag:
        cargs.append("--mni")
    if outdir is not None:
        cargs.extend([
            "--outdir",
            outdir
        ])
    if asegfname is not None:
        cargs.extend([
            "--asegfname",
            asegfname
        ])
    if voltype is not None:
        cargs.extend([
            "--voltype",
            voltype
        ])
    if step1_flag:
        cargs.append("--step1")
    if step2_flag:
        cargs.append("--step2")
    if step3_flag:
        cargs.append("--step3")
    if noaseg_flag:
        cargs.append("--noaseg")
    if nointensity_flag:
        cargs.append("--nointensity")
    if hemi_flag:
        cargs.append("--hemi")
    if masktargethemi_flag:
        cargs.append("--masktargethemi")
    if maskmovinghemi_flag:
        cargs.append("--maskmovinghemi")
    if nocleanup_flag:
        cargs.append("--nocleanup")
    if keepelreg_flag:
        cargs.append("--keepelreg")
    if keepallm3z_flag:
        cargs.append("--keepallm3z")
    if cleanall_flag:
        cargs.append("--cleanall")
    if cleansurfreg_flag:
        cargs.append("--cleansurfreg")
    if cleanelreg_flag:
        cargs.append("--cleanelreg")
    if cleanvolreg_flag:
        cargs.append("--cleanvolreg")
    if m3d_flag:
        cargs.append("--m3d")
    if openmp is not None:
        cargs.extend([
            "--openmp",
            str(openmp)
        ])
    if nolog_flag:
        cargs.append("--nolog")
    if version_flag:
        cargs.append("--version")
    if help_flag:
        cargs.append("--help")
    ret = MriCvsRegisterOutputs(
        root=execution.output_file("."),
        final_cvs_morph=execution.output_file(outdir + "/final_CVSmorph_toTEMPLATE.m3z") if (outdir is not None) else None,
        final_cvs_morphed_norm=execution.output_file(outdir + "/final_CVSmorphed_toTEMPLATE_norm.mgz") if (outdir is not None) else None,
        final_cvs_morphed_aseg=execution.output_file(outdir + "/final_CVSmorphed_toTEMPLATE_aseg.mgz") if (outdir is not None) else None,
        step1_morphed_aseg=execution.output_file(outdir + "/step1_CVSmorphed_toTEMPLATE_aseg.mgz") if (outdir is not None) else None,
        step1_morphed_norm=execution.output_file(outdir + "/step1_CVSmorphed_toTEMPLATE_norm.mgz") if (outdir is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_CVS_REGISTER_METADATA",
    "MriCvsRegisterOutputs",
    "mri_cvs_register",
]
