| Title: | Contextualizing Untargeted Annotation with Semi-Quantitative Charged Aerosol Detection for Pertinent Characterization of Natural Extracts |
|---|---|
| Description: | Provides the infrastructure to perform Automated Composition Assessment of Natural Extracts by combining untargeted mass spectrometry feature tables and taxonomically informed metabolite annotations (TIMA) with semi-quantitative universal detectors such as Charged Aerosol Detection (CAD) and Photodiode Array (PDA) chromatograms. Includes Fourier filtering, derivative-based peak sharpening, peak integration, extracted ion chromatogram correlation, Wikidata/LOTUS chemotaxonomic literature queries, and interactive visualizations. |
| Authors: | Adriano Rutz [aut, cre] (ORCID: <https://orcid.org/0000-0003-0443-9902>) |
| Maintainer: | Adriano Rutz <[email protected]> |
| License: | AGPL (>= 3) |
| Version: | 0.0.0.9003 |
| Built: | 2026-11-20 22:56:07 UTC |
| Source: | https://github.com/adafede/cascade |
Example datasets included with CASCADE for demonstration and testing
purposes. All tabular datasets are stored as data.frame objects and
converted to data.table::data.table when loaded via the internal load_*
helpers.
cascade_annotations cascade_features cascade_features_informed cascade_features_not_informed cascade_chromatograms_positive cascade_chromatograms_negative cascade_ms_datacascade_annotations cascade_features cascade_features_informed cascade_features_not_informed cascade_chromatograms_positive cascade_chromatograms_negative cascade_ms_data
cascade_annotations: data.frame, 3,471 rows x 58 columns
(EDAM: data_0962 Small molecule report)
cascade_features: data.frame, 3,471 rows x 101 columns
(EDAM: data_2536 Mass spectrometry data)
cascade_features_informed: data.frame, 4,132 rows x 11 columns
(EDAM: data_2536 Mass spectrometry data)
cascade_features_not_informed: data.frame, 650 rows x 11 columns
(EDAM: data_2536 Mass spectrometry data)
cascade_chromatograms_positive: data.frame, 122,541 rows x 3 columns
(EDAM: data_2536 Mass spectrometry data)
cascade_chromatograms_negative: data.frame, 122,079 rows x 3 columns
(EDAM: data_2536 Mass spectrometry data)
cascade_ms_data: Named list (rt, mz, intensity) containing
5,668 MS1 scans (EDAM: data_0943 Mass spectrum)
An object of class data.frame with 3471 rows and 58 columns.
An object of class data.frame with 3471 rows and 101 columns.
An object of class data.frame with 4132 rows and 11 columns.
An object of class data.frame with 650 rows and 11 columns.
An object of class data.frame with 122541 rows and 3 columns.
An object of class data.frame with 122079 rows and 3 columns.
An object of class list of length 3.
Metabolite annotation table from a Swertia extract analyzed with TIMA. Contains 3,471 unique features with their chemical and taxonomic contextualizations.
Complete mzmine feature table. Contains 3,471 features with m/z, retention time, and intensity.
CAD-detected peaks that matched annotation hypotheses. Contains 4,132 peak-feature matches.
CAD-detected peaks that did not match any annotation hypothesis. Contains 650 peak-feature matches.
Chromatogram traces from positive-mode analysis. Tidy long-form data.frame with 3 columns.
Chromatogram traces from negative-mode analysis. Tidy long-form data.frame with 3 columns.
Example MS1 spectral dataset used for extracted ion chromatogram (XIC) reconstruction and peak shape comparison.
Visualizes and aligns BPI, CAD, and PDA chromatograms across positive and/or negative ionization runs after optional Fourier noise filtering, peak sharpening, and baseline correction.
check_chromatograms_alignment( file_negative = NULL, file_positive = NULL, time_min = 0.5, time_max = 32.5, cad_shift = 0.05, pda_shift = 0.1, fourier_components = 0.01, frequency = 1, resample = 1, chromatograms = c("bpi_pos", "cad_pos", "pda_pos"), headers = c(bpi = "BasePeak_0", pda = "PDA#1_TotalAbsorbance_0", cad = "UV#1_CAD_1_0"), type = "baselined", normalize_intensity = TRUE, normalize_time = FALSE, show_example = FALSE, intensity_floor = 0.001, k2 = 250, k4 = 1250000, sigma = 0.05, smoothing_width = 8, baseline_method = "peakDetection", improve_signal = TRUE )check_chromatograms_alignment( file_negative = NULL, file_positive = NULL, time_min = 0.5, time_max = 32.5, cad_shift = 0.05, pda_shift = 0.1, fourier_components = 0.01, frequency = 1, resample = 1, chromatograms = c("bpi_pos", "cad_pos", "pda_pos"), headers = c(bpi = "BasePeak_0", pda = "PDA#1_TotalAbsorbance_0", cad = "UV#1_CAD_1_0"), type = "baselined", normalize_intensity = TRUE, normalize_time = FALSE, show_example = FALSE, intensity_floor = 0.001, k2 = 250, k4 = 1250000, sigma = 0.05, smoothing_width = 8, baseline_method = "peakDetection", improve_signal = TRUE )
file_negative |
Path to negative-mode |
file_positive |
Path to positive-mode |
time_min |
Minimum retention time in minutes. Default is |
time_max |
Maximum retention time in minutes. Default is |
cad_shift |
CAD retention time shift in minutes, or |
pda_shift |
PDA retention time shift in minutes, or |
fourier_components |
Fraction of Fourier components to retain. Default
is |
frequency |
Acquisition frequency in Hz. Default is |
resample |
Resampling factor. Default is |
chromatograms |
Character vector of chromatograms to plot. Default is
|
headers |
Named character vector mapping detector types ( |
type |
Type of chromatogram to display: |
normalize_intensity |
Logical; normalize intensity to |
normalize_time |
Logical; normalize time to |
show_example |
Logical; use bundled example data. Default is |
intensity_floor |
Small positive value for intensity floor. Default is
|
k2 |
Second-derivative weight for signal sharpening. Default is |
k4 |
Fourth-derivative weight for signal sharpening. Default is
|
sigma |
Gaussian sigma for signal sharpening. Default is |
smoothing_width |
Moving-average window width for derivative smoothing.
Default is |
baseline_method |
Baseline correction method passed to
|
improve_signal |
Logical; apply Fourier filtering and sharpening.
Default is |
A plotly htmlwidget displaying the aligned chromatograms.
check_chromatograms_alignment(show_example = TRUE)check_chromatograms_alignment(show_example = TRUE)
Detects, fits (via Exponential-Gaussian Hybrid or Gaussian nonlinear least
squares), and trapezoidally integrates peaks in a detector chromatogram (CAD,
BPI, or PDA), links them to MS features, and returns an interactive plotly
visualization showing the signal, detected peak maxima, and start/end
integration bounds.
check_peaks_integration( file = NULL, features = NULL, detector = "cad", chromatogram = "baselined", headers = c(bpi = "BasePeak_0", pda = "PDA#1_TotalAbsorbance_0", cad = "UV#1_CAD_1_0"), min_area = 0.005, min_intensity = 10000, shift = 0.05, show_example = FALSE, fourier_components = 0.01, time_min = 0.5, time_max = 32.5, frequency = 1, resample = 1, intensity_floor = 0.001, k2 = 250, k4 = 1250000, sigma = 0.05, smoothing_width = 8, baseline_method = "peakDetection", sd_max = 50, max_iter = 1000, noise_threshold = 0.001, fit = "egh", intensity_threshold = 0.1, improve_signal = TRUE )check_peaks_integration( file = NULL, features = NULL, detector = "cad", chromatogram = "baselined", headers = c(bpi = "BasePeak_0", pda = "PDA#1_TotalAbsorbance_0", cad = "UV#1_CAD_1_0"), min_area = 0.005, min_intensity = 10000, shift = 0.05, show_example = FALSE, fourier_components = 0.01, time_min = 0.5, time_max = 32.5, frequency = 1, resample = 1, intensity_floor = 0.001, k2 = 250, k4 = 1250000, sigma = 0.05, smoothing_width = 8, baseline_method = "peakDetection", sd_max = 50, max_iter = 1000, noise_threshold = 0.001, fit = "egh", intensity_threshold = 0.1, improve_signal = TRUE )
file |
Path to |
features |
Path to feature table (optional when |
detector |
Detector type: |
chromatogram |
Chromatogram processing stage: |
headers |
Named character vector mapping detector types to |
min_area |
Minimum relative area fraction for peak filtering. Default is
|
min_intensity |
Minimum MS intensity for feature filtering. Default is
|
shift |
Retention time shift in minutes. Default is |
show_example |
Logical; use bundled example data. Default is |
fourier_components |
Fraction of Fourier components to retain. Default
is |
time_min |
Minimum retention time in minutes. Default is |
time_max |
Maximum retention time in minutes. Default is |
frequency |
Acquisition frequency in Hz. Default is |
resample |
Resampling factor. Default is |
intensity_floor |
Small positive value for intensity floor. Default is
|
k2 |
Second-derivative weight for signal sharpening. Default is |
k4 |
Fourth-derivative weight for signal sharpening. Default is
|
sigma |
Gaussian sigma for signal sharpening. Default is |
smoothing_width |
Moving-average window width for derivative smoothing.
Default is |
baseline_method |
Baseline correction method passed to
|
sd_max |
Maximum standard deviation for peak filtering. Default is |
max_iter |
Maximum iterations for peak fitting. Default is |
noise_threshold |
Noise threshold for peak detection. Default is
|
fit |
Peak fitting model: |
intensity_threshold |
Minimum normalized intensity threshold for peak
filtering. Default is |
improve_signal |
Logical; apply Fourier filtering and sharpening.
Default is |
A plotly htmlwidget showing the chromatogram and detected peak
boundaries.
check_peaks_integration(show_example = TRUE)check_peaks_integration(show_example = TRUE)
Queries Wikidata for natural products reported in the specified taxa
within a publication year range (start to end), enriches them with
NPClassifier chemical classifications from LOTUS, optionally deduplicates
stereoisomers and filters to chromatographiable mass/XLogP ranges, and
builds stacked histograms, interactive treemaps, and sunburst plots.
generate_ids( taxa = c("Swertia", "Kopsia", "Ginkgo"), comparison = NULL, no_stereo = TRUE, filter_ms_conditions = TRUE, start = "0", end = "9999", limit = "1000000", show_title = FALSE, format_tables = FALSE )generate_ids( taxa = c("Swertia", "Kopsia", "Ginkgo"), comparison = NULL, no_stereo = TRUE, filter_ms_conditions = TRUE, start = "0", end = "9999", limit = "1000000", show_title = FALSE, format_tables = FALSE )
taxa |
Character vector of scientific taxon names to query. Default is
|
comparison |
Optional character vector of two taxon names in |
no_stereo |
Logical; collapse stereoisomers to unique 2D structures per
taxon/reference. Default is |
filter_ms_conditions |
Logical; filter structures to chromatographiable
mass ( |
start |
Character(1); minimum publication year. Default is |
end |
Character(1); maximum publication year. Default is |
limit |
Character(1); maximum number of SPARQL rows per taxon. Default
is |
show_title |
Logical; include taxon name and unique structure count
titles on interactive treemaps and sunbursts. Default is |
format_tables |
Logical; format the returned |
A named list with four elements:
plots: Named list of ggplot chemical class histograms.
treemaps: Named list of interactive plotly treemap widgets.
sunbursts: Named list of interactive plotly sunburst widgets.
tables: Named list of compound-taxon-reference data.table objects
(or gt_tbl objects when format_tables = TRUE).
old_wd <- setwd(tempdir()) try(generate_ids(taxa = "Swertia")) setwd(old_wd)old_wd <- setwd(tempdir()) try(generate_ids(taxa = "Swertia")) setwd(old_wd)
Combines preprocessed detector chromatograms, peak-correlated MS features, and TIMA structural annotations to produce a suite of annotated pseudochromatograms (colored by chemical pathway/superclass and closest taxonomic occurrence) and interactive chemical hierarchy treemaps.
generate_pseudochromatograms( annotations = NULL, features_informed = NULL, features_not_informed = NULL, file = NULL, headers = c(bpi = "BasePeak_0", pda = "PDA#1_TotalAbsorbance_0", cad = "UV#1_CAD_1_0"), detector = "cad", show_example = FALSE, min_confidence = 0.4, min_similarity_prefilter = 0.6, min_similarity_filter = 0.8, mode = "pos", organism = "Swertia chirayita", fourier_components = 0.01, frequency = 1, resample = 1, shift = 0.05, time_min = 0.5, time_max = 32.5, intensity_floor = 0.001, k2 = 250, k4 = 1250000, sigma = 0.05, smoothing_width = 8, baseline_method = "peakDetection", improve_signal = TRUE, correct_acn = FALSE, acn_time = 30.5, dvol = 0.5 )generate_pseudochromatograms( annotations = NULL, features_informed = NULL, features_not_informed = NULL, file = NULL, headers = c(bpi = "BasePeak_0", pda = "PDA#1_TotalAbsorbance_0", cad = "UV#1_CAD_1_0"), detector = "cad", show_example = FALSE, min_confidence = 0.4, min_similarity_prefilter = 0.6, min_similarity_filter = 0.8, mode = "pos", organism = "Swertia chirayita", fourier_components = 0.01, frequency = 1, resample = 1, shift = 0.05, time_min = 0.5, time_max = 32.5, intensity_floor = 0.001, k2 = 250, k4 = 1250000, sigma = 0.05, smoothing_width = 8, baseline_method = "peakDetection", improve_signal = TRUE, correct_acn = FALSE, acn_time = 30.5, dvol = 0.5 )
annotations |
Path to TIMA annotations |
features_informed |
Path to peak-informed features |
features_not_informed |
Path to non-informed features |
file |
Path to |
headers |
Named character vector mapping detector types to |
detector |
Detector type: |
show_example |
Logical; use bundled example data. Default is |
min_confidence |
Minimum final annotation confidence score. Default is
|
min_similarity_prefilter |
Minimum correlation score for pre-filtering.
Default is |
min_similarity_filter |
Minimum correlation score for final filtering.
Default is |
mode |
Ionization mode: |
organism |
Investigated organism scientific name for taxonomic
prioritization. Default is |
fourier_components |
Fraction of Fourier components to retain. Default
is |
frequency |
Acquisition frequency in Hz. Default is |
resample |
Resampling factor. Default is |
shift |
Retention time shift in minutes. Default is |
time_min |
Minimum retention time in minutes. Default is |
time_max |
Maximum retention time in minutes. Default is |
intensity_floor |
Small positive value for intensity floor. Default is
|
k2 |
Second-derivative weight for signal sharpening. Default is |
k4 |
Fourth-derivative weight for signal sharpening. Default is
|
sigma |
Gaussian sigma for signal sharpening. Default is |
smoothing_width |
Moving-average window width for derivative smoothing.
Default is |
baseline_method |
Baseline correction method passed to
|
improve_signal |
Logical; apply Fourier filtering and sharpening.
Default is |
correct_acn |
Logical; apply acetonitrile gradient response correction
to CAD peak areas. Default is |
acn_time |
Numeric; gradient time in minutes to reach 100% acetonitrile
when |
dvol |
Numeric; dwell time offset in minutes when |
A named list with three elements:
plots_1: Named list of 8 ggplot pseudochromatograms.
plots_2: Named list of 2 interactive plotly signal-based sunbursts.
treemaps: Named list of interactive plotly treemap widgets.
generate_pseudochromatograms(show_example = TRUE)generate_pseudochromatograms(show_example = TRUE)
Integrates peak-informed features across positive and/or negative modes with TIMA structural annotations and LOTUS taxonomic/literature metadata, applies confidence-ordered 1D non-maximum suppression across retention-time windows, and produces both an interactive HTML table (with 2D chemical structure depictions via CDK Depict) and a tab-separated summary table.
generate_tables( annotations = NULL, file_negative = NULL, file_positive = NULL, min_confidence = 0.4, show_example = FALSE, export_csv = TRUE, export_html = TRUE, export_dir = "data/processed", export_name = "cascade_table" )generate_tables( annotations = NULL, file_negative = NULL, file_positive = NULL, min_confidence = 0.4, show_example = FALSE, export_csv = TRUE, export_html = TRUE, export_dir = "data/processed", export_name = "cascade_table" )
annotations |
Path to TIMA annotations |
file_negative |
Path to negative-mode informed features |
file_positive |
Path to positive-mode informed features |
min_confidence |
Minimum final annotation confidence score. Default is
|
show_example |
Logical; use bundled example data. Default is |
export_csv |
Logical; export |
export_html |
Logical; export |
export_dir |
Directory where output files are written. Default is
|
export_name |
Base filename (without extension) for exported tables.
Default is |
A named list with two elements:
pretty_table: A gt_tbl interactive table object.
csv_table: A data.table containing the formatted summary rows.
old_wd <- setwd(tempdir()) generate_tables(show_example = TRUE, export_csv = FALSE, export_html = FALSE) setwd(old_wd)old_wd <- setwd(tempdir()) generate_tables(show_example = TRUE, export_csv = FALSE, export_html = FALSE) setwd(old_wd)
Generates a stacked horizontal histogram, an interactive treemap, and an
interactive sunburst plot from one or more prepared TIMA annotation tables
returned by prepare_tima_annotations().
plot_tima(tables)plot_tima(tables)
tables |
A list of prepared annotation |
A named list with three elements:
histogram: A ggplot stacked bar chart.
treemap: A plotly interactive treemap widget.
sunburst: A plotly interactive sunburst widget.
tables <- prepare_tima_annotations(show_example = TRUE) plot_tima(tables)tables <- prepare_tima_annotations(show_example = TRUE) plot_tima(tables)
Filters and standardizes Taxonomically Informed Metabolite Annotation (TIMA)
output tables across initial spectral similarity, matched peak counts,
biological, chemical, and final confidence scores, retaining the top
candidate per feature for downstream visualization with plot_tima().
prepare_tima_annotations( annotations = NULL, predicted_classes = FALSE, min_score_initial = 0, min_score_biological = 0, min_score_chemical = 0, min_score_final = 0, min_matched_peaks_absolute = 0L, min_matched_peaks_percentage = 0, min_peaks = 3L, libraries = c("gnps", "massbank", "merlin", "ISDB", "ISDB - Wikidata", "TIMA MS1"), show_example = FALSE )prepare_tima_annotations( annotations = NULL, predicted_classes = FALSE, min_score_initial = 0, min_score_biological = 0, min_score_chemical = 0, min_score_final = 0, min_matched_peaks_absolute = 0L, min_matched_peaks_percentage = 0, min_peaks = 3L, libraries = c("gnps", "massbank", "merlin", "ISDB", "ISDB - Wikidata", "TIMA MS1"), show_example = FALSE )
annotations |
Named character vector of annotation file paths (optional
when |
predicted_classes |
Logical; use Sirius/CANOPUS predicted NPClassifier
classes instead of candidate structure classes. Default is |
min_score_initial |
Minimum initial spectral similarity score. Default
is |
min_score_biological |
Minimum biological (taxonomic) score. Default is
|
min_score_chemical |
Minimum chemical consistency score. Default is
|
min_score_final |
Minimum final combined score. Default is |
min_matched_peaks_absolute |
Minimum absolute number of matched MS2
peaks. Default is |
min_matched_peaks_percentage |
Minimum fraction of spectrum peaks
matched. Default is |
min_peaks |
Minimum total number of peaks in the query MS2 spectrum.
Default is |
libraries |
Character vector of spectral libraries to retain. Default
is |
show_example |
Logical; use bundled example data. Default is |
A named list of prepared data.table annotation tables.
prepare_tima_annotations(show_example = TRUE)prepare_tima_annotations(show_example = TRUE)
Extracts MS1 ion chromatograms (XICs) for all features falling within detected and trapezoidally integrated chromatographic peaks (e.g., CAD, PDA, or BPI), computes window-preserving interpolated Pearson correlation similarity scores between each feature's XIC profile and the corresponding detector peak profile, and exports both peak-informed and non-informed feature tables as TSV files.
process_compare_peaks( file = NULL, features = NULL, type = "baselined", detector = "cad", headers = c(bpi = "BasePeak_0", pda = "PDA#1_TotalAbsorbance_0", cad = "UV#1_CAD_1_0"), export_dir = "data/interim/peaks", show_example = FALSE, fourier_components = 0.01, frequency = 1, min_area = 0.005, min_intensity = 10000, resample = 1, shift = 0.05, time_min = 0.5, time_max = 32.5 )process_compare_peaks( file = NULL, features = NULL, type = "baselined", detector = "cad", headers = c(bpi = "BasePeak_0", pda = "PDA#1_TotalAbsorbance_0", cad = "UV#1_CAD_1_0"), export_dir = "data/interim/peaks", show_example = FALSE, fourier_components = 0.01, frequency = 1, min_area = 0.005, min_intensity = 10000, resample = 1, shift = 0.05, time_min = 0.5, time_max = 32.5 )
file |
Path to |
features |
Path to feature table (optional when |
type |
Chromatogram processing stage: |
detector |
Detector type: |
headers |
Named character vector mapping detector types to |
export_dir |
Directory where the output |
show_example |
Logical; use bundled example data. Default is |
fourier_components |
Fraction of Fourier components to retain. Default
is |
frequency |
Acquisition frequency in Hz. Default is |
min_area |
Minimum relative area fraction for peak filtering. Default is
|
min_intensity |
Minimum MS intensity for feature filtering. Default is
|
resample |
Resampling factor. Default is |
shift |
Retention time shift in minutes. Default is |
time_min |
Minimum retention time in minutes. Default is |
time_max |
Maximum retention time in minutes. Default is |
Invisibly returns a named list with two data.table elements:
features_informed and features_not_informed.
tmp <- tempdir() process_compare_peaks(show_example = TRUE, export_dir = tmp)tmp <- tempdir() process_compare_peaks(show_example = TRUE, export_dir = tmp)
Performs a SPARQL query against Wikidata (or another SPARQL 1.1 endpoint)
and returns a data.table. Requests gzip-compressed CSV (falling back to
TSV) streamed directly to disk via curl and parsed with
data.table::fread(). Automatically retries against the QLever Wikidata
endpoint (https://qlever.dev/api/wikidata) when fallback = TRUE.
query_wikidata( sparql_query, remove_url = TRUE, endpoint = "https://query.wikidata.org/sparql", agent = "https://github.com/adafede/cascade", timeout = 3600L, fallback = TRUE, headers = NULL, post = FALSE )query_wikidata( sparql_query, remove_url = TRUE, endpoint = "https://query.wikidata.org/sparql", agent = "https://github.com/adafede/cascade", timeout = 3600L, fallback = TRUE, headers = NULL, post = FALSE )
sparql_query |
Character(1). SPARQL query string. |
remove_url |
Logical(1). Strip |
endpoint |
Character(1). SPARQL endpoint URL. Default is
|
agent |
Character(1). HTTP |
timeout |
Numeric(1). Total request timeout in seconds (default
|
fallback |
Logical(1). Retry with QLever Wikidata endpoint on failure
(default |
headers |
Character(1) or |
post |
Logical(1). Send the SPARQL query as an HTTP POST request body
( |
A data.table containing the query results.
q <- paste0( "SELECT ?taxon WHERE { ", "?taxon <http://www.wikidata.org/prop/direct/P225> 'Gentiana lutea' . }" ) try(query_wikidata(q, timeout = 15L))q <- paste0( "SELECT ?taxon WHERE { ", "?taxon <http://www.wikidata.org/prop/direct/P225> 'Gentiana lutea' . }" ) try(query_wikidata(q, timeout = 15L))
Queries Wikidata for the item whose taxon name (wdt:P225) matches
taxon_name and returns the corresponding Wikidata entity identifier
(e.g., "Q158572").
taxon_name_to_qid(taxon_name)taxon_name_to_qid(taxon_name)
taxon_name |
Character(1). Scientific name of the taxon (e.g.,
|
Character vector of matching Wikidata QID(s).
try(taxon_name_to_qid(taxon_name = "Gentiana lutea"))try(taxon_name_to_qid(taxon_name = "Gentiana lutea"))