frag4feature-purityA-method: Using a purityA object, link MS/MS data to XCMS features

frag4feature,purityA-methodR Documentation

Using a purityA object, link MS/MS data to XCMS features



Assign fragmentation spectra (MS/MS) stored within a purityA class object to grouped features within an XCMS xset object.

XCMS calculates individual chromatographic peaks for each mzML file (retrieved using xcms::chromPeaks(xcmsObj)), these are then grouped together (using xcms::groupChromPeaks). Ideally the mzML files that contain the MS/MS spectra also contain sufficient MS1 scans for XCMS to detect MS1 chromatographic features. If this is the case, to determine if a MS2 spectra is to be linked to an XCMS grouped feature, the associated acquisition time of the MS/MS event has to be within the retention time window defined for the individual peaks associated for each file. The precursor m/z value also has to be within the user ppm tolerance to XCMS feature.

See below for representation of the linking (the * —— * represent a many-to-many relationship) e.g. 1 or more MS/MS events can be linked to 1 or more individual feature and an individual XCMS feature can be linked to 1 or more grouped XCMS features

  • [grouped XCMS feature - across files] * —— * [individual XCMS feature - per file] * —— * [MS/MS spectra]

Alternatively, if the "useGroup" argument is set to TRUE, the full width of the grouped peak (determined as the minimum rtmin and maximum rtmax of the all associated individual peaks) will be used. This option should be used if the mzML file with MS/MS has very limited MS1 data and so individual chromatographic peaks might not be detected with the mzML files containing the MS/MS data. However, it should be noted this may lead to potential inaccurate linking.

  • [grouped XCMS peaks] * —— * [MS/MS spectra]

Example LC-MS/MS processing workflow

  • Purity assessments

    • (mzML files) -> purityA -> (pa)

  • XCMS processing

    • (mzML files) -> xcms.findChromPeaks -> (optionally) xcms.adjustRtime -> xcms.groupChromPeaks -> (xcmsObj)

    • Older versions of XCMS — (mzML files) -> xcms.xcmsSet -> -> xcms.retcor -> -> (xcmsObj)

  • Fragmentation processing

    • (xcmsObj, pa) -> frag4feature -> filterFragSpectra -> averageAllFragSpectra -> createDatabase -> spectralMatching -> (sqlite spectral database)

Additional notes

  • If using only a single file, then grouping still needs to be performed within XCMS before frag4feature can be used.

  • Fragmentation spectra below a certain precursor ion purity can be be removed (see plim argument).

  • A SQLite database can be created directly here but the functionality has been deprecated and the createDatabase function should now be used

  • Can experience some problems when using XCMS version < 3 and obiwarp retention time correction.


## S4 method for signature 'purityA'
  ppm = 5,
  plim = NA,
  intense = TRUE,
  convert2RawRT = TRUE,
  useGroup = FALSE,
  createDb = FALSE,
  outDir = ".",
  dbName = NA,
  grpPeaklist = NA,
  use_group = NA,
  out_dir = NA,
  create_db = NA,
  grp_peaklist = NA,
  db_name = NA,
  xset = NA



object; purityA object


object; XCMSnExp, xcmsSet or xsAnnotate object derived from the same files as those used to create the purityA object


numeric; ppm tolerance between precursor mz and XCMS feature mz


numeric; minimum purity of precursor to be included


boolean; If TRUE the most intense precursor will be used. If FALSE the precursor closest to the center of the isolation window will be used


boolean; If retention time correction has been used in XCMS set this to TRUE


boolean; Ignore individual peaks and just find matching fragmentation spectra within the (full) rtmin rtmax of each grouped feature


boolean; if yes, generate a database of MS2 spectra


string; path where (optionally generated) database file should be saved


character; name to assign to (optionally exported) database.


dataframe; Can use any peak dataframe to add to databse. Still needs to be derived from the "obj" object though


boolean; (Deprecated, to be removed - replaced with useGroup argument for style consistency)


character; (Deprecated, to be removed - use createDatabase function) Path where database will be created


boolean; (Deprecated, to be removed - use createDatabase function) SQLite database will be created of the results


dataframe; (Deprecated, to be removed - use createDatabase function) Can use any peak dataframe to add to databse. Still needs to be derived from the xset object though


character; (Deprecated, to be removed - use createDatabase function) If create_db is TRUE, a custom database name can be used, default is a time stamp


object; (Deprecated, to be removed - use xcmsObj) 'xcmsSet' object derived from the same files as those used to create the purityA object


Returns a purityA object (pa) with the following slots populated:

  • pa@grped_df: A dataframe of the grouped XCMS features linked to the associated fragmentation spectra precursor details is recorded here

  • pa@grped_ms2: A list of fragmentation spectra associated with each grouped XCMS feature is recorded here

  • pa@f4f_link_type: The linking method is recorded here (e.g. individual peaks or grouped - "useGroup=TRUE")


#====== XCMS =================================
## Read in MS data
msmsPths <- list.files(system.file("extdata", "lcms", "mzML",
           package="msPurityData"), full.names = TRUE, pattern = "MSMS")
ms_data = readMSData(msmsPths, mode = 'onDisk', msLevel. = 1)

## Find peaks in each file
cwp <- CentWaveParam(snthresh = 5, noise = 100, ppm = 10, peakwidth = c(3, 30))
xcmsObj  <- xcms::findChromPeaks(ms_data, param = cwp)

## Optionally adjust retention time
xcmsObj  <- adjustRtime(xcmsObj , param = ObiwarpParam(binSize = 0.6))

## Group features across samples
pdp <- PeakDensityParam(sampleGroups = c(1, 1), minFraction = 0, bw = 30)
xcmsObj <- groupChromPeaks(xcmsObj , param = pdp)

## Or if using the old XCMS functions
#xcmsObj <- xcms::xcmsSet(msmsPths)
#xcmsObj <- xcms::group(xcmsObj)
#xcmsObj <- xcms::retcor(xcmsObj)
#xcmsObj <- xcms::group(xcmsObj)

#====== msPurity ============================
pa <- purityA(msmsPths)
pa <- frag4feature(pa, xcmsObj)

Viant-Metabolomics/msPurity documentation built on April 17, 2022, 4:25 a.m.