| Title: | Reproducible 'targets' Pipelines for Physiological Signal Analysis |
|---|---|
| Description: | A collection of reusable 'targets' target factories for the Physio ecosystem: drop-in pipelines for the standard single-modality analyses (ECG heart-rate variability, EEG band power, EMG amplitude/fatigue, EDA skin conductance) plus multi-record cohort branching and Quarto reporting. Each factory returns a list of targets so a whole reproducible '_targets.R' is a couple of lines, with incremental re-runs and byte-level provenance. |
| Authors: | Yusuke Matsui [aut, cre] |
| Maintainer: | Yusuke Matsui <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-10-03 13:42:56 UTC |
| Source: | https://github.com/x-biosignal/PhysioPipe |
Stack per-branch data frames from a cohort run into one table
pp_bind_cohort(branches, id = NULL)pp_bind_cohort(branches, id = NULL)
branches |
A list of per-record data frames (dynamic-branch output). |
id |
Optional vector of record ids, added as a |
A single row-bound data frame.
branches <- list( data.frame(sdnn = 50), data.frame(sdnn = 61) ) pp_bind_cohort(branches, id = c("rec100", "rec101"))branches <- list( data.frame(sdnn = 50), data.frame(sdnn = 61) ) pp_bind_cohort(branches, id = c("rec100", "rec101"))
File paths of the bundled demo ECG record (MIT-BIH 100 excerpt)
pp_ecg_demo_files()pp_ecg_demo_files()
Character vector of the record's companion files (.dat, .hea).
Read a WFDB record (by companion files or base) into a PhysioExperiment
pp_ecg_read(record)pp_ecg_read(record)
record |
Either the companion files ( |
A PhysioExperiment.
Join time- and frequency-domain HRV into one row per channel
pp_hrv_combine(hrv_time, hrv_freq)pp_hrv_combine(hrv_time, hrv_freq)
hrv_time |
Output of |
hrv_freq |
Output of |
A data frame merged on channel.
hrv_time <- data.frame(channel = "MLII", sdnn = 50, rmssd = 42) hrv_freq <- data.frame(channel = "MLII", lf = 400, hf = 330) pp_hrv_combine(hrv_time, hrv_freq)hrv_time <- data.frame(channel = "MLII", sdnn = 50, rmssd = 42) hrv_freq <- data.frame(channel = "MLII", lf = 400, hf = 330) pp_hrv_combine(hrv_time, hrv_freq)
Write a simple RR tachogram PNG (headless) and return its path
pp_plot_tachogram(rr, path = "figures/tachogram.png")pp_plot_tachogram(rr, path = "figures/tachogram.png")
rr |
Output of |
path |
Output PNG path. |
path (so the target can be format = "file").
Deterministic (seeded) synthetic signals per modality. Clearly synthetic — for exercising a pipeline's mechanics, not for making claims.
pp_simulate( modality = c("eeg", "emg", "eda"), seed = 1L, n_channels = NULL, duration = NULL, sampling_rate = NULL )pp_simulate( modality = c("eeg", "emg", "eda"), seed = 1L, n_channels = NULL, duration = NULL, sampling_rate = NULL )
modality |
One of "eeg", "emg", "eda". |
seed |
Integer RNG seed (fixed so pipelines stay reproducible). |
n_channels, duration, sampling_rate
|
Optional geometry overrides. |
A PhysioExperiment (time x channels) with a raw assay.
if (requireNamespace("PhysioCore", quietly = TRUE)) { pe <- pp_simulate("eeg") }if (requireNamespace("PhysioCore", quietly = TRUE)) { pe <- pp_simulate("eeg") }
Companion files of a WFDB record base
pp_wfdb_files(base)pp_wfdb_files(base)
base |
Record base path (no extension), e.g. |
Character vector of existing base.* signal/header files.
# Create a stand-in record base and list its WFDB companion files. base <- file.path(tempdir(), "100") file.create(paste0(base, c(".dat", ".hea", ".atr"))) basename(pp_wfdb_files(base))# Create a stand-in record base and list its WFDB companion files. base <- file.path(tempdir(), "100") file.create(paste0(base, c(".dat", ".hea", ".atr"))) basename(pp_wfdb_files(base))
Intermediate/terminal tables written as Parquet can be read by Python
(pandas/pyarrow), DuckDB, and Nextflow processes — unlike the default .rds
target store. This is the seam that keeps pipelines orchestrator-agnostic.
pp_write_parquet(df, path)pp_write_parquet(df, path)
df |
A data frame. |
path |
Output |
path (so the target can be format = "file").
if (requireNamespace("arrow", quietly = TRUE)) { path <- pp_write_parquet(data.frame(a = 1:3, b = 4:6), file.path(tempdir(), "demo.parquet")) file.exists(path) }if (requireNamespace("arrow", quietly = TRUE)) { path <- pp_write_parquet(data.frame(a = 1:3, b = 4:6), file.path(tempdir(), "demo.parquet")) file.exists(path) }
Builds a standard resting-ECG pipeline as a list of targets:
read -> lead -> R-peaks -> RR -> {HRV time, HRV freq} -> summary, plus an
RR-tachogram figure. With more than one record it fans out via dynamic
branching (one branch per record) and adds a combined cohort table.
tar_ecg_hrv( name = "ecg", records = NULL, channel = 1L, detector = "pan_tompkins" )tar_ecg_hrv( name = "ecg", records = NULL, channel = 1L, detector = "pan_tompkins" )
name |
Target-name prefix (a string; targets are |
records |
|
channel |
Lead index to analyse (MIT-BIH 100: 1 = MLII, 2 = V5). |
detector |
|
A list of target objects to splice into a _targets.R pipeline.
tar_eeg_bandpower(), tar_emg_features(), tar_eda_scr()
# The factory returns target objects to splice into a `_targets.R` list(); # building them does not run the pipeline. targs <- tar_ecg_hrv() # bundled demo record (single-record pipeline) length(targs) class(targs[[1]]) # Cohort fan-out (dynamic branching) when given several record bases: length(tar_ecg_hrv(records = c("data/100", "data/101")))# The factory returns target objects to splice into a `_targets.R` list(); # building them does not run the pipeline. targs <- tar_ecg_hrv() # bundled demo record (single-record pipeline) length(targs) class(targs[[1]]) # Cohort fan-out (dynamic branching) when given several record bases: length(tar_ecg_hrv(records = c("data/100", "data/101")))
signal -> tonic/phasic decomposition -> SCR features.
tar_eda_scr(name = "eda", source = NULL)tar_eda_scr(name = "eda", source = NULL)
name |
Target-name prefix. |
source |
Expression producing a PhysioExperiment, or NULL for a synthetic EDA demo (drifting SCL + discrete SCRs). |
A list of targets.
# Returns target objects (synthetic EDA demo: drifting SCL + discrete SCRs). targs <- tar_eda_scr() length(targs)# Returns target objects (synthetic EDA demo: drifting SCL + discrete SCRs). targs <- tar_eda_scr() length(targs)
signal -> band power per channel. Band power is computed from the Welch PSD
integrated over each band, so it is inherently frequency-selective (no
pre-filter needed).
tar_eeg_bandpower( name = "eeg", source = NULL, bands = list(alpha = c(8, 13), beta = c(13, 30)), method = "welch", relative = FALSE )tar_eeg_bandpower( name = "eeg", source = NULL, bands = list(alpha = c(8, 13), beta = c(13, 30)), method = "welch", relative = FALSE )
name |
Target-name prefix. |
source |
Expression producing a PhysioExperiment, or NULL for a synthetic EEG demo (10 Hz alpha + noise). |
bands |
Named list of |
method |
Welch or wavelet PSD. |
relative |
Report band power relative to total. |
A list of targets.
# Returns target objects (synthetic EEG demo); splice into a `_targets.R`. targs <- tar_eeg_bandpower() length(targs) # Point it at a real file instead of the synthetic demo: # tar_eeg_bandpower(source = quote(PhysioIO::readEDF("sub01.edf")))# Returns target objects (synthetic EEG demo); splice into a `_targets.R`. targs <- tar_eeg_bandpower() length(targs) # Point it at a real file instead of the synthetic demo: # tar_eeg_bandpower(source = quote(PhysioIO::readEDF("sub01.edf")))
signal -> linear envelope and signal -> spectral fatigue (median/mean
frequency + RMS over windows).
tar_emg_features(name = "emg", source = NULL)tar_emg_features(name = "emg", source = NULL)
name |
Target-name prefix. |
source |
Expression producing a PhysioExperiment, or NULL for a synthetic bursty EMG demo. |
A list of targets.
# Returns target objects (synthetic bursty-EMG demo). targs <- tar_emg_features() length(targs)# Returns target objects (synthetic bursty-EMG demo). targs <- tar_emg_features() length(targs)
Wraps tarchetypes::tar_quarto_raw() so a rendered report becomes a tracked
target that re-renders when any embedded result changes. The .qmd reads
results with targets::tar_read(); targets discovers those dependencies
automatically.
tar_physio_report(name = "report", path = NULL)tar_physio_report(name = "report", path = NULL)
name |
Target name (string). |
path |
Path to the |
A single target object (requires the tarchetypes and quarto
packages plus the Quarto CLI at build time).
# list(tar_ecg_hrv(), tar_physio_report())# list(tar_ecg_hrv(), tar_physio_report())