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

import typing
import pathlib
from styxdefs import *
import dataclasses

APARCSTATS2TABLE_METADATA = Metadata(
    id="7b7bfbf1a3b6bd57ebf50cd28aa6878555458f68.boutiques",
    name="aparcstats2table",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class Aparcstats2tableOutputs(typing.NamedTuple):
    """
    Output object returned when calling `aparcstats2table(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_table: OutputPathType
    """Output table file with processed data."""


def aparcstats2table(
    hemi: str,
    tablefile: InputPathType,
    subjects: list[str] | None = None,
    subjectsfile: InputPathType | None = None,
    qdec: InputPathType | None = None,
    qdec_long: InputPathType | None = None,
    parcellation: str | None = "aparc",
    measure: str | None = "area",
    delimiter: str | None = "tab",
    skip_missing: bool = False,
    parcid_only: bool = False,
    common_parcs: bool = False,
    parcs_file: InputPathType | None = None,
    report_rois: bool = False,
    transpose: bool = False,
    debug: bool = False,
    etiv: bool = False,
    scale: float | None = 1,
    runner: Runner | None = None,
) -> Aparcstats2tableOutputs:
    """
    Converts a cortical stats file into a table format with subjects as rows and
    parcellations as columns.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        hemi: Hemisphere being analyzed (lh or rh required).
        tablefile: Output table file.
        subjects: List of subject IDs.
        subjectsfile: File containing list of subjects (one per line).
        qdec: QDEC table file with subject IDs.
        qdec_long: Longitudinal QDEC table with subject templates.
        parcellation: Parcellation atlas (default: aparc).
        measure: Measure type (e.g., area, volume, thickness).
        delimiter: Delimiter between measures in the table (default: tab).
        skip_missing: Skip subjects if input is not found.
        parcid_only: Write only ROI names without pre/appended hemi/measure.
        common_parcs: Output only common parcellations across all subjects.
        parcs_file: File specifying which parcellations to output.
        report_rois: Print ROI information for each subject.
        transpose: Transpose the table (subjects in columns).
        debug: Increase verbosity.
        etiv: Report volume as percent estimated total intracranial volume.
        scale: Scale factor for output values.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `Aparcstats2tableOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(APARCSTATS2TABLE_METADATA)
    cargs = []
    cargs.append("aparcstats2table")
    if subjects is not None:
        cargs.extend([
            "--subjects",
            *subjects
        ])
    if subjectsfile is not None:
        cargs.extend([
            "--subjectsfile",
            execution.input_file(subjectsfile)
        ])
    if qdec is not None:
        cargs.extend([
            "--qdec",
            execution.input_file(qdec)
        ])
    if qdec_long is not None:
        cargs.extend([
            "--qdec-long",
            execution.input_file(qdec_long)
        ])
    cargs.extend([
        "--hemi",
        hemi
    ])
    cargs.extend([
        "-t",
        execution.input_file(tablefile)
    ])
    if parcellation is not None:
        cargs.extend([
            "--parc",
            parcellation
        ])
    if measure is not None:
        cargs.extend([
            "-m",
            measure
        ])
    if delimiter is not None:
        cargs.extend([
            "-d",
            delimiter
        ])
    if skip_missing:
        cargs.append("--skip")
    if parcid_only:
        cargs.append("--parcid-only")
    if common_parcs:
        cargs.append("--common-parcs")
    if parcs_file is not None:
        cargs.extend([
            "--parcs-from-file",
            execution.input_file(parcs_file)
        ])
    if report_rois:
        cargs.append("--report-rois")
    if transpose:
        cargs.append("--transpose")
    if debug:
        cargs.append("-v")
    if etiv:
        cargs.append("--etiv")
    if scale is not None:
        cargs.extend([
            "--scale",
            str(scale)
        ])
    ret = Aparcstats2tableOutputs(
        root=execution.output_file("."),
        output_table=execution.output_file(pathlib.Path(tablefile).name),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "APARCSTATS2TABLE_METADATA",
    "Aparcstats2tableOutputs",
    "aparcstats2table",
]
