Skip to content

Add GCIMSDataset methods for getChromatogram()/getSpectrum() - #53

Merged
zeehio merged 5 commits into
masterfrom
claude/gcims-dataset-chromatogram-spectrum
Jul 16, 2026
Merged

Add GCIMSDataset methods for getChromatogram()/getSpectrum()#53
zeehio merged 5 commits into
masterfrom
claude/gcims-dataset-chromatogram-spectrum

Conversation

@zeehio

@zeehio zeehio commented Jul 16, 2026

Copy link
Copy Markdown
Member

getChromatogram()/getSpectrum() are now S4 generics (previously plain
functions working only on GCIMSSample). The new GCIMSDataset methods
extract one chromatogram/spectrum per sample and wrap them in a new
GCIMSChromatogramSet/GCIMSSpectrumSet object, together with a copy of
pData(dataset) so plots can use the dataset's annotations.

Each sample keeps its own native retention/drift time axis inside the
Set (no interpolation onto a shared grid), and the new plot() methods
combine them by row-binding rather than requiring a common axis, so
mismatched sample axes are never silently distorted. plot(..., color_by
= ) lets you color by group instead of just SampleID.

The vignette now demonstrates getChromatogram(dataset, ...)/
getSpectrum(dataset, ...) right after smoothing the whole dataset, as a
simpler alternative to manually picking one sample to visualize.

Regenerated NAMESPACE/man with roxygen2 7.3.1 (matching RoxygenNote),
which also picked up previously stale docs for DelayedDatasetBase's
dropSolePendingOp() method (added in an earlier PR, never regenerated).

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_019V3CHRGSzcEu3k6tpUFv56

claude added 5 commits July 16, 2026 04:22
getChromatogram()/getSpectrum() are now S4 generics (previously plain
functions working only on GCIMSSample). The new GCIMSDataset methods
extract one chromatogram/spectrum per sample and wrap them in a new
GCIMSChromatogramSet/GCIMSSpectrumSet object, together with a copy of
pData(dataset) so plots can use the dataset's annotations.

Each sample keeps its own native retention/drift time axis inside the
Set (no interpolation onto a shared grid), and the new plot() methods
combine them by row-binding rather than requiring a common axis, so
mismatched sample axes are never silently distorted. plot(..., color_by
= <any pData column>) lets you color by group instead of just SampleID.

The vignette now demonstrates getChromatogram(dataset, ...)/
getSpectrum(dataset, ...) right after smoothing the whole dataset, as a
simpler alternative to manually picking one sample to visualize.

Regenerated NAMESPACE/man with roxygen2 7.3.1 (matching RoxygenNote),
which also picked up previously stale docs for DelayedDatasetBase's
dropSolePendingOp() method (added in an earlier PR, never regenerated).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019V3CHRGSzcEu3k6tpUFv56
…uction

GCIMSChromatogramSet/GCIMSSpectrumSet stored the sample identity in two
places (the names of the chromatograms/spectra list, and pData$SampleID)
with nothing enforcing they referred to the same set of samples. A
mismatched pData built this way constructed silently, and plot()'s
left_join(by = "SampleID") would then produce misleading NA/mismatched
annotations instead of failing loudly. initialize() now aborts with a
clear message when pData is missing a SampleID column, or its SampleID
values don't match the sample names as a set.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019V3CHRGSzcEu3k6tpUFv56
sampleNames() previously always returned names(chromatograms)/
names(spectra), ignoring pData entirely. Now, when pData is present, it
is treated as the source of truth for sample identity and order (mirrors
GCIMSDataset, where sampleNames<- keeps pData$SampleID in sync). This
also exposed a latent bug in plot(): it zipped x@chromatograms/x@spectra
together with sample_names positionally via purrr::map2(), which was
only correct because sampleNames() previously always matched the
underlying list's own order. Switched both plot() methods to look up
each sample by name (x[[sample_id]]) instead, so they stay correct
regardless of how pData's row order relates to the list's order. Added
regression tests for both the reordering and the plot() lookup.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019V3CHRGSzcEu3k6tpUFv56
Replace the previous fix (sampleNames() preferring pData, plot() doing
name-based lookups) with what was actually being asked for: enforce the
invariant structurally, at the points where it can be violated.

- initialize() now reorders pData's rows to match the chromatograms/
  spectra list order right after validating they refer to the same
  samples, so the two are positionally aligned from construction
  onward (matched by SampleID, not blindly reordered, so annotations
  stay attached to the right sample).
- Added a sampleNames<- replacement method for both classes, mirroring
  GCIMSDataset's own setter: renaming updates both the list names and
  pData$SampleID together, so they can never drift apart afterwards.

sampleNames() goes back to simply returning names(chromatograms)/
names(spectra), since alignment is now guaranteed rather than
special-cased in the getter.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019V3CHRGSzcEu3k6tpUFv56
…xist

CI (PR #53) failed R CMD check with:

  checking Rd \usage sections ... WARNING
  Undocumented arguments in Rd file 'GCIMSChromatogramSet-class.Rd': '...'
  Documented arguments not in \usage in Rd file 'GCIMSChromatogramSet-class.Rd': 'y'
  (same for GCIMSSpectrumSet-class.Rd)

plot()'s roxygen block was copy-pasted from plot-GCIMSChromatogram.R,
which documents a `y` param inherited from the base plot generic's
signature. But that method is function(x, ...), so roxygen renders its
\usage using the generic's own (x, y, ...) signature, whereas my method
is function(x, color_by = "SampleID", ...) -- an actual extra
parameter, which makes roxygen use the method's own formals verbatim,
with no y in it. Replaced the stale `@param y` with `@param ...
Ignored`, which now matches the generated \S4method{plot}{...}(x,
color_by = "SampleID", ...) usage exactly.

Verified locally with rcmdcheck: `checking Rd \usage sections` is back
to a NOTE (the one pre-existing, unrelated findPeaksImpl.Rd issue that
already exists on master), not a WARNING.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019V3CHRGSzcEu3k6tpUFv56
@zeehio
zeehio merged commit 5584790 into master Jul 16, 2026
1 check passed
@zeehio
zeehio deleted the claude/gcims-dataset-chromatogram-spectrum branch July 16, 2026 11:16
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