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)
A data frame representing the spectrum with columns for m/z and intensity.
A numeric value specifying the ppm threshold for identifying close fragments. Default is 30.
A numeric value for the m/z threshold below which the m/z value will be set to this threshold. Default is 400.
A data frame representing the cleaned spectrum after removing the noisy fragments.
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.
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