← Về thư mục
📄 / / profiles / r-and-d / raw_evidence / OpenAI4S / skills / bioskills / bio-temporal-genomics-trajectory-modeling / references / usage-guide.md

Temporal Trajectory Modeling - Usage Guide

Overview

This skill fits continuous trajectories to BULK or time-resolved omics where the x-axis is MEASURED experimental time (hours, days, developmental stage) or a pseudobulk value aggregated over real time - it is explicitly not single-cell pseudotime. Two complementary jobs: penalized-spline GAMs (mgcv) model gradually curving trends and test whether expression changes or differs between conditions, while changepoint methods (segmented, ruptures) locate discrete regime shifts. Three decisions gate correctness before any p-value: the distributional scale (raw overdispersed counts need nb() plus a library-size offset, not Gaussian), residual autocorrelation across ordered timepoints (which inflates smooth-term significance if ignored), and whether the mechanism is gradual (GAM) or genuinely abrupt (changepoint). The basis dimension k is a flexibility ceiling below the number of timepoints, not a knot count; REML picks the realized wiggliness and edf reports it.

Prerequisites

R

install.packages(c('mgcv', 'segmented'))
BiocManager::install('tradeSeq')

Python

pip install ruptures numpy matplotlib pandas

Data Requirements

Quick Start

Tell the AI agent what to model: - "Fit smooth GAM curves to my gene expression over time and test which genes change" - "My input is raw counts - model them on the correct distributional scale" - "Test whether treated samples diverge from controls over time with a difference smooth" - "My timepoints are correlated - handle residual autocorrelation in the GAM" - "Detect changepoints where expression shifts abruptly, and check the shift is real"

Example Prompts

GAM Trajectory Fitting

"Fit a generalized additive model to each gene in my RNA-seq time-course and report which genes have significant temporal trends after FDR correction."

"I have 10 timepoints of variance-stabilized expression. Fit smooth curves and give me the effective degrees of freedom per gene, using REML."

Distribution and Autocorrelation

"My data are raw RNA-seq counts with varying library sizes. Fit a negative-binomial GAM with a library-size offset rather than a Gaussian model."

"My samples are a single series measured repeatedly over time, so timepoints are correlated. Fit a GAM that models the residual autocorrelation and check the residual ACF."

Condition Comparison

"I have time-course RNA-seq from WT and KO mice. Test which genes have diverging temporal trajectories using an ordered-factor difference smooth."

"Compare drug-treated vs untreated expression curves over time and give me a single p-value for whether the trajectories differ."

Changepoint Detection

"Find genes where expression shifts abruptly during my developmental time course, and confirm the shift is a real regime change rather than a smooth ramp."

"Detect breakpoints in my temporal expression data. Distinguish a slope change from a level jump, and tell me when the regime shifts."

Model Selection

"For each gene, compare a smooth GAM against a linear fit by AIC and report whether non-linear modeling is warranted."

What the Agent Will Do

  1. Load expression data and measured-time metadata; confirm the scale matches the family (vst/log-CPM for Gaussian, raw counts with an offset for nb())
  2. Fit GAMs per gene with k set below the number of unique timepoints and REML smoothing
  3. Model residual autocorrelation with corAR1/bam(rho=) where the design warrants it, and inspect the residual ACF
  4. Run diagnostics (gam.check/k.check, concurvity for multi-smooth models), responding to a low k-index by doubling k and refitting rather than reflexively raising it
  5. Test condition divergence with an ordered-factor difference smooth plus the required parametric main effect
  6. Correct smooth-term p-values across genes with BH FDR, treating them as approximate
  7. Detect changepoints with a noise-calibrated penalty and a cost model matched to the shift type, pre-testing that a break exists
  8. Predict trajectories only within the sampled time range with pointwise confidence bands, and export result tables

Tips