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

import typing
import pathlib
from styxdefs import *
import dataclasses

DT_RECON_METADATA = Metadata(
    id="2b8457b9d61edcd3ebcd8e361c6c29d3e697032b.boutiques",
    name="dt_recon",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class DtReconOutputs(typing.NamedTuple):
    """
    Output object returned when calling `dt_recon(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    dwi_nifti: OutputPathType
    """Converted input to NIFTI format."""
    dwi_eddy_corrected: OutputPathType
    """DWI after eddy-current correction."""
    tensor_map: OutputPathType
    """Tensor map."""
    fa_map: OutputPathType
    """Fractional anisotropy (FA) map."""
    fa_tal_map: OutputPathType
    """FA map in Talairach space."""
    register_file_output: OutputPathType
    """Registration file."""
    mask_file: OutputPathType
    """Mask file."""


def dt_recon(
    input_volume: InputPathType,
    subject_id: str,
    output_dir: str,
    bvals_bvecs: str | None = None,
    info_dump: InputPathType | None = None,
    ec_reference: float | None = None,
    no_ec_flag: bool = False,
    no_reg_flag: bool = False,
    register_file: InputPathType | None = None,
    no_tal_flag: bool = False,
    subjects_dir: str | None = None,
    save_ec_residuals_flag: bool = False,
    pca_analysis_flag: bool = False,
    mask_prune_threshold: float | None = None,
    init_spm_flag: bool = False,
    init_fsl_flag: bool = False,
    debug_flag: bool = False,
    version_flag: bool = False,
    runner: Runner | None = None,
) -> DtReconOutputs:
    """
    Performs DTI reconstruction from the raw DWI input files.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        input_volume: Input volume (DWI data).
        subject_id: Subject ID.
        output_dir: Output directory.
        bvals_bvecs: B-values and B-vectors files.
        info_dump: Use info dump created by unpacksdcmdir or dcmunpack.
        ec_reference: Use specified time points as 0-based reference for eddy\
            current correction.
        no_ec_flag: Turn off eddy/motion correction.
        no_reg_flag: Do not register to subject or resample to talairach.
        register_file: Supply a register.lta file instead of registering.
        no_tal_flag: Do not resample FA to talairach space.
        subjects_dir: Specify subjects directory (default env SUBJECTS_DIR).
        save_ec_residuals_flag: Save residual error (dwires and eres).
        pca_analysis_flag: Run PCA/SVD analysis on eres (saves in pca-eres\
            dir).
        mask_prune_threshold: Set threshold for masking (default is FLT_MIN).
        init_spm_flag: Initialize BBR with SPM instead of coreg (requires\
            MATLAB).
        init_fsl_flag: Initialize BBR with FSL instead of coreg.
        debug_flag: Print out lots of info.
        version_flag: Print version of this script and exit.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `DtReconOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(DT_RECON_METADATA)
    cargs = []
    cargs.append("dt_recon")
    cargs.extend([
        "--i",
        execution.input_file(input_volume)
    ])
    if bvals_bvecs is not None:
        cargs.extend([
            "--b",
            bvals_bvecs
        ])
    cargs.extend([
        "--s",
        subject_id
    ])
    cargs.extend([
        "--o",
        output_dir
    ])
    if info_dump is not None:
        cargs.extend([
            "--info-dump",
            execution.input_file(info_dump)
        ])
    if ec_reference is not None:
        cargs.extend([
            "--ecref",
            str(ec_reference)
        ])
    if no_ec_flag:
        cargs.append("--no-ec")
    if no_reg_flag:
        cargs.append("--no-reg")
    if register_file is not None:
        cargs.extend([
            "--reg",
            execution.input_file(register_file)
        ])
    if no_tal_flag:
        cargs.append("--no-tal")
    if subjects_dir is not None:
        cargs.extend([
            "--sd",
            subjects_dir
        ])
    if save_ec_residuals_flag:
        cargs.append("--eres-save")
    if pca_analysis_flag:
        cargs.append("--pca")
    if mask_prune_threshold is not None:
        cargs.extend([
            "--prune_thr",
            str(mask_prune_threshold)
        ])
    if init_spm_flag:
        cargs.append("--init-spm")
    if init_fsl_flag:
        cargs.append("--init-fsl")
    if debug_flag:
        cargs.append("--debug")
    if version_flag:
        cargs.append("--version")
    ret = DtReconOutputs(
        root=execution.output_file("."),
        dwi_nifti=execution.output_file(output_dir + "/dwi.nii.gz"),
        dwi_eddy_corrected=execution.output_file(output_dir + "/dwi-ec.nii.gz"),
        tensor_map=execution.output_file(output_dir + "/tensor.nii.gz"),
        fa_map=execution.output_file(output_dir + "/fa.nii.gz"),
        fa_tal_map=execution.output_file(output_dir + "/fa-tal.nii.gz"),
        register_file_output=execution.output_file(output_dir + "/register.lta"),
        mask_file=execution.output_file(output_dir + "/mask.nii.gz"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "DT_RECON_METADATA",
    "DtReconOutputs",
    "dt_recon",
]
