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

import typing
import pathlib
from styxdefs import *
import dataclasses

POPP_METADATA = Metadata(
    id="29bde353620add34cd7a90603c61465fa385c87a.boutiques",
    name="popp",
    package="fsl",
    container_image_tag="brainlife/fsl:6.0.4-patched2",
)


class PoppOutputs(typing.NamedTuple):
    """
    Output object returned when calling `popp(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    processed_data_output: OutputPathType
    """Processed physiological data output"""
    timing_output: OutputPathType
    """Timing and triggers output"""
    rvt_data_output: OutputPathType
    """RVT data output file"""
    heartrate_data_output: OutputPathType
    """Heartrate data output file"""


def popp(
    input_file: InputPathType,
    output_basename: str,
    sampling_rate: float | None = 100,
    tr_value: float | None = None,
    resp_column: float | None = None,
    cardiac_column: float | None = None,
    trigger_column: float | None = None,
    rvt_flag: bool = False,
    heart_rate_flag: bool = False,
    pulseox_trigger_flag: bool = False,
    smooth_card: float | None = None,
    smooth_resp: float | None = None,
    high_freq_cutoff: float | None = 5,
    low_freq_cutoff: float | None = 0.1,
    init_thresh_c: float | None = 90,
    n_thresh_c: float | None = 60,
    init_thresh_r: float | None = 80,
    n_thresh_r: float | None = 80,
    invert_resp_flag: bool = False,
    invert_cardiac_flag: bool = False,
    noclean1_flag: bool = False,
    noclean2_flag: bool = False,
    load_card_phase: InputPathType | None = None,
    load_resp_phase: InputPathType | None = None,
    vol_file: InputPathType | None = None,
    start_sample: float | None = None,
    resp_add: str | None = None,
    resp_del: str | None = None,
    card_add: str | None = None,
    card_del: str | None = None,
    verbose_flag: bool = False,
    debug_flag: bool = False,
    help_flag: bool = False,
    runner: Runner | None = None,
) -> PoppOutputs:
    """
    Physiological data processing tool of FSL.
    
    Author: FMRIB Analysis Group, University of Oxford
    
    URL: https://fsl.fmrib.ox.ac.uk/fsl/fslwiki
    
    Args:
        input_file: Input physiological data filename (text format).
        output_basename: Output basename for physiological data and\
            timing/triggers (no extensions).
        sampling_rate: Sampling rate in Hz (default is 100Hz).
        tr_value: TR value in seconds.
        resp_column: Specify column number of respiratory input.
        cardiac_column: Specify column number of cardiac input.
        trigger_column: Specify column number of trigger input.
        rvt_flag: Generate RVT data.
        heart_rate_flag: Generate heartrate data.
        pulseox_trigger_flag: Specify that cardiac data is a trigger.
        smooth_card: Specify smoothing amount for cardiac (in seconds).
        smooth_resp: Specify smoothing amount for respiratory (in seconds).
        high_freq_cutoff: High frequency cut off for respiratory filter in Hz\
            (default is 5Hz).
        low_freq_cutoff: Low frequency cut off for respiratory filter in Hz\
            (default is 0.1Hz).
        init_thresh_c: Initial threshold percentile for cardiac (default 90).
        n_thresh_c: Neighbourhood exclusion threshold percentile for cardiac\
            (default 60).
        init_thresh_r: Initial threshold percentile for respiratory (default\
            80).
        n_thresh_r: Neighbourhood exclusion threshold percentile for\
            respiratory (default 80).
        invert_resp_flag: Invert respiratory trace.
        invert_cardiac_flag: Invert cardiac trace.
        noclean1_flag: Turn off cleanup phase 1.
        noclean2_flag: Turn off cleanup phase 2.
        load_card_phase: Input cardiac phase for reprocessing (text format).
        load_resp_phase: Input respiratory phase for reprocessing (text format).
        vol_file: Input volumetric image (EPI) filename.
        start_sample: Set sample number of the starting time (t=0).
        resp_add: Comma separated list of times (in sec) to add to respiratory\
            peak list (uses nearest local max).
        resp_del: Comma separated list of times (in sec) to delete from\
            respiratory peak list (uses nearest existing peak).
        card_add: Comma separated list of times (in sec) to add to cardiac peak\
            list (uses nearest local max).
        card_del: Comma separated list of times (in sec) to delete from cardiac\
            peak list (uses nearest existing peak).
        verbose_flag: Switch on diagnostic messages.
        debug_flag: Output debugging information.
        help_flag: Display this help message.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `PoppOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(POPP_METADATA)
    cargs = []
    cargs.append("popp")
    cargs.extend([
        "-i",
        execution.input_file(input_file)
    ])
    cargs.extend([
        "-o",
        output_basename
    ])
    if sampling_rate is not None:
        cargs.extend([
            "-s",
            str(sampling_rate)
        ])
    if tr_value is not None:
        cargs.extend([
            "--tr",
            str(tr_value)
        ])
    if resp_column is not None:
        cargs.extend([
            "--resp",
            str(resp_column)
        ])
    if cardiac_column is not None:
        cargs.extend([
            "--cardiac",
            str(cardiac_column)
        ])
    if trigger_column is not None:
        cargs.extend([
            "--trigger",
            str(trigger_column)
        ])
    if rvt_flag:
        cargs.append("--rvt")
    if heart_rate_flag:
        cargs.append("--heartrate")
    if pulseox_trigger_flag:
        cargs.append("--pulseox_trigger")
    if smooth_card is not None:
        cargs.extend([
            "--smoothcard",
            str(smooth_card)
        ])
    if smooth_resp is not None:
        cargs.extend([
            "--smoothresp",
            str(smooth_resp)
        ])
    if high_freq_cutoff is not None:
        cargs.extend([
            "--highfreqcutoff",
            str(high_freq_cutoff)
        ])
    if low_freq_cutoff is not None:
        cargs.extend([
            "--lowfreqcutoff",
            str(low_freq_cutoff)
        ])
    if init_thresh_c is not None:
        cargs.extend([
            "--initthreshc",
            str(init_thresh_c)
        ])
    if n_thresh_c is not None:
        cargs.extend([
            "--nthreshc",
            str(n_thresh_c)
        ])
    if init_thresh_r is not None:
        cargs.extend([
            "--initthreshr",
            str(init_thresh_r)
        ])
    if n_thresh_r is not None:
        cargs.extend([
            "--nthreshr",
            str(n_thresh_r)
        ])
    if invert_resp_flag:
        cargs.append("--invertresp")
    if invert_cardiac_flag:
        cargs.append("--invertcardiac")
    if noclean1_flag:
        cargs.append("--noclean1")
    if noclean2_flag:
        cargs.append("--noclean2")
    if load_card_phase is not None:
        cargs.extend([
            "--loadcardphase",
            execution.input_file(load_card_phase)
        ])
    if load_resp_phase is not None:
        cargs.extend([
            "--loadrespphase",
            execution.input_file(load_resp_phase)
        ])
    if vol_file is not None:
        cargs.extend([
            "--vol",
            execution.input_file(vol_file)
        ])
    if start_sample is not None:
        cargs.extend([
            "--startingsample",
            str(start_sample)
        ])
    if resp_add is not None:
        cargs.extend([
            "--respadd",
            resp_add
        ])
    if resp_del is not None:
        cargs.extend([
            "--respdel",
            resp_del
        ])
    if card_add is not None:
        cargs.extend([
            "--cardadd",
            card_add
        ])
    if card_del is not None:
        cargs.extend([
            "--carddel",
            card_del
        ])
    if verbose_flag:
        cargs.append("-v")
    if debug_flag:
        cargs.append("--debug")
    if help_flag:
        cargs.append("-h")
    ret = PoppOutputs(
        root=execution.output_file("."),
        processed_data_output=execution.output_file(output_basename + "_processed.txt"),
        timing_output=execution.output_file(output_basename + "_timing.txt"),
        rvt_data_output=execution.output_file(output_basename + "_rvt.txt"),
        heartrate_data_output=execution.output_file(output_basename + "_heartrate.txt"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "POPP_METADATA",
    "PoppOutputs",
    "popp",
]
