Skip to contents

GCMSprime searches recovered spectra using their fitted ion totals. When a retention-index (RI) calibration is available, the selected column class and tolerance restrict the candidates. Spectral scores then rank the remaining references. The same interface accepts sparse in-memory libraries and large SQLite libraries. The search benchmark reports the speed and accuracy of each spectral comparison on EI reference spectra.

One call after deconvolution

library(GCMSprime)
lib <- readMSP("library.msp", backend="sqlite", db_file="library.sqlite")
cal <- calibrateRI("alkanes.cdf", carbon=7:23, psf=fit$psf_standard)
weights <- libraryIonWeights(lib)  # compute once and reuse

identified <- identifyCompounds(fit, lib, calibration=cal,
  phase="DB5", ri_tolerance=30, n_matches=5,
  method=c("stein_scott_angular", "multinomial"), ion_weights=weights,
  msp_file="sample_identified.msp", xlsx_file="sample_identified.xlsx")

identified$compounds
identified$identification$matches

The first method supplies the best-match columns in the compound table. Every returned match, its spectral score, RI difference, reference provenance and ion totals are included in the Excel Matches sheet. MSP output retains unique peak names, the RI, fitted pseudocount and tentative library annotation. Profiles, spectra and the model objective stay unchanged.

Identification can also run during the CDF workflow:

fit <- gcmsDeco("sample.cdf", "sample.msp", xlsx_file="sample.xlsx",
  alkanes_file="alkanes.cdf", precluster=32L, library=lib,
  search=list(phase="DB5", ri_tolerance=30, n_matches=5,
              method="stein_scott"))

Inspect calibration and retention constraints

cal$anchors[, c("carbon", "start", "narrow_width", "retention_time", "RI", "residual")]
cal$candidates

The timing anchor is peak onset at 1% of height plus half a local narrow-peak width. This reduces the influence of long tails on RI estimation. Standards and sample profiles use the same convention. A natural cubic spline interpolates the alkane coordinates and their indices exactly. phase="DB5" is the default; DB1 and DBWAX are also supported. ri_tolerance=30 admits compatible references within 30 index units. Use a standard acquired under the sample’s programme.

Unlabelled reference RIs keep their provenance. If their column class is known, set unknown_phase="DB5" explicitly. ri_tolerance=Inf requests spectral-only searching. The identification theory gives the calibration, column matching and missing-reference rules.

RIs can also be exported without searching a library:

fit <- annotateRI(fit, cal, phase="DB5",
  msp_file="sample_RI.msp", xlsx_file="sample_RI.xlsx")
fit$compounds[c("peak_onset", "retention_coordinate", "retention_index")]

The MSP uses NIST’s Retention_index: SemiStdNP=... field for a DB5-type column. Excel retains the alkane assignments and timing coordinates. By default, peaks outside the calibrated range receive no RI. Set extrapolate=TRUE to use the natural spline’s linear tails; the compound table and MSP comments flag these values. annotateRI() also annotates a multisample result and exports median consensus RIs with the sample values.

Choose spectral comparisons

Method Main use
stein_scott Mass- and intensity-weighted dot product; the default EI comparison
cosine, angular Compare spectral directions; angular gives the corresponding geometric distance
hellinger Compare square-root-normalized ion patterns
jensen_shannon, multinomial Symmetric probability/count comparisons retaining fitted query totals
stein_scott_angular Angular distance after the Stein–Scott transform
w <- libraryIonWeights(lib)
matches <- librarySearch(fit, lib, calibration=cal, phase="DB5",
  ri_tolerance=30, n_matches=5,
  method=c("stein_scott", "hellinger", "multinomial"), ion_weights=w)
as.data.frame(matches)

Uniform ion weights are the default. Reusable rarity weights emphasize ions seen in fewer library spectra. Relative-intensity references with unknown ion totals are balanced to the query total for multinomial comparisons. The formulas and benchmark explain the transformations, weights, zero handling, score scales and accuracy.

Identify a multisample experiment

experiment <- gcmsDeco("chromatograms", output_dir="identified_results",
  precluster=32L, library=lib,
  search=list(phase="DB5", ri_tolerance=30, n_matches=5,
              method=c("stein_scott", "hellinger")))

occurrences <- do.call(rbind, lapply(experiment$paths,
  function(path) readRDS(path)$compounds))
occurrences <- occurrences[order(occurrences$match_score, decreasing=TRUE), ]
unique_compounds <- occurrences[!duplicated(occurrences$coupled_compound), ]

Library search runs on each final original-channel sample spectrum, using that sample’s alkane calibration. Consensus IDs connect repeated occurrences. The summary above retains the best-scoring occurrence annotation per consensus compound; full ranked matches and RI differences remain in each sample report.

See multiple-sample deconvolution for directory structure and spectral library import for open/commercial data.