Class containing MS Peak Lists
Source:R/generics.R, R/mspeaklists.R, R/mspeaklists-set.R, and 1 more
MSPeakLists-class.RdContains all MS (and MS/MS where available) peak lists for a featureGroups object.
Usage
peakLists(obj, ...)
averagedPeakLists(obj, ...)
spectrumSimilarity(obj, ...)
spectrumSimilarityIMS(obj, ...)
# S4 method for class 'MSPeakLists'
peakLists(obj)
# S4 method for class 'MSPeakLists'
averagedPeakLists(obj)
# S4 method for class 'MSPeakLists'
analyses(obj)
# S4 method for class 'MSPeakLists'
groupNames(obj)
# S4 method for class 'MSPeakLists'
length(x)
# S4 method for class 'MSPeakLists'
show(object)
# S4 method for class 'MSPeakLists,ANY,ANY,missing'
x[i, j, ..., reAverage = FALSE, drop = TRUE]
# S4 method for class 'MSPeakLists,ANY,ANY'
x[[i, j]]
# S4 method for class 'MSPeakLists'
x$name
# S4 method for class 'MSPeakLists'
as.data.table(x, fGroups = NULL, averaged = TRUE)
# S4 method for class 'MSPeakLists'
delete(obj, i = NULL, j = NULL, k = NULL, reAverage = FALSE, ...)
# S4 method for class 'MSPeakLists'
filter(
obj,
MSLevel = 1:2,
absMinIntensity = NULL,
relMinIntensity = NULL,
topMostPeaks = NULL,
minPeaks = NULL,
maxMZOverPrec = NULL,
absMinAbundanceFeat = NULL,
relMinAbundanceFeat = NULL,
absMinAbundanceFGroup = NULL,
relMinAbundanceFGroup = NULL,
maxRelCumIntensity = NULL,
isolatePrec = NULL,
deIsotope = FALSE,
removeMZs = NULL,
withMSMS = FALSE,
annotatedBy = NULL,
retainPrecursor = TRUE,
mzWindow = defaultLim("mz", "medium"),
reAverage = FALSE,
negate = FALSE
)
# S4 method for class 'MSPeakLists'
plotSpectrum(
obj,
groupName,
analysis = NULL,
MSLevel = 1,
title = NULL,
normalized = "multiple",
specSimParams = getDefSpecSimParams(),
xlim = NULL,
ylim = NULL,
showLegend = TRUE,
...
)
# S4 method for class 'MSPeakLists'
spectrumSimilarity(
obj,
groupName1,
groupName2 = NULL,
analysis1 = NULL,
analysis2 = NULL,
MSLevel = 1,
specSimParams = getDefSpecSimParams(),
NAToZero = FALSE,
drop = TRUE
)
# S4 method for class 'MSPeakLists'
spectrumSimilarityIMS(obj, fGroups, doFGroups = TRUE, warn = TRUE, ...)
# S4 method for class 'MSPeakListsSet'
analysisInfo(obj, df = FALSE)
# S4 method for class 'MSPeakListsSet'
show(object)
# S4 method for class 'MSPeakListsSet,ANY,ANY,missing'
x[i, j, ..., reAverage = FALSE, sets = NULL, drop = TRUE]
# S4 method for class 'MSPeakListsSet'
as.data.table(x, fGroups = NULL, averaged = TRUE)
# S4 method for class 'MSPeakListsSet'
delete(obj, i = NULL, j = NULL, k = NULL, reAverage = FALSE, ...)
# S4 method for class 'MSPeakListsSet'
filter(
obj,
...,
removeMZs = NULL,
withMSMS = FALSE,
annotatedBy = NULL,
retainPrecursor = TRUE,
mzWindow = defaultLim("mz", "medium"),
reAverage = FALSE,
negate = FALSE,
sets = NULL
)
# S4 method for class 'MSPeakListsSet'
plotSpectrum(
obj,
groupName,
analysis = NULL,
MSLevel = 1,
title = NULL,
normalized = "multiple",
specSimParams = getDefSpecSimParams(),
xlim = NULL,
ylim = NULL,
perSet = TRUE,
mirror = TRUE,
...
)
# S4 method for class 'MSPeakListsSet'
spectrumSimilarity(
obj,
groupName1,
groupName2 = NULL,
analysis1 = NULL,
analysis2 = NULL,
MSLevel = 1,
specSimParams = getDefSpecSimParams(),
NAToZero = FALSE,
drop = TRUE
)
# S4 method for class 'MSPeakListsSet'
unset(obj, set)
getDefIsolatePrecParams(...)Arguments
- obj, x, object
The
MSPeakListsobject to access.- ...
For the
"["operator: ignored.For
delete: passed to the function specified asj.For
plotSpectrum: passed toplot.For
spectrumSimilarityIMS: passed tospectrumSimilarityFor sets workflow methods: further arguments passed to the base
MSPeakListsmethod.- i, j
For
[/[[: A numeric or character value which is used to select analyses/feature groups by their index or name, respectively (for the order/names seeanalyses()/groupNames()).
For[: Can also be logical to perform logical selection (similar to regular vectors). If missing all analyses/feature groups are selected.
For[[: should be a scalar value. Ifjis not specified,iselects by feature groups instead.
Fordelete: The data to remove from.iare the feature groups as numeric index, logical or character,jthe MS peaks as numeric indices (rows). If either isNULLthen data for all is removed.jmay also be a function: it will be called for each feature group, with the peak list table (adata.table), feature group name, analysis (NULLif averaged function specifies the peak list indices (rows) to be removed (specified as anintegerorlogical- reAverage
Set to
TRUEto regenerate group averaged MS peak lists. NOTE it is very important that any annotation data relying on MS peak lists (formulae/compounds) are regenerated afterwards! Otherwise it is likely that e.g. plotting methods will use wrong MS/MS data.- drop
If set to
TRUEand if the comparison is made between two spectra thendropis used to reduce thematrixreturn value to anumericvector.- name
The feature group name (partially matched).
- fGroups
The
featureGroupsobject that was used to generate this object. If notNULLit is used to add feature group information (retention and m/z values).- averaged
If
TRUEthen feature group averaged peak list data is used.- k
A vector with analyses (
characterwith names orintegerwith indices) for which the data should be deleted. Ifk!=NULLthen deletions will not occur on group averaged peak lists. Otherwise, ifk=NULLthen deletion occurs on both group averaged and analysis specific peak lists.- MSLevel
The MS level for which data is plotted or filtered: 1 for regular MS, 2 for MSMS.
For
filter: can also be1:2to specify both.- absMinIntensity, relMinIntensity
Absolute/relative intensity threshold for peaks. Set to
NULLfor none.- topMostPeaks
Only consider this number of most intense peaks. Set to
NULLto consider all.- minPeaks
If the number of peaks in an MS/MS peak list (excluding the precursor peak) is lower than this it will be completely removed. Set to
NULLto ignore.- maxMZOverPrec
Any mass peaks with an m/z higher than this value (relative to the precursor) will be removed. Set to
NULLto ignore.- absMinAbundanceFeat, relMinAbundanceFeat
The minimum absolute/relative abundance for a mass peak across spectra that are averaged for a feature. Setting
reAveragedetermines if feature group peak lists are also filtered:reAverage=FALSEthen this filter is also applied to feature group data, using the the mean averaged peak abundance from the peak lists in the group.reAverage=TRUEthen this filter is not applied to the (regenerated) feature group data.
In most cases
reAverage=TRUEmakes more sense to avoid inconsistent filtering approaches between feature and feature group data.Set to
NULLto ignore.- absMinAbundanceFGroup, relMinAbundanceFGroup
The minimum absolute/relative abundance of a mass peak across spectra that are averaged for a feature group. Set to
NULLto ignore.- maxRelCumIntensity
The maximum relative cumulative intensity of a peak, calculated in descending order (most intense peaks first). For instance, a value of 0.95 means that only the most intense peaks that together account for <=95% of the total intensity are retained. Set to
NULLto ignore.- isolatePrec
If not
NULLthen value should be alistwith parameters used for isolating the precursor and its isotopes in MS peak lists (seeIsolating precursor data). Alternatively,TRUEto apply the filter with default settings (as given withgetDefIsolatePrecParams).- deIsotope
Remove any isotopic peaks in peak lists. This may improve data processing steps which do not assume the presence of isotopic peaks (e.g. MetFrag for MS/MS). Note that
generateMSPeakListsdoes not (yet) support flagging of isotopes.- removeMZs
A set of m/z values to be removed from the peak lists. This is typically used to remove background peaks. The m/z values should be specified by either be a
numericvector or adata.framewith anmzcolumn. The latter is returned by thegetBGMSMSPeaksfunction, which attempts to automatically detect background peaks.(sets workflow) Should be a
listthat specifies the m/z values to be removed (in above mentioned format) for each set. The order should match that of the sets in theMSPeakListsobject.- withMSMS
If set to
TRUEthen only results will be retained for which MS/MS data is available. ifnegate=TRUEthen only results without MS/MS data will be retained.- annotatedBy
Either a
formulasorcompoundsobject, or alistwith both. Any MS/MS peaks that are not annotated by any of the candidates in the specified objects are removed.NOTE: the
annotatedByfilter currently only supports filtering peak of feature groups (and not of features). Hence, this filter cannot be combined withreAverage=TRUE. Furthermore, if peak lists are re-averaged after application of this filter, any filtered results will be undone.- retainPrecursor
If
TRUEthen precursor peaks will never be filtered out from MS/MS peak lists (note that precursors are never removed from MS peak lists). Thenegateargument does not affect this setting.- mzWindow
The m/z window used to find peaks to be removed from the
removeMZsfilter.- negate
If
TRUEthen filters are applied in opposite manner.- groupName
The name of the feature group for which a plot should be made. To compare spectra, two group names can be specified.
- analysis
The name of the analysis for which a plot should be made. If
NULLthen data from the feature group averaged peak list is used. When comparing spectra, eitherNULLor the analyses for both spectra should be specified.- title
The title of the plot. If
NULLa title will be automatically made.- normalized
Controls intensity normalization. Should be
FALSE(don't normalize),TRUE(normalize) or"multiple"(only normalizes if multiple spectra are plotted).- specSimParams
A named
listwith parameters that influence the calculation of MS spectra similarities. See the spectral similarity parameters documentation for more details.- xlim, ylim
Sets the plot size limits used by
plot. Set toNULLfor automatic plot sizing.- showLegend
Set to
TRUEto show a legend.- groupName1, groupName2
The names of the feature groups for which the comparison should be made. If both arguments are specified then a comparison is made with the spectra specified by
groupName1vs those specified bygroupName2. The length of either can be >1 to generate a comparison matrix. Alternatively, ifgroupName2isNULLthen all the spectra specified ingroupName1will be compared with eachother, i.e. resulting in a square similarity matrix.- analysis1, analysis2
The name of the analysis (analyses) for the comparison. If
NULLthen data from the feature group averaged peak list is used. Otherwise, should be the same length asgroupName1/groupName2.- NAToZero
Set to
TRUEto convertNAsimilarities (i.e. when no similarity could be calculated) to zero values.- doFGroups
Set to
TRUEto compare spectra of feature groups,FALSEto compare spectra of features.- warn
Set to
TRUEto show a warning when no relevant feature group data is found.- df
If
TRUEthen adata.frameis returned, otherwise adata.tableis returned.- sets
(sets workflow) A
characterwith name(s) of the sets to keep (or remove ifnegate=TRUE).- perSet, mirror
(sets workflow) If
perSet=TRUEthen the set specific mass peaks are annotated separately. Furthermore, ifmirror=TRUE(and there are two sets in the object) then a mirror plot is generated.- set
(sets workflow) The name of the set.
Value
peakLists returns a nested list containing MS (and MS/MS where
available) peak lists per feature group and per analysis. The format is:
[[analysis]][[featureGroupName]][[MSType]][[PeakLists]] where
MSType is either "MS" or "MSMS" and PeakLists a
data.table containing all m/z values (mz
column) and their intensities (intensity column). In addition, the
peak list tables may contain a cmp column which contains an unique
alphabetical identifier to which isotopic cluster (or "compound") a mass
belongs (only supported by MS peak lists generated by Bruker tools at the
moment).
averagedPeakLists returns a nested list of feature group
averaged peak lists in a similar format as peakLists.
delete returns the object for which the specified data was removed.
spectrumSimilarityIMS returns a data.table with spectral similarities for each IMS
precursor and feature pair.
Details
Objects for this class are returned by generateMSPeakLists.
The getDefIsolatePrecParams is used to create a parameter
list for isolating the precursor and its isotopes (see Isolating precursor data).
Methods (by generic)
peakLists(MSPeakLists): Accessor method to obtain the MS peak lists.averagedPeakLists(MSPeakLists): Accessor method to obtain the feature group averaged MS peak lists.analyses(MSPeakLists): returns acharactervector with the names of the analyses for which data is present in this object.groupNames(MSPeakLists): returns acharactervector with the names of the feature groups for which data is present in this object.length(MSPeakLists): Obtain total number of m/z values.show(MSPeakLists): Shows summary information for this object.x[i: Subset on analyses/feature groups.x[[i: Extract a list with MS and MS/MS (if available) peak lists. If the second argument (j) is not specified the averaged peak lists for the group specified by the first argument (i) will be returned.$: Extract group averaged MS peaklists for a feature group.as.data.table(MSPeakLists): Returns all MS peak list data in a table.delete(MSPeakLists): Completely deletes specified peaks from MS peak lists.filter(MSPeakLists): provides post filtering of generated MS peak lists, which may further enhance quality of subsequent workflow steps (e.g. formulae calculation and compounds identification) and/or speed up these processes. The filters are applied to peak lists for each feature and feature group. The feature group peak lists are not re-averaged by default (see thereAverageargument). not filtered afterwards.plotSpectrum(MSPeakLists): Plots a spectrum using MS or MS/MS peak lists for a given feature group. Two spectra can be compared when two feature groups are specified.spectrumSimilarity(MSPeakLists): Calculates the spectral similarity between two or more spectra.spectrumSimilarityIMS(MSPeakLists): Calculates the spectral similarity between spectra from IMS features (or feature groups) and their IMS precursors in post mobility workflows (seeassignMobilities).
Slots
peakListsContains a list of all MS (and MS/MS) peak lists. Use the
peakListsmethod for access.metadataMetadata for all spectra used to generate peak lists. Follows the format of the
peakListsslot.averagedPeakListsA
listwith averaged MS (and MS/MS) peak lists for each feature group.avgPeakListArgsA
listwith arguments used to generate feature group averaged MS(/MS) peak lists.origFGNamesA
characterwith the original input feature group names.analysisInfo(sets workflow) Analysis information. Use the
analysisInfomethod for access.
Isolating precursor data
Formula calculation typically relies on evaluating the measured isotopic pattern
from the precursor to score candidates. Some algorithms (currently only GenForm) penalize candidates if
mass peaks are present in MS1 spectra that do not contribute to the isotopic pattern. Since these spectra are
typically very 'noisy' due to background and co-eluting ions, an additional filtering step may be recommended prior
to formula calculation. During this precursor isolation step all mass peaks are removed that are (1) not the
precursor and (2) not likely to be an isotopologue of the precursor. To determine potential isotopic peaks the
following parameters are used:
maxIsotopesThe maximum number of isotopes to consider. For instance, a value of 5 means thatM+0(i.e. the monoisotopic peak) tillM+5is considered. All mass peaks outside this range are removed.mzDefectRangeA two-sizedvectorspecifying the minimum (can be negative) and maximum m/z defect deviation compared to the precursor m/z defect. When chlorinated, brominated or other compounds with strong m/z defect in their isotopologues are to be considered a higher range may be desired. On the other hand, for natural compounds this range may be tightened. Note that the search range is propegated with increasing distance from the precursor, e.g. the search range is doubled forM+2, tripled forM+3etc.intRangeA two-sizedvectorspecifying the minimum and maximum relative intensity range compared to the precursor. For instance,c(0.001, 2)removes all peaks that have an intensity below 0.1% or above 200% of that of the precursor.zThezvalue (i.e. absolute charge) to be considerd. For instance, a value of2would look forM+0.5,M+1etc. Note that themzDefectRangeis adjusted accordingly (e.g. halved ifz=2).maxGapThe maximum number of missing adjacent isotopic peaks ('gaps'). If the (rounded) m/z difference to the previous peak exceeds this value then this and all next peaks will be removed. Similar toz, the maximum gap is automatically adjusted forcharge.
These parameters should be in a list that is passed to the isolatePrec argument to filter. The
default values can be obtained with the getDefIsolatePrecParams function:
maxIsotopes=5; mzDefectRange=c(-0.01, 0.01); intRange=c(0.001, 2); z=1; maxGap=2
Source
spectrumSimilarity: The principles of spectral binning and cosine similarity calculations
were loosely was based on the code from SpectrumSimilarity() function of OrgMassSpecR.
Sets workflows
The MSPeakListsSet class is applicable for sets workflows. This class is derived from MSPeakLists and therefore largely follows the same user interface.
The following methods are specifically defined for sets workflows:
unsetConverts the object data for a specified set into a 'non-set' object (MSPeakListsUnset), which allows it to be used in 'regular' workflows. Only the MS peaks that are present in the specified set are kept.analysisInfoReturns the analysis info for this object.
The following methods are changed or with new functionality:
filterand the subset operator ([) Can be used to select data that is only present for selected sets (setsargument).The
filtermethod is applied for each set individually, and afterwards the results are combined again (seegenerateMSPeakLists). Note that this has important implications for e.g. intensity filters (absMinIntensity/relMinIntensity),topMostPeaksandminPeaks. Furthermore, when theannotatedByfilter is applied, each set specific MS peak list is filtered by the annotation results from only that set. Finally, theremoveMZsfilter should be set for each set separately.plotSpectrumIs able to highlight set specific mass peaks (perSetandmirrorarguments).spectrumSimilarityFirst calculates similarities for each spectral pair per set (e.g. all positive mode spectra are compared and then all negative mode spectra are compared). This data is then combined into an overall similarity value. How this combination is performed depends on thesetCombineMethodfield of thespecSimParamsargument.