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

import typing
import pathlib
from styxdefs import *
import dataclasses

LONG_STATS_COMBINE_METADATA = Metadata(
    id="44c43a96c18b3f3b72a80aed68ec585e7b861c9d.boutiques",
    name="long_stats_combine",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class LongStatsCombineOutputs(typing.NamedTuple):
    """
    Output object returned when calling `long_stats_combine(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_qdec_file: OutputPathType
    """Output long qdec table"""
    output_stacked_stats_file: OutputPathType | None
    """Stacked stats table for all subjects, all time points"""


def long_stats_combine(
    qdec: InputPathType,
    stats: str,
    measure: str,
    subject_dir: str,
    output_qdec: str,
    output_stats: str | None = None,
    input_stats: InputPathType | None = None,
    cross_sectional: bool = False,
    runner: Runner | None = None,
) -> LongStatsCombineOutputs:
    """
    Adds columns from stats into longitudinal qdec table, using longitudinally
    processed results.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        qdec: QDEC table file specifying the subjects and time points. File has\
            first columns: fsid fsid-base.
        stats: The stats file, e.g. aseg.stats or lh.aparc.stats.
        measure: The stats measure (e.g. volume, thickness, mean, std).
        subject_dir: Full path to FreeSurfer subjects directory.
        output_qdec: File name of output long qdec table.
        output_stats: File name to output stacked stats table (all subjects,\
            all time points).
        input_stats: File name of stacked stats table (same order as qdec),\
            instead of using --stats and --meas.
        cross_sectional: Use cross sectional results (for testing only).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `LongStatsCombineOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(LONG_STATS_COMBINE_METADATA)
    cargs = []
    cargs.append("long_stats_combine")
    cargs.extend([
        "--qdec",
        execution.input_file(qdec)
    ])
    cargs.extend([
        "--stats",
        stats
    ])
    cargs.extend([
        "--meas",
        measure
    ])
    cargs.extend([
        "--sd",
        subject_dir
    ])
    cargs.append("--out")
    cargs.extend([
        "--outqdec",
        output_qdec
    ])
    if output_stats is not None:
        cargs.extend([
            "--outstats",
            output_stats
        ])
    if input_stats is not None:
        cargs.extend([
            "--instats",
            execution.input_file(input_stats)
        ])
    if cross_sectional:
        cargs.append("--cross")
    ret = LongStatsCombineOutputs(
        root=execution.output_file("."),
        output_qdec_file=execution.output_file(output_qdec),
        output_stacked_stats_file=execution.output_file(output_stats) if (output_stats is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "LONG_STATS_COMBINE_METADATA",
    "LongStatsCombineOutputs",
    "long_stats_combine",
]
