Skip to content

Reimplement plotTIS()/plotRIC() on the Set classes; add single-sample methods - #54

Merged
zeehio merged 2 commits into
masterfrom
claude/gcims-plotric-plottis-refactor
Jul 16, 2026
Merged

Reimplement plotTIS()/plotRIC() on the Set classes; add single-sample methods#54
zeehio merged 2 commits into
masterfrom
claude/gcims-plotric-plottis-refactor

Conversation

@zeehio

@zeehio zeehio commented Jul 16, 2026

Copy link
Copy Markdown
Member

Summary

  • plotTIS()/plotRIC() for GCIMSDataset are reimplemented on top of GCIMSSpectrumSet/GCIMSChromatogramSet (added in Add GCIMSDataset methods for getChromatogram()/getSpectrum() #53), removing the duplicated reshape2::melt() + ggplot() code between the two functions. getTIS()/getRIC() still return matrices unchanged (used internally by align() and by any external callers), and the joint per-sample RIC+TIS extraction optimization is untouched.
  • Both gained a color_by parameter (defaults to "SampleID", preserving current behavior) that lets you color by any pData() column, not just SampleID.
  • plotTIS()/plotRIC() now also have GCIMSSample methods, closing a gap: every other TIS/RIC-adjacent generic (getChromatogram, getSpectrum, smooth, baseline, findPeaks) already worked on both GCIMSSample and GCIMSDataset, but these two didn't. RIC's chromatogram carries an accurate single-value drift time (the RIP position), not a misleading range or NA.
  • The RIP-position computation (which.max(rowSums(intensity(object)))) was independently duplicated in getRIC() and alignDt() (the latter via getTIS()). Factored into one unexported rip_position() helper used by both, plus the new plotRIC().
  • The vignette's two hand-rolled single-sample TIS/RIC plots (manual data.frame() + ggplot(), including a vestigial no-op dplyr::filter()) are now one-line plotTIS()/plotRIC() calls.

Test plan

  • Full testthat suite passes, including new tests for plotTIS/plotRIC on both GCIMSSample and GCIMSDataset (default behavior, range restriction, color_by, empty-set error handling)
  • align-GCIMSDataset.R/align-GCIMSSample.R tests (the actual consumers of getRIC/getTIS/alignDt) pass unchanged, confirming the matrix-returning contract and RIP-position refactor didn't change numerical behavior
  • Verified locally with rcmdcheck against the pinned roxygen2 version — no new WARNINGs; the two vignette-build WARNINGs seen locally are an artifact of skipping vignette rebuilding to save time and don't occur in CI's actual build step

Generated by Claude Code

claude added 2 commits July 16, 2026 13:15
…atogramSet

plotTIS() and plotRIC() had near-identical, duplicated code to melt a
matrix into long format and build a ggplot with SampleID coloring. Now
both build a GCIMSSpectrumSet/GCIMSChromatogramSet from the (possibly
sample-subsetted) matrix and delegate the actual plotting to
plot.GCIMSSpectrumSet/plot.GCIMSChromatogramSet, removing the
duplication. This also lets both gain a color_by parameter (defaulting
to "SampleID", preserving prior behavior) to color by any pData()
column, matching the annotation-aware plotting GCIMSChromatogramSet/
GCIMSSpectrumSet were built for.

getTIS()/getRIC() themselves are untouched: they keep returning
interpolated matrices via the joint per-sample extraction
(extract_RIC_and_TIS), since that's still the right representation for
a matrix API and is relied on directly by align-GCIMSDataset.R.

Updated the existing plotTIS/plotRIC tests: plot.*Set() attaches data at
the top-level ggplot object (ggplot(df) + geom_line(mapping = ...)),
not per-layer like the old geom_line(data = ...) did, so tests now read
p$data instead of p$layers[[1]]$data. Added a test for the new color_by
parameter.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019V3CHRGSzcEu3k6tpUFv56
plotTIS/plotRIC previously only had GCIMSDataset methods, unlike every
other TIS/RIC-adjacent generic (getChromatogram, getSpectrum, smooth,
baseline, findPeaks), which work on both GCIMSSample and GCIMSDataset.
Add the GCIMSSample methods, mirroring the dataset-level ones: wrap the
existing getTIS()/getRIC() output in a GCIMSSpectrum/GCIMSChromatogram
(populated the same way getSpectrum()/getChromatogram() do) and
delegate to their existing plot() methods.

RIC is extracted from a single drift-time row (the RIP position), not
aggregated across a range, so its chromatogram's drift_time_idx/
drift_time_ms are set to that one accurate value (via
dt_rt_range_normalization()'s existing single-index support) rather
than a misleading range or NA.

That RIP-position computation (which.max(rowSums(intensity(object))))
was previously duplicated in both getRIC() and alignDt() (the latter
reaching it via getTIS() instead). Factored it into one unexported
rip_position() helper used by both, plus the new plotRIC(), so there's
a single definition instead of three.

Simplified the vignette's two hand-rolled single-sample TIS/RIC plots
(manual data.frame + ggplot, including a vestigial no-op dplyr::filter)
into plotTIS()/plotRIC() calls now that they exist.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019V3CHRGSzcEu3k6tpUFv56
@zeehio
zeehio merged commit d80a760 into master Jul 16, 2026
1 check passed
@zeehio
zeehio deleted the claude/gcims-plotric-plottis-refactor branch July 16, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants