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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_GTMPVC_METADATA = Metadata(
    id="fd930d51e0a8f5012076ae523ec1cb2238ba47c5.boutiques",
    name="mri_gtmpvc",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriGtmpvcOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_gtmpvc(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    synthesized_volume: OutputPathType
    """Synthesized volume"""
    rescaled_input: OutputPathType
    """Rescaled input volume"""
    eresiduals: OutputPathType
    """Residual errors volume"""
    yhat: OutputPathType
    """Yhat volume"""
    yhat_with_noise: OutputPathType
    """Yhat with noise volume"""
    yhat_full_fov: OutputPathType
    """Yhat full FoV volume"""
    yhat_prior: OutputPathType
    """Yhat prior to smoothing volume"""
    x_matrix: OutputPathType
    """X matrix in matlab4 format"""
    y_matrix: OutputPathType
    """Y matrix in matlab4 format"""
    beta_matrix: OutputPathType
    """Beta matrix in matlab4 format"""
    x0_matrix: OutputPathType
    """X0 matrix in matlab4 format"""
    gtm_values_text: OutputPathType
    """Demeaned GTM values as text file"""


def mri_gtmpvc(
    input_volume: InputPathType,
    psf: float,
    segmentation: InputPathType,
    output_directory: str,
    frame: float | None = None,
    registration: InputPathType | None = None,
    mask: InputPathType | None = None,
    auto_mask: int | None = None,
    no_reduce_fov: bool = False,
    reduce_fov_eqodd: bool = False,
    contrast_matrix: InputPathType | None = None,
    default_seg_merge: bool = False,
    merge_hypos: bool = False,
    merge_cblum_wm_gyri: bool = False,
    tt_reduce: bool = False,
    replace_seg: str | None = None,
    replace_file: InputPathType | None = None,
    rescale: str | None = None,
    no_rescale: bool = False,
    scale_refval: float | None = None,
    ctab: InputPathType | None = None,
    ctab_default: bool = False,
    tt_update: bool = False,
    lateralization: bool = False,
    no_tfe: bool = False,
    no_pvc: bool = False,
    segpvfres: float | None = None,
    rbv: bool = False,
    rbv_res: float | None = None,
    mueller_pvc: str | None = None,
    mg_ref_cerebral_wm: bool = False,
    mg_ref_lobes_wm: bool = False,
    glm_mg_pvc: float | None = None,
    km_ref: str | None = None,
    km_hb: str | None = None,
    steady_state: str | None = None,
    save_x: bool = False,
    save_y: bool = False,
    save_beta: bool = False,
    save_x0: bool = False,
    save_input: bool = False,
    save_eres: bool = False,
    save_yhat: bool = False,
    save_yhat_noise: str | None = None,
    save_yhat_full_fov: bool = False,
    save_yhat0: bool = False,
    synth: str | None = None,
    synth_only: bool = False,
    synth_save: bool = False,
    save_text: bool = False,
    threads: float | None = None,
    max_threads: bool = False,
    max_threads_minus_one: bool = False,
    subjects_dir: str | None = None,
    vg_thresh: float | None = None,
    gdiag: float | None = None,
    debug: bool = False,
    checkopts: bool = False,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> MriGtmpvcOutputs:
    """
    mri_gtmpvc performs partial volume correction on PET data using anatomical
    segmentation.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        input_volume: Input volume: source data to PVC.
        psf: Scanner PSF FWHM in mm.
        segmentation: Anatomical segmentation to define regions for GTM.
        output_directory: Output directory.
        frame: Only process 0-based frame F from input volume.
        registration: LTA registration file that maps PET to anatomical.
        mask: Ignore areas outside of the mask (in input vol space).
        auto_mask: Automatically compute mask with FWHM and threshold.
        no_reduce_fov: Do not reduce FoV to encompass mask.
        reduce_fov_eqodd: Reduce FoV to encompass mask but force nc=nr and ns\
            to be odd.
        contrast_matrix: Univariate contrast to test.
        default_seg_merge: Default schema for merging ROIs.
        merge_hypos: Merge left and right hypointensites into ROI.
        merge_cblum_wm_gyri: Cerebellum WM gyri back into cerebellum WM.
        tt_reduce: Reduce segmentation to that of a tissue type.
        replace_seg: Replace seg Id1 with seg Id2.
        replace_file: File with a list of Ids to replace.
        rescale: Specify reference region(s) used to rescale (default is pons).
        no_rescale: Do not global rescale such that mean of reference region is\
            scaleref.
        scale_refval: Scale such that mean in reference region is refval.
        ctab: Specify color table explicitly.
        ctab_default: Use default color table.
        tt_update: Changes tissue type of VentralDC, BrainStem, and Pons to be\
            SubcortGM.
        lateralization: Lateralize tissue types.
        no_tfe: Do not correct for tissue fraction effect.
        no_pvc: Turns off PVC entirely.
        segpvfres: Set the tissue fraction resolution parameter (default is\
            0.5).
        rbv: Perform RBV PVC.
        rbv_res: Set RBV voxel resolution.
        mueller_pvc: Perform Mueller-Gaertner PVC.
        mg_ref_cerebral_wm: Set MG RefIds to 2 and 41.
        mg_ref_lobes_wm: Set MG RefIds to those for lobes when using wm subseg.
        glm_mg_pvc: GLM-based Mueller-Gaertner PVC.
        km_ref: Compute reference TAC for KM as mean of given RefIds.
        km_hb: Compute HiBinding TAC for KM as mean of given RefIds.
        steady_state: Steady-state analysis spec blood plasma concentration,\
            unit scale, and decay correction factor.
        save_x: Save X matrix in matlab4 format as X.mat.
        save_y: Save y matrix in matlab4 format as y.mat.
        save_beta: Save beta matrix in matlab4 format as beta.mat.
        save_x0: Save X0 matrix in matlab4 format as X0.mat.
        save_input: Saves rescaled input as input.rescaled.nii.gz.
        save_eres: Saves residual error.
        save_yhat: Saves yhat.
        save_yhat_noise: Saves yhat with noise, seed < 0 for TOD.
        save_yhat_full_fov: Saves yhat in full FoV (if FoV was reduced).
        save_yhat0: Saves yhat prior to smoothing.
        synth: Synthesize volume with gtmbeta as input.
        synth_only: Exit after doing synthesis (implies --synth-save).
        synth_save: With --synth saves synthesized volume to\
            outdir/synth.nii.gz.
        save_text: Save demeaned GTM values out to text files named after the\
            seg.
        threads: Use N threads (with Open MP).
        max_threads: Use the maximum allowable number of threads for this\
            computer.
        max_threads_minus_one: Use one less than the maximum allowable number\
            of threads for this computer.
        subjects_dir: Specify SUBJECTS_DIR.
        vg_thresh: Threshold for LTAconcat error.
        gdiag: Set diagnostic level.
        debug: Turn on debugging.
        checkopts: Don't run anything, just check options and exit.
        help_: Print out information on how to use this program.
        version: Print out version and exit.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriGtmpvcOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_GTMPVC_METADATA)
    cargs = []
    cargs.append("mri_gtmpvc")
    cargs.extend([
        "--i",
        execution.input_file(input_volume)
    ])
    if frame is not None:
        cargs.extend([
            "--frame",
            str(frame)
        ])
    cargs.extend([
        "--psf",
        str(psf)
    ])
    cargs.extend([
        "--seg",
        execution.input_file(segmentation)
    ])
    if registration is not None:
        cargs.extend([
            "--reg",
            execution.input_file(registration)
        ])
    cargs.extend([
        "--o",
        output_directory
    ])
    if mask is not None:
        cargs.extend([
            "--mask",
            execution.input_file(mask)
        ])
    if auto_mask is not None:
        cargs.extend([
            "--auto-mask",
            str(auto_mask)
        ])
    if no_reduce_fov:
        cargs.append("--no-reduce-fov")
    if reduce_fov_eqodd:
        cargs.append("--reduce-fov-eqodd")
    if contrast_matrix is not None:
        cargs.extend([
            "--C",
            execution.input_file(contrast_matrix)
        ])
    if default_seg_merge:
        cargs.append("--default-seg-merge")
    if merge_hypos:
        cargs.append("--merge-hypos")
    if merge_cblum_wm_gyri:
        cargs.append("--merge-cblum-wm-gyri")
    if tt_reduce:
        cargs.append("--tt-reduce")
    if replace_seg is not None:
        cargs.extend([
            "--replace",
            replace_seg
        ])
    if replace_file is not None:
        cargs.extend([
            "--replace-file",
            execution.input_file(replace_file)
        ])
    if rescale is not None:
        cargs.extend([
            "--rescale",
            rescale
        ])
    if no_rescale:
        cargs.append("--no-rescale")
    if scale_refval is not None:
        cargs.extend([
            "--scale-refval",
            str(scale_refval)
        ])
    if ctab is not None:
        cargs.extend([
            "--ctab",
            execution.input_file(ctab)
        ])
    if ctab_default:
        cargs.append("--ctab-default")
    if tt_update:
        cargs.append("--tt-update")
    if lateralization:
        cargs.append("--lat")
    if no_tfe:
        cargs.append("--no-tfe")
    if no_pvc:
        cargs.append("--no-pvc")
    if segpvfres is not None:
        cargs.extend([
            "--segpvfres",
            str(segpvfres)
        ])
    if rbv:
        cargs.append("--rbv")
    if rbv_res is not None:
        cargs.extend([
            "--rbv-res",
            str(rbv_res)
        ])
    if mueller_pvc is not None:
        cargs.extend([
            "--mg",
            mueller_pvc
        ])
    if mg_ref_cerebral_wm:
        cargs.append("--mg-ref-cerebral-wm")
    if mg_ref_lobes_wm:
        cargs.append("--mg-ref-lobes-wm")
    if glm_mg_pvc is not None:
        cargs.extend([
            "--mgx",
            str(glm_mg_pvc)
        ])
    if km_ref is not None:
        cargs.extend([
            "--km-ref",
            km_ref
        ])
    if km_hb is not None:
        cargs.extend([
            "--km-hb",
            km_hb
        ])
    if steady_state is not None:
        cargs.extend([
            "--ss",
            steady_state
        ])
    if save_x:
        cargs.append("--X")
    if save_y:
        cargs.append("--y")
    if save_beta:
        cargs.append("--beta")
    if save_x0:
        cargs.append("--X0")
    if save_input:
        cargs.append("--save-input")
    if save_eres:
        cargs.append("--save-eres")
    if save_yhat:
        cargs.append("--save-yhat")
    if save_yhat_noise is not None:
        cargs.extend([
            "--save-yhat-with-noise",
            save_yhat_noise
        ])
    if save_yhat_full_fov:
        cargs.append("--save-yhat-full-fov")
    if save_yhat0:
        cargs.append("--save-yhat0")
    if synth is not None:
        cargs.extend([
            "--synth",
            synth
        ])
    if synth_only:
        cargs.append("--synth-only")
    if synth_save:
        cargs.append("--synth-save")
    if save_text:
        cargs.append("--save-text")
    if threads is not None:
        cargs.extend([
            "--threads",
            str(threads)
        ])
    if max_threads:
        cargs.append("--max-threads")
    if max_threads_minus_one:
        cargs.append("--max-threads-minus-1")
    if subjects_dir is not None:
        cargs.extend([
            "--sd",
            subjects_dir
        ])
    if vg_thresh is not None:
        cargs.extend([
            "--vg-thresh",
            str(vg_thresh)
        ])
    if gdiag is not None:
        cargs.extend([
            "--gdiag",
            str(gdiag)
        ])
    if debug:
        cargs.append("--debug")
    if checkopts:
        cargs.append("--checkopts")
    if help_:
        cargs.append("--help")
    if version:
        cargs.append("--version")
    ret = MriGtmpvcOutputs(
        root=execution.output_file("."),
        synthesized_volume=execution.output_file(output_directory + "/synth.nii.gz"),
        rescaled_input=execution.output_file(output_directory + "/input.rescaled.nii.gz"),
        eresiduals=execution.output_file(output_directory + "/eresiduals.nii.gz"),
        yhat=execution.output_file(output_directory + "/yhat.nii.gz"),
        yhat_with_noise=execution.output_file(output_directory + "/yhat_with_noise.nii.gz"),
        yhat_full_fov=execution.output_file(output_directory + "/yhat_full_fov.nii.gz"),
        yhat_prior=execution.output_file(output_directory + "/yhat_prior.nii.gz"),
        x_matrix=execution.output_file(output_directory + "/X.mat"),
        y_matrix=execution.output_file(output_directory + "/y.mat"),
        beta_matrix=execution.output_file(output_directory + "/beta.mat"),
        x0_matrix=execution.output_file(output_directory + "/X0.mat"),
        gtm_values_text=execution.output_file(output_directory + "/gtm_values.txt"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_GTMPVC_METADATA",
    "MriGtmpvcOutputs",
    "mri_gtmpvc",
]
