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

import typing
import pathlib
from styxdefs import *
import dataclasses

DMRI_PATHSTATS_METADATA = Metadata(
    id="8110c02ff2c74fe994c5787d89b13efd80585a6a.boutiques",
    name="dmri_pathstats",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class DmriPathstatsOutputs(typing.NamedTuple):
    """
    Output object returned when calling `dmri_pathstats(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    out_file: OutputPathType | None
    """Text file for overall path measures"""
    out_vox_file: OutputPathType | None
    """Text file for voxel-by-voxel measures along path"""
    median_file: OutputPathType | None
    """.trk file of median streamline"""


def dmri_pathstats(
    intrk: InputPathType,
    intrc: InputPathType,
    rois: list[InputPathType] | None = None,
    meas: list[InputPathType] | None = None,
    measname: list[str] | None = None,
    dtbase: str | None = None,
    path: str | None = None,
    subj: str | None = None,
    out: str | None = None,
    outvox: str | None = None,
    median: InputPathType | None = None,
    ends: str | None = None,
    ref: InputPathType | None = None,
    pthr: float | None = None,
    fthr: float | None = None,
    debug: bool = False,
    checkopts: bool = False,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> DmriPathstatsOutputs:
    """
    Compute path statistics for diffusion MRI data based on input .trk file and
    optional various measures.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        intrk: Input .trk file.
        intrc: Input tracula directory.
        rois: Input labeling ROIs for .trk file (optional).
        meas: Input microstructural measure volume(s) (optional).
        measname: Name(s) of microstructural measure(s) (as many as volumes).
        dtbase: Base name of input dtifit volumes (optional).
        path: Name of pathway (optional, written to output files).
        subj: Name of subject (optional, written to output files).
        out: Output text file for overall path measures.
        outvox: Output text file for voxel-by-voxel measures along path\
            (optional).
        median: Output .trk file of median streamline (optional).
        ends: Base name of output volumes of streamline ends (optional).
        ref: Reference volume (needed only if using --ends without --dtbase).
        pthr: Lower threshold on path posterior distribution, as a portion of\
            the maximum (range: 0-1, default: 0.2).
        fthr: Lower threshold on FA (range: 0-1, default: no threshold).
        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 `DmriPathstatsOutputs`).
    """
    if rois is not None and not (0 <= len(rois)): 
        raise ValueError(f"Length of 'rois' must be greater than 0 but was {len(rois)}")
    if meas is not None and not (0 <= len(meas)): 
        raise ValueError(f"Length of 'meas' must be greater than 0 but was {len(meas)}")
    if measname is not None and not (0 <= len(measname)): 
        raise ValueError(f"Length of 'measname' must be greater than 0 but was {len(measname)}")
    if pthr is not None and not (0 <= pthr <= 1): 
        raise ValueError(f"'pthr' must be between 0 <= x <= 1 but was {pthr}")
    if fthr is not None and not (0 <= fthr <= 1): 
        raise ValueError(f"'fthr' must be between 0 <= x <= 1 but was {fthr}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(DMRI_PATHSTATS_METADATA)
    cargs = []
    cargs.append("./dmri_pathstats")
    cargs.extend([
        "--intrk",
        execution.input_file(intrk)
    ])
    if rois is not None:
        cargs.extend([
            "--rois",
            *[execution.input_file(f) for f in rois]
        ])
    cargs.extend([
        "--intrc",
        execution.input_file(intrc)
    ])
    if meas is not None:
        cargs.extend([
            "--meas",
            *[execution.input_file(f) for f in meas]
        ])
    if measname is not None:
        cargs.extend([
            "--measname",
            *measname
        ])
    if dtbase is not None:
        cargs.extend([
            "--dtbase",
            dtbase
        ])
    if path is not None:
        cargs.extend([
            "--path",
            path
        ])
    if subj is not None:
        cargs.extend([
            "--subj",
            subj
        ])
    if out is not None:
        cargs.extend([
            "--out",
            out
        ])
    if outvox is not None:
        cargs.extend([
            "--outvox",
            outvox
        ])
    if median is not None:
        cargs.extend([
            "--median",
            execution.input_file(median)
        ])
    if ends is not None:
        cargs.extend([
            "--ends",
            ends
        ])
    if ref is not None:
        cargs.extend([
            "--ref",
            execution.input_file(ref)
        ])
    if pthr is not None:
        cargs.extend([
            "--pthr",
            str(pthr)
        ])
    if fthr is not None:
        cargs.extend([
            "--fthr",
            str(fthr)
        ])
    if debug:
        cargs.append("--debug")
    if checkopts:
        cargs.append("--checkopts")
    if help_:
        cargs.append("--help")
    if version:
        cargs.append("--version")
    ret = DmriPathstatsOutputs(
        root=execution.output_file("."),
        out_file=execution.output_file(out) if (out is not None) else None,
        out_vox_file=execution.output_file(outvox) if (outvox is not None) else None,
        median_file=execution.output_file(pathlib.Path(median).name) if (median is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "DMRI_PATHSTATS_METADATA",
    "DmriPathstatsOutputs",
    "dmri_pathstats",
]
