gcmsDeco() takes a CDF file for one sample or a
directory of CDF files for a batch. With a directory, it estimates one
mass spectrum per compound across the batch and integrates a separate
elution profile in each sample where the compound occurs. The example
below fits the batch once and searches each shared spectrum once.
Install R, RStudio and GCMSprime
On Windows, install the following in order.
- Install R for Windows from CRAN.
- Install the open-source RStudio Desktop for Windows.
- Install the Rtools version listed for your version of R in its default location. Rtools provides the C++ compiler used by the GitHub packages below. If RStudio is open, restart it.
In the RStudio Console, run the following once. The same R commands install the packages on macOS or Linux with the R build tools available.
install.packages(c("remotes", "ncdf4", "openxlsx", "DBI", "RSQLite", "jsonlite"))
remotes::install_github(c(
"tomwenseleers/L0glm/L0glm",
"tomwenseleers/logconNMF/logconNMF",
"tomwenseleers/GCMSprime/GCMSprime"
))Prepare a reference library
If your reference library is already in MSP format, use it directly. To convert a vendor-formatted Agilent or Shimadzu library, including a licensed NIST library, use OpenChrom.
- At first launch, choose Yes at the Vendor plugins missing prompt. Select Agilent ChemStation GC-MS for an Agilent library or Shimadzu MS Database for a Shimadzu library. Install the converter and restart OpenChrom.
- Open Data Analysis. In the file browser,
double-click the Agilent
.Llibrary folder or the Shimadzu.spcfile. - Choose File → Save As…, select the NIST text format
(
*.msp) and save the library aslibrary.msp.
From the R working directory containing library.msp,
import it once. SQLite is convenient for a full NIST library.
In a later session, run library(GCMSprime) and
lib <- openLibrary("library.sqlite") to reopen the
index.
Fit a batch of chromatograms
Export each sample as an ANDI-MS (.cdf) file. Put at
least two sample files under chromatograms/ in the same
working directory. Put any alkane standards in the reserved
standards/ subdirectory.
chromatograms/
sample01.cdf
sample02.cdf
standards/
alkanes.cdf
fit <- gcmsDeco("chromatograms", output_dir = "results")GCMSprime orders samples by acquisition time and uses the nearest
standard if several were run. If the CDFs lack acquisition dates, supply
their order explicitly, for example by adding
batch = list(sample_order = c("sample01.cdf", "sample02.cdf"))
to the call.
Open results/experiment.xlsx for the compound and area
tables. results/areas.csv gives integrated areas by sample
and compound, and results/consensus.msp contains the shared
spectra. In R, coef(fit) returns those spectra as a
compound-by-ion matrix.
Search the shared spectra
With an alkane standard, use the column phase to restrict the search
by retention index (RI). Here the samples were run on a DB-5-type
column. Use "DBWAX" or "DB1" for the
corresponding phases. GCMSprime calibrates each sample against its
standard, then takes the median RI across occurrences of each compound.
The search returns up to five reference spectra within ±30 RI units on
that phase.
phase <- "DB5"
fit <- annotateRI(fit, phase = phase)
hits <- librarySearch(coef(fit), lib,
ri = fit$retentionIndices$retention_index,
phase = phase, ri_tolerance = 30, n_matches = 5L)If you have no alkane standard or the library lacks RIs for your column, use this spectral-only search instead.
hits <- librarySearch(coef(fit), lib, ri_tolerance = Inf, n_matches = 5L)Save the ranked candidates alongside the area table. The
compound column identifies the fitted compound,
rank orders its candidate matches, and
delta_RI gives the library RI minus the measured RI when
both are available.
write.csv(hits$matches, "results/library_matches.csv", row.names = FALSE)