Event detection and duration in slow GCaMP traces with plateaus, superimposed transients and baseline wander: how do you handle it?

Data

  • C. elegans head neurons, GCaMP6s (nuclear-localised strain QW1217), about 120 neurons per animal, volumetric imaging at 2 Hz, about 22 min per recording, 9 animals.

  • Per-neuron raw fluorescence from tracked ROIs. A co-expressed RFP channel is available but is 3 to 4 times noisier frame to frame than GCaMP.

  • Four bright-light flashes per recording saturate the camera; about 7 s around each is masked. GCaMP (not RFP) rises about 16% after each flash and decays over about 40 s.

  • No neuron identities. Bleaching present; camera offset about 100 counts has to be subtracted.

Goal: A per-neuron “fingerprint” of activity (event rate, onset, duration, amplitude, area, shape). we need event boundaries that are accurate.

What the traces look like

  • Graded activity, not spikes.

  • Three kinds of activity, often in the same neuron:

    • fast-rising, slowly decaying transients (rise 1 to 3 s, decay 10 to 60 s);

    • plateaus lasting tens of seconds to minutes, with sharp fluctuations riding on top of them;

    • slow wander of the level over minutes, both above and below the apparent resting level.

  • Noise: white frame-to-frame noise plus a strongly correlated slow component (lag-1 autocorrelation about 0.5 to 0.7). We cannot tell how much of the slow component is biological.

  • About two thirds of neurons spend less than 15% of their time near their most common level, so there is no obvious “rest”.

Problems

  1. Baseline / resting level. A drift-following baseline (running percentile) removes slow activity and plateaus. A stiff baseline (bleaching only) turns slow wander into “events”. Lowest-percentile baselines sit far below rest. Mode-based rest and a two-state Gaussian mixture were not reliable either.

  2. Event boundaries.

    • Peak-prominence bases cut off the start of rises that begin below rest, or below where the trace settles afterwards.

    • Walking outward to the nearest trough recovers those onsets, but truncates slow decays that have small steps in them.

  3. Fragmentation. A plateau with sharp fluctuations on top is split into many short events instead of being one long event (optionally with sub-peaks). What merging rule decides “one event with ripples” versus “several events”?

  4. Overlapping and nested events. When a transient rides on a plateau, or a second transient starts before the first has decayed, the durations of both become unreliable. Joint fitting of several template shapes was non-unique.

  5. Shape classification. Labelling events as pulse / sawtooth / square from rise, fall and plateau times does not match what we see by eye. Template fits (rise, hold, exponential decay) fit isolated events but not real overlapping ones.

  6. Sensitivity versus false positives, with no ground truth.

    • Threshold detectors (k x noise SD) either miss slow events or produce many small ones.

    • Phase-randomised surrogates keep the slow spectrum, so small slow events cannot be told apart from surrogate fluctuations.

    • Our simulator’s event shapes are our own assumptions, so validating against it is partly circular.

  7. Fast onsets versus slow events. Smoothing smears sharp onsets. Derivative or step detectors miss slow rises.

What we tried

  • Baselines: lowest 1%; running 10th percentile (150 s); asymmetric least squares (stiff); half-sample mode; two-component Gaussian mixture.

  • Detectors:

    • threshold with hysteresis (MAD noise);

    • step / derivative “upswing” detector, single- and multi-scale;

    • matched filter;

    • two-state HMM;

    • shift-invariant Haar wavelet denoising plus a peak-prominence event tree;

    • surrogate-based per-neuron confidence bars.

  • Shape fits: rise / hold / decay templates, fitted singly and jointly for overlapping events.

Questions:

  1. Do people avoid discrete events altogether for fingerprints like this and use continuous features (fraction of time “high”, derivative statistics, spectra) instead?

  2. How do you segment a plateau that has transients on top: hysteresis thresholds, a minimum dip depth between events, a minimum event duration, persistence or prominence rules? How do you choose those parameters?

  3. Is state segmentation better suited to graded worm neurons than event detection? For example: rise / high / fall / low phases from a regularised derivative, HMMs, switching linear dynamical systems, or change-point detection. Can those give per-state durations?

  4. Are there any signal “smoothing”/de-noising treatments that might work and what is your experience with them?

I’m at a loss for what to do next to get reliable event detection. Am i even thinking about this correctly? Please advise if you can!!

Thank you in advance!!

I’d separate the fingerprint question from finding a single correct event boundary. If the same slow component can be assigned to either baseline drift or sustained activity, an HMM will still need assumptions to distinguish them; its state durations won’t independently validate that distinction.

For a first fingerprint, I’d compare a small set of continuous summaries across several plausible baseline choices and ask whether the neuron rankings or clusters survive. Fraction of time above a threshold still needs an explicit reference level. A feature that changes substantially with that choice should carry that uncertainty into the fingerprint. For plateaus with peaks on top, I’d keep coarse elevated-state occupancy and within-state peak counts separate, rather than force both into one non-overlapping event list.

The flash response also seems worth a separate sensitivity analysis: your seven-second mask is shorter than the reported roughly forty-second response. I’d compare fingerprints with and without those longer flash-locked windows, without assuming the green-channel change is necessarily an artefact.

What will the fingerprints be used for: clustering within a recording, comparing conditions, or matching across animals? That seems important for deciding which ambiguities are tolerable. These are analysis suggestions, not a pipeline I’ve validated on your recordings.

I’d include equal-duration masks placed away from the flashes as a comparison. If neuron rankings shift just as much there, losing data or ordinary non-stationarity may explain some of the change. That would help interpret the sensitivity test without deciding whether the flash-locked response is biological.