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

import typing
import pathlib
from styxdefs import *
import dataclasses

MERGE_STATS_TABLES_METADATA = Metadata(
    id="004967733986569ad699b7fcfc4e0e899cb02c90.boutiques",
    name="merge_stats_tables",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MergeStatsTablesOutputs(typing.NamedTuple):
    """
    Output object returned when calling `merge_stats_tables(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    merged_stats_table: OutputPathType
    """The merged stats table"""


def merge_stats_tables(
    outputfile: str,
    meas: str,
    subject: str | None = None,
    input_: InputPathType | None = None,
    subjectsfile: InputPathType | None = None,
    intable: InputPathType | None = None,
    subdir: str | None = None,
    delimiter: str | None = None,
    common_segs: bool = False,
    all_segs: bool = False,
    transpose: bool = False,
    skip: bool = False,
    debug: bool = False,
    runner: Runner | None = None,
) -> MergeStatsTablesOutputs:
    """
    Merges a set of stats table files into a single stats table where each line is a
    subject and each column is a segmentation or parcellation.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        outputfile: The output table file.
        meas: Measure to write in output table.
        subject: Specify a single subject name.
        input_: Specify a single input stat file.
        subjectsfile: Name of the file which has the list of subjects (one\
            subject per line).
        intable: Use `fname` as input (REQUIRED when passing subject ids).
        subdir: Use `subdir` instead of default "stats/" when passing subject\
            ids.
        delimiter: Delimiter between measures in the table. Options are 'tab',\
            'space', 'comma', and 'semicolon'. Default is 'space'.
        common_segs: Output only the common segmentations of all the statsfiles\
            given.
        all_segs: Output all the segmentations of the statsfiles given.
        transpose: Transpose the table (default is subjects in rows and\
            segmentations in cols).
        skip: If a subject does not have a stats file, skip it instead of\
            exiting.
        debug: Increase verbosity for debugging purposes.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MergeStatsTablesOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MERGE_STATS_TABLES_METADATA)
    cargs = []
    cargs.append("merge_stats_tables")
    if subject is not None:
        cargs.extend([
            "-s",
            subject
        ])
    if input_ is not None:
        cargs.extend([
            "-i",
            execution.input_file(input_)
        ])
    cargs.extend([
        "-t",
        outputfile
    ])
    cargs.extend([
        "-m",
        meas
    ])
    if subjectsfile is not None:
        cargs.extend([
            "--subjectsfile",
            execution.input_file(subjectsfile)
        ])
    if intable is not None:
        cargs.extend([
            "--intable",
            execution.input_file(intable)
        ])
    if subdir is not None:
        cargs.extend([
            "--subdir",
            subdir
        ])
    if delimiter is not None:
        cargs.extend([
            "-d",
            delimiter
        ])
    if common_segs:
        cargs.append("--common-segs")
    if all_segs:
        cargs.append("--all-segs")
    cargs.append("[SEGIDS_FROM_FILE]")
    cargs.append("[SEGNO]")
    cargs.append("[NO_SEGNO_FLAG]")
    if transpose:
        cargs.append("--transpose")
    if skip:
        cargs.append("--skip")
    if debug:
        cargs.append("-v")
    ret = MergeStatsTablesOutputs(
        root=execution.output_file("."),
        merged_stats_table=execution.output_file(outputfile),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MERGE_STATS_TABLES_METADATA",
    "MergeStatsTablesOutputs",
    "merge_stats_tables",
]
