/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package umich.ms.util;

import umich.ms.datatypes.spectrum.ISpectrum;

/**
 * Utilities for working with {@link ISpectrum} objects.
 * @author Dmitry Avtonomov
 */
public class SpectrumUtils {
    private SpectrumUtils() {}

    /**
     * Given an m/z value, calculates what a certain ppm accuracy converts to in terms of m/z.
     * @param mz base m/z at which the calculation is done
     * @param ppm
     * @return
     */
    public static double ppm2amu(double mz, double ppm) {
        return (mz / 1e6) * ppm;
    }

    /**
     * Given an absolute m/z difference ({@code amu} parameter), find out how much ppm that is.
     * @param mz base m/z at which the calculation is done.
     * @param amu absolute m/z difference, which is to be converted to ppm.
     * @return
     */
    public static double amu2ppm(double mz, double amu) {
        return amu / (mz / 1e6);
    }
}

@@ -601,16 +601,70 @@
 aram ppm
+Delta ppm difference, which is to be converted to amu.
 %0D%0A     *
@@ -736,16 +736,21 @@
 uble ppm
+Delta
 ) %7B%0D%0A   
@@ -777,16 +777,21 @@
 6) * ppm
+Delta
 ;%0D%0A    %7D
@@ -978,16 +978,21 @@
 aram amu
+Delta
  absolut
@@ -1122,16 +1122,21 @@
 uble amu
+Delta
 ) %7B%0D%0A   
@@ -1150,16 +1150,21 @@
 turn amu
+Delta
  / (mz /
@@ -1177,12 +1177,494 @@
 %0D%0A    %7D%0D
+%0A%0D%0A    /**%0D%0A     * Check if the 2nd m/z value is within some PPM distance from the 1st one. PPM will be calculated based on the 1st%0D%0A     * m/z value.%0D%0A     * @param mz1 PPM tolerance will be calculated relative to this value%0D%0A     * @param mz2 the value to check for being within some PPM range%0D%0A     * @param ppm%0D%0A     * @return%0D%0A     */%0D%0A    public static boolean isWithinPpm(double mz1, double mz2, double ppm) %7B%0D%0A        return Math.abs(amu2ppm(mz1, mz1 - mz2)) %3C= ppm;%0D%0A    %7D%0D
 %0A%7D%0D%0A

Improve SpectrumUtils