match_ms2_fragments: Match MS2 Fragments

View source: R/53_ms2_spectra_matching_scores.R

match_ms2_fragmentsR Documentation

Match MS2 Fragments

Description

Matches MS2 fragment ions between an experimental spectrum and a library spectrum.

Usage

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 with 'mz' and 'intensity' columns representing the experimental MS2 spectrum.

library.spectrum

A data frame with 'mz' and 'intensity' columns representing the reference MS2 spectrum.

ms2.match.ppm

Numeric, mass tolerance in parts per million (ppm) for fragment matching. Default is 30 ppm.

mz.ppm.thr

Numeric, minimum m/z threshold for ppm-based error calculation. Default is 400.

direction

Character, either '"reverse"' (library to experimental matching) or '"forward"' (experimental to library matching). Default is '"reverse"'.

remove.noise

Logical, whether to remove low-intensity fragment ions before matching. Default is 'TRUE'.

Details

This function aligns the fragment ions from an experimental MS2 spectrum with those from a library spectrum based on m/z similarity within a given ppm tolerance.

- If 'direction = "reverse"', the function looks for matches of each **library fragment ion** in the **experimental spectrum**. - If 'direction = "forward"', the function looks for matches of each **experimental fragment ion** in the **library spectrum**.

If multiple matches are found for a given fragment, the most intense one is selected.

Value

A data frame containing the matched fragment ions with the following columns:

Lib.index

Index of the fragment in the library spectrum.

Exp.index

Index of the fragment in the experimental spectrum.

Lib.mz

m/z value of the library fragment ion.

Lib.intensity

Intensity of the library fragment ion.

Exp.mz

m/z value of the experimental fragment ion.

Exp.intensity

Intensity of the experimental fragment ion.

Unmatched peaks in either spectrum are included with missing values ('NA') in the corresponding columns.

Author(s)

Xiaotao Shen xiaotao.shen@outlook.com

Examples

# Example data for experimental and library MS2 spectra
experimental.spectrum <- data.frame(mz = c(100.1, 150.2, 200.3), intensity = c(300, 500, 200))
library.spectrum <- data.frame(mz = c(100.09, 150.25, 210.4), intensity = c(250, 600, 150))

# Perform MS2 fragment matching
matched_fragments <- match_ms2_fragments(
  experimental.spectrum = experimental.spectrum,
  library.spectrum = library.spectrum,
  ms2.match.ppm = 30,
  direction = "reverse"
)

print(matched_fragments)


tidymass/metid documentation built on June 1, 2025, 10:04 p.m.