| Title: | Spectra to queries |
|---|---|
| Description: | Translates tandem mass spectrometry (MS/MS) spectral libraries into diagnostic fragment and neutral-loss ion queries for chemical structure and skeleton classification, ranked by Matthews Correlation Coefficient (MCC). |
| Authors: | Adriano Rutz [aut, cre] (ORCID: <https://orcid.org/0000-0003-0443-9902>), Sarah Szwarc [ctb] (ORCID: <https://orcid.org/0000-0001-6369-5522>) |
| Maintainer: | Adriano Rutz <[email protected]> |
| License: | AGPL (>= 3) |
| Version: | 0.0.0.9002 |
| Built: | 2026-11-20 20:10:35 UTC |
| Source: | https://github.com/spectra-to-knowledge/SpectraToQueries |
A data.frame containing 321 MS/MS spectra of monoterpene
indole alkaloids (MIAs) from the MIADB (Monoterpene Indole Alkaloid
Database) across 81 fine-grained chemical skeletons (SKELETON). This is
stored as a portable data.frame with mz and intensity peaks as list
columns, and is automatically converted to a Spectra::Spectra object
when used in spectra_to_queries().
mia_spectra_dfmia_spectra_df
A data.frame with 321 rows and 37 columns:
Metadata columns: msLevel, rtime, acquisitionNum, TITLE,
PRECURSOR_MZ, SKELETON (81 unique skeletons), and other MS/MS
spectrum attributes
mz (list): Fragment m/z values for each spectrum
intensity (list): Fragment intensities for each spectrum
Total of 24,255 peaks across all 321 spectra (median 66 peaks per spectrum).
The mia_spectra_df object represents the spectral data with fine-grained
skeleton annotations. Use mia_spectra_grouped_df for the variant with
broader grouped skeleton annotations.
This portable data.frame format enables cross-platform distribution and
is automatically converted to a Spectra::Spectra object by
spectra_to_queries().
Data extracted from MIADB, a public spectral library of monoterpene indole alkaloids.
Accompanying publication: Szwarc, S., Rutz, A., Lee, K. et al. (2025). "Translating community-wide spectral library into actionable chemical knowledge: a proof of concept with monoterpene indole alkaloids." Journal of Cheminformatics, 17:62. doi:10.1186/s13321-025-01009-0
utils::data(mia_spectra_df, package = "SpectraToQueries") nrow(mia_spectra_df) # 321 spectrautils::data(mia_spectra_df, package = "SpectraToQueries") nrow(mia_spectra_df) # 321 spectra
A data.frame containing the 321 MS/MS spectra from the MIADB
(Monoterpene Indole Alkaloid Database) with SKELETON annotations grouped
into 53 broader chemical skeleton classes. Stored as a portable data.frame
with mz and intensity peaks as list columns.
mia_spectra_grouped_dfmia_spectra_grouped_df
A data.frame with 321 rows and 36 columns:
Metadata columns: msLevel, rtime, acquisitionNum, TITLE,
PRECURSOR_MZ, SKELETON (53 grouped skeleton classes), and other
MS/MS spectrum attributes
mz (list): Fragment m/z values for each spectrum
intensity (list): Fragment intensities for each spectrum
Total of 24,255 peaks across all 321 spectra (median 66 peaks per spectrum).
In this dataset, closely related sub-skeletons are merged into broader
skeleton classes (e.g., corynanthean_1+corynanthean_2+...) to evaluate
diagnostic ion queries at a higher structural hierarchy level.
This portable data.frame format enables cross-platform distribution and
is automatically converted to a Spectra::Spectra object by
spectra_to_queries().
Data extracted from MIADB, a public spectral library of monoterpene indole alkaloids.
Accompanying publication: Szwarc, S., Rutz, A., Lee, K. et al. (2025). "Translating community-wide spectral library into actionable chemical knowledge: a proof of concept with monoterpene indole alkaloids." Journal of Cheminformatics, 17:62. doi:10.1186/s13321-025-01009-0
utils::data(mia_spectra_grouped_df, package = "SpectraToQueries") nrow(mia_spectra_grouped_df) # 321 spectra length(unique(mia_spectra_grouped_df$SKELETON)) # 53 grouped classesutils::data(mia_spectra_grouped_df, package = "SpectraToQueries") nrow(mia_spectra_grouped_df) # 321 spectra length(unique(mia_spectra_grouped_df$SKELETON)) # 53 grouped classes
Converts tandem mass spectra into diagnostic fragment (_frag)
and neutral-loss (_nl) ion queries ranked by Matthews Correlation
Coefficient (MCC), together with ready-to-run MassQL queries.
spectra_to_queries( spectra = NULL, export = "data/interim/queries.tsv", dalton = 0.01, decimals = 4L, intensity_min = 0, ions_max = 10L, n_skel_min = 5L, n_spec_min = 3L, ppm = 30, mcc_min = 0, precision_min = 0, recall_min = 0, zero_val = 0 )spectra_to_queries( spectra = NULL, export = "data/interim/queries.tsv", dalton = 0.01, decimals = 4L, intensity_min = 0, ions_max = 10L, n_skel_min = 5L, n_spec_min = 3L, ppm = 30, mcc_min = 0, precision_min = 0, recall_min = 0, zero_val = 0 )
spectra |
A Spectra::Spectra object, a portable |
export |
Export file path for the resulting TSV table (or |
dalton |
Tolerance in Dalton. Default is |
decimals |
Number of decimals for rounding. Default is |
intensity_min |
Minimal relative intensity threshold (0 to 100). Default
is |
ions_max |
Maximal number of ions in a query combination. Default is
|
n_skel_min |
Minimal number of spectra per skeleton class. Default is
|
n_spec_min |
Minimal number of spectra where a signal has to be found.
Default is |
ppm |
Tolerance in parts per million. Default is |
mcc_min |
Minimal single-ion Matthews Correlation Coefficient. Default
is |
precision_min |
Minimal single-ion precision (pre-filter before MCC).
Default is |
recall_min |
Minimal single-ion recall (pre-filter before MCC). Default
is |
zero_val |
Zero value threshold for intensity. Default is |
For each skeleton class with at least n_skel_min spectra, the pipeline:
Normalizes MS2 intensities, removes sub-threshold and non-positive
neutral-loss peaks, and aligns m/z values across spectra using
intensity-weighted consensus centroids within dalton + mz * ppm / 1e6.
Evaluates candidate fragment and neutral-loss centroids against the raw
unbinned spectra (requiring precursor_mz - nl > 0).
Selects up to ions_max candidate ions per skeleton using greedy
hitting-set pruning on 100%-recall ions followed by forward conjunctive
MCC selection with negative-class correlation penalty (mRMR).
Prunes the power set of ion combinations via Branch-and-Bound when the optimistic zero-FP upper bound cannot reach the current best MCC.
Returns the single most parsimonious query achieving the maximum MCC per
skeleton and translates it to MassQL via to_massql().
Invisibly returns a data.frame with columns skeleton, mcc,
combined_ions, and massql, and writes the TSV table to export when
export is non-NULL.
df <- data.frame( msLevel = c(2L, 2L, 2L, 2L), SKELETON = c("SkelA", "SkelA", "SkelB", "SkelB"), precursorMz = c(300.0, 300.0, 300.0, 300.0) ) df$mz <- list( c(100.0, 150.0), c(100.0, 160.0), c(200.0, 250.0), c(200.0, 260.0) ) df$intensity <- list(c(80, 100), c(70, 100), c(90, 100), c(85, 100)) spectra_to_queries( spectra = df, export = NULL, n_skel_min = 2L, n_spec_min = 2L )df <- data.frame( msLevel = c(2L, 2L, 2L, 2L), SKELETON = c("SkelA", "SkelA", "SkelB", "SkelB"), precursorMz = c(300.0, 300.0, 300.0, 300.0) ) df$mz <- list( c(100.0, 150.0), c(100.0, 160.0), c(200.0, 250.0), c(200.0, 260.0) ) df$intensity <- list(c(80, 100), c(70, 100), c(90, 100), c(85, 100)) spectra_to_queries( spectra = df, export = NULL, n_skel_min = 2L, n_spec_min = 2L )
Translates one or more ion query expressions (such as
"108.0804_frag & 241.095_nl", "100_frag & (200_frag | 300_frag)", or a
list of ion vectors/expressions) into MassQL queries
(QUERY scaninfo(MS2DATA) WHERE ...).
to_massql(query, dalton = 0.01, ppm = 30, intensity_min = 0)to_massql(query, dalton = 0.01, ppm = 30, intensity_min = 0)
query |
Character vector of query expressions, or a |
dalton |
Tolerance in Dalton ( |
ppm |
Tolerance in parts per million ( |
intensity_min |
Minimal relative intensity threshold in percent
( |
MassQL ignores TOLERANCEMZ when TOLERANCEPPM is present on the
same condition. When dalton > 0, to_massql() emits a single effective
TOLERANCEMZ modifier (round(dalton + max(mz) * ppm / 1e6, 6) for
MS2PROD, and static dalton for MS2NL). When dalton == 0 and
ppm > 0, it emits TOLERANCEPPM. Disjunctive normal form clauses that
cannot share a single OR group are joined with " ; ".
Character vector of MassQL query strings.
to_massql("108.0804_frag & 241.095_nl", dalton = 0.01, ppm = 30)to_massql("108.0804_frag & 241.095_nl", dalton = 0.01, ppm = 30)