This function matches MS2 fragments between an experimental spectrum and a library spectrum based on m/z values, using a specified mass tolerance (ppm). It returns a matrix of matched fragments, including their m/z values and intensities.

match_ms2_fragments(
  experimental.spectrum,
  library.spectrum,
  ms2.match.ppm = 30,
  mz.ppm.thr = 400,
  direction = c("reverse", "forward"),
  remove.noise = TRUE
)

Arguments

experimental.spectrum

A data frame representing the experimental spectrum, with columns `mz` for mass-to-charge ratios and `intensity` for corresponding intensities.

library.spectrum

A data frame representing the library spectrum, with columns `mz` for mass-to-charge ratios and `intensity` for corresponding intensities.

ms2.match.ppm

Numeric. The mass tolerance in parts per million (ppm) for matching MS2 fragments. Default is 30.

mz.ppm.thr

Numeric. A threshold for mass-to-charge ratio (m/z) to use in ppm calculation. Default is 400.

Value

A data frame with matched MS2 fragments, containing the following columns:

Lib.index

The index of the fragment in the library spectrum.

Exp.index

The index of the matched fragment in the experimental spectrum.

Lib.mz

The m/z value of the fragment in the library spectrum.

Lib.intensity

The intensity of the fragment in the library spectrum.

Exp.mz

The m/z value of the matched fragment in the experimental spectrum.

Exp.intensity

The intensity of the matched fragment in the experimental spectrum.

Details

The function first removes noisy fragments from both the experimental and library spectra based on the provided mass tolerance (ppm). It then performs matching by comparing the m/z values of the fragments. If multiple experimental fragments match a library fragment, the one with the highest intensity is selected. Any unmatched fragments are added with NA values for the respective library or experimental fragment.

Author

Xiaotao Shen xiaotao.shen@outlook.com