This function removes noisy fragments from a given spectrum based on m/z values and intensities. Fragments with m/z values that are too close to each other, determined by a ppm threshold, are considered noisy. Among these close fragments, the fragment with the lowest intensity is removed.

remove_noise(spec, ppm.ms2match = 30, mz.ppm.thr = 400)

Arguments

spec

A data frame representing the spectrum with columns for m/z and intensity.

ppm.ms2match

A numeric value specifying the ppm threshold for identifying close fragments. Default is 30.

mz.ppm.thr

A numeric value for the m/z threshold below which the m/z value will be set to this threshold. Default is 400.

Value

A data frame representing the cleaned spectrum after removing the noisy fragments.

Details

The function first sorts the spectrum based on m/z values and calculates the differences between consecutive m/z values. Fragments whose m/z differences are below the specified ppm threshold are identified. Among these fragments, the one with the lowest intensity is removed from the spectrum.

Examples

exp.spectrum <- data.frame(mz = 1:10, intensity = 1:10)
remove_noise(exp.spectrum)
#>    mz intensity
#> 1   1         1
#> 2   2         2
#> 3   3         3
#> 4   4         4
#> 5   5         5
#> 6   6         6
#> 7   7         7
#> 8   8         8
#> 9   9         9
#> 10 10        10