Converts a peak_list object containing peaks from multiple samples into
an aligned peak table by clustering peaks across samples according to
retention time and (optionally) spectral similarity. The tree is cut at
height hmax, whose meaning depends on clust (see hmax).
Usage
get_peaktable(peak_list, ...)
# Default S3 method
get_peaktable(
peak_list,
chrom_list,
response = c("area", "height"),
use_corrected_rt = NULL,
hmax = 0.2,
summarize_by = c("weighted.mean", "median", "mean", "max"),
plot_it = FALSE,
ask = plot_it,
clust = c("rt", "sp.rt"),
sigma_t = NULL,
sigma_r = 0.5,
deepSplit = FALSE,
verbose = FALSE,
...,
sigma.t = NULL,
sigma.r = NULL,
use.cor = NULL
)
# S3 method for class 'matched_peak_list'
get_peaktable(
peak_list,
pks,
response = c("area", "height"),
rt_tol = 0.01,
na.fill = 0,
verbose = FALSE,
...
)
# S3 method for class 'matched_peak_list_set'
get_peaktable(
peak_list,
pks,
response = c("area", "height"),
rt_tol = 0.01,
na.fill = 0,
verbose = FALSE,
...
)Arguments
- peak_list
A
peak_listobject created byget_peaks, or amatched_peak_listcreated bymatch_peaks.- ...
Additional arguments (currently unused).
- chrom_list
A list of chromatographic matrices. Only required when
clust = "sp.rt".- response
Peak intensity measure: either
"area"(default) or"height".- use_corrected_rt
Logical. Indicates whether to use corrected retention times (
rt.corcolumn) or raw retention times (rtcolumn). Unless otherwise specified, thert.corcolumn will be used by default if it exists in the providedpeak_list. Either way, they are stored in thert,startandendrows ofpk_meta, andargs$use_corrected_rtrecords which were used.- hmax
Height at which the clustering tree is cut. With
clust = "rt", peaks are clustered by complete linkage on retention time, sohmaxis the largest retention time difference allowed between any two peaks in the same cluster, in minutes. Withclust = "sp.rt", peaks are clustered by average linkage on the dissimilarity \(1 - S_{ij}\), which runs from 0 to 1, andhmaxis the maximum tree height passed tocutreeDynamicTree; clusters may be split below it (seedeepSplit). There, the default of0.2lets peaks with identical spectra sit about0.67 * sigma_tapart, a third of the meanend - startat the defaultsigma_t. Ignored for peak lists produced byget_peaks(windows = )orget_peaks(targets = ), since those peaks are grouped by integration window or target instead of being clustered (see Windows and targets).- summarize_by
How to summarize peak metadata within each cluster. Options are
"weighted.mean"(default, weights peaks by their intensity as given byresponse),"mean","median"(which aggregate metadata across all peaks in the cluster) or"max"(which selects the most intense peak in the cluster and uses its metadata directly).- plot_it
Logical. If
TRUE, for every component a strip plot will be shown indicating the clustering.- ask
Logical. Ask before showing new plot? Defaults to
plot_it.- clust
Specify whether to perform hierarchical clustering based on spectral similarity and retention time (
sp.rt) or retention time alone (rt). Defaults tort. Ignored for peak lists produced byget_peaks(windows = )orget_peaks(targets = ), which are grouped by window or target (see Windows and targets).- sigma_t
Width of Gaussian kernel for retention time similarity, in minutes. Controls the weight given to retention time when
clust = "sp.rt". Defaults to half the meanend - startacross all peaks.- sigma_r
Width of Gaussian kernel for spectral similarity. Controls the weight given to spectral correlation when
clust = "sp.rt". Defaults to0.5.- deepSplit
Logical. Controls sensitivity to cluster splitting when
clust = "sp.rt". IfTRUE, returns a larger number of smaller clusters. Defaults toFALSE. For additional information, seecutreeDynamicTree.- verbose
Logical. Whether to warn when two peaks from the same sample fall in the same cluster. Defaults to
FALSE.- sigma.t
The
sigma.targument is deprecated. Please usesigma_t, which is in minutes.sigma.tis read in the units of the retention times, as before.- sigma.r
The
sigma.rargument is deprecated. Please usesigma_rinstead.- use.cor
The
use.corargument is deprecated. Please useuse_corrected_rtinstead.- pks
A
peak_listobject fromget_peaks. Required whenpeak_listis amatched_peak_list. Used to retrieve per-peak intensities and metadata.- rt_tol
Numeric. Maximum allowed deviation (in retention-time units) when joining matched peak RTs back to the corresponding row in
pks. Defaults to0.01.- na.fill
Value used to fill cells where no peak was matched in a given sample. Defaults to
0. Only used by thematched_peak_listmethod.
Value
An S3 peak_table object, containing the following elements:
tab: The peak table itself — adata.frameof intensities in a sample × peak configuration. A peak that was not found in a sample, or whose response is negative, is recorded as0(na.fillfor amatched_peak_list). A peak whose model failed, whichget_peaks(targets = )keeps with a missingheightandarea, is recorded asNA.pk_meta: Adata.frameof peak metadata, one column per peak. Its rows are the wavelength (lambda), the peak number (peak), and whichever of the peak list'srt,start,end,sd,tau,FWHM,r.squared,purity,window_limitedandconvergedcolumns it has. See theValuesection ofget_peaksfor their meanings. The rows taken from the peak list are summarized across samples according tosummarize_by; by default, peaks are weighted by intensity, which reduces the influence of small peaks. With"weighted.mean"or"mean", theconvergedandwindow_limitedrows become the share of the column's peaks with that flag, so0.25means a quarter of them. In a table built from amatched_peak_list, the rows hold the reference sample's values instead.sample_meta: Adata.frameof sample metadata: the fields added to the chromatograms withchromConverter::add_metadata()(chromConverter 0.11.0 or later), and any attached withattach_metadata.NAif there are none.instrument_meta: Adata.frameof instrumental metadata transferred automatically from the chromatograms.ref_spectra: A matrix of reference spectra (in a wavelength × peak configuration).NAuntil added withattach_ref_spectra.args: A list of the arguments given toget_peaktableto generate the peak table, with thefit,baselineandmax_iterthe peaks were fitted with inget_peaks. Itsfilterselement holds anyfilter_peaksandfilter_peaktablecalls applied, as code, separated by"; ".
Note
This function is adapted from the getPeakTable function in the alsace
package by Ron Wehrens: https://github.com/rwehrens/alsace/blob/master/R/getPeakTable.R.
Clustering
By default, clustering is performed on retention times alone (when
clust = "rt"). Alternatively, clustering can also incorporate information
about spectral similarity (when clust = "sp.rt") using a similarity function
adapted from Broeckling et al., 2014:
$$
S_{ij} =
\exp\left(-\frac{(t_i - t_j)^2}{2\sigma_t^2}\right)
\cdot
\exp\left(-\frac{(1 - c_{ij})^2}{2\sigma_r^2}\right)
$$
where \(c_{ij}\) is the spectral correlation between spectra \(i\) and
\(j\), and \(\sigma_t\) and \(\sigma_r\) control the relative
contributions of retention time and spectral similarity, respectively (see
sigma_t and sigma_r).
When two peaks from the same sample fall in the same cluster, only the more
intense one enters the peak table, with a warning if verbose = TRUE. Such
warnings are often benign, but they can also mean hmax is too large. Lowering hmax merges fewer peaks, at the
cost of splitting some across multiple clusters; filtering low-intensity
peaks before clustering reduces the warnings without that trade-off.
Windows and targets
Peak lists produced by get_peaks(windows = ) are grouped by
integration window rather than clustered by retention time, including after
correct_peaks. This gives one peak table column per window, ordered by
retention time.
Peak lists produced by get_peaks(targets = ) are grouped by target
instead of being clustered, each peak going to the matching target.
Targets found in no sample are omitted from the peak table. If targets has
a name column, the columns are named after the targets.
Peak tables built from get_peaks(windows = ) or get_peaks(targets = )
keep those windows or targets as an attribute of the same name, as a
record of how the table was built. The targets attribute lists every
target that was searched for, including any found in no sample, which have
no column. Neither attribute is updated when columns are removed.
Matched peak lists
match_peaks pairs the peaks in each sample with the peaks of a reference
sample, by spectrum as well as retention time. Each column then follows one
compound across the samples, even where retention times drift too far for
clustering to group the peaks reliably. In crowded stretches of the
chromatogram, this works only if neighboring compounds have distinct
spectra. This suits targeted analysis (see targeted_analysis) and
studies in which one sample, such as a standard mix or a pooled sample,
contains every compound of interest.
The peak table has one column for each peak
in the reference sample, at each of the specified wavelengths. A peak that's
missing in the reference sample gets no column, even if it's present in other
samples, so choose the reference with care (see match_peaks).
References
Broeckling, C. D., Afsar F.A., Neumann S., Ben-Hur A., and Prenni J.E. 2014. RAMClust: A Novel Feature Clustering Method Enables Spectral-Matching-Based Annotation for Metabolomics Data. Anal. Chem. 86:6812-6817. doi:10.1021/ac501530d .
Wehrens, R., Carvalho, E., Fraser, P.D. 2015. Metabolite profiling in LC–DAD using multivariate curve resolution: the alsace package for R. Metabolomics 11:143-154. doi:10.1007/s11306-014-0683-5 .
Examples
data(Sa_pr)
pks <- get_peaks(Sa_pr, lambdas = c('210'))
get_peaktable(pks, response = "area")
#> V1 V2 V3 V4 V5 V6 V7
#> 119 0.000000 5.160717 0.6216202 16.6408509 0.4577718 0.4599784 81.1954044
#> 121 0.000000 4.012988 0.8692032 0.5517739 7.7387426 0.0000000 0.0000000
#> 122 0.000000 8.168948 1.3471271 2.0773758 25.8641682 2.2710192 59.7697574
#> 458 5.640076 5.769393 1.7765152 1.7162467 18.6509054 0.0000000 0.2636266
#> V8 V9 V10 V11 V12 V13 V14
#> 119 2.725664 42.309860 1.55284 1.537438 2.509823 37.504493 14.03672
#> 121 57.367316 0.000000 18.42121 0.000000 1.022751 8.082183 20.06353
#> 122 1.164881 0.000000 36.05080 1.536124 4.585314 32.383822 12.62787
#> 458 110.608512 3.767623 33.80274 4.325797 1.389959 5.667755 43.02514
#> V15 V16 V17 V18 V19 V20 V21 V22
#> 119 0.000000 34.13395 0.000000 4.567092 0.000000 5.128388 1.95140616 12.59202
#> 121 8.359219 0.00000 22.311973 0.000000 1.171736 1.812437 0.09512587 0.00000
#> 122 0.000000 28.69373 1.215313 2.452972 0.000000 3.390005 0.59202006 0.00000
#> 458 23.415509 0.00000 25.148310 0.000000 5.164612 5.576050 0.34027136 0.00000
#> V23 V24 V25 V26 V27 V28 V29
#> 119 14.918412 0.00000 2.3572466 0.092200823 17.6381605 0.00000 1.7600985
#> 121 6.833451 11.80269 0.7327165 0.007687478 0.3798519 13.93831 0.5340067
#> 122 8.923256 15.44319 2.7602610 0.080516725 0.0000000 16.53251 0.8198640
#> 458 12.455040 14.88247 2.2405245 0.004549712 0.0000000 23.49422 0.9877410
#> V30 V31 V32 V33 V34 V35 V36
#> 119 0.0000000 1.2108244 0.9140629 1.683199 0.8260853 1.447895 1.980108
#> 121 0.2088148 0.4814268 0.4277401 0.000000 2.0490665 0.000000 1.746997
#> 122 0.0000000 1.0992387 1.1170352 0.000000 0.0000000 0.000000 5.719170
#> 458 0.5647096 0.9305848 1.3541306 1.668973 2.9601134 0.000000 3.644116
