Morpheus.MassTolerance.CalculateMassError C# (CSharp) Method

CalculateMassError() public static method

public static CalculateMassError ( double experimental, double theoretical, MassToleranceUnits massErrorUnits ) : double
experimental double
theoretical double
massErrorUnits MassToleranceUnits
return double
        public static double CalculateMassError(double experimental, double theoretical, MassToleranceUnits massErrorUnits)
        {
            if(massErrorUnits == MassToleranceUnits.Da)
            {
                return experimental - theoretical;
            }
            else if(massErrorUnits == MassToleranceUnits.ppm)
            {
                return (experimental - theoretical) / theoretical * 1e6;
            }
            else
            {
                return double.NaN;
            }
        }

Usage Example

Example #1
0
        private static List<MSPeak> Deisotope(IEnumerable<MSPeak> peaks, int maxAbsoluteCharge, int polarity, MassTolerance isotopicMZTolerance)
        {
            List<MSPeak> new_peaks = new List<MSPeak>(peaks);

            int p = new_peaks.Count - 1;
            while(p >= 1)
            {
                int q = p - 1;
                bool removed = false;
                while(q >= 0)
                {
                    if(new_peaks[p].MZ > (new_peaks[q].MZ + Constants.C12_C13_MASS_DIFFERENCE) + isotopicMZTolerance)
                    {
                        break;
                    }

                    if(new_peaks[p].Intensity < new_peaks[q].Intensity)
                    {
                        if(polarity == 0)
                        {
                            if(Math.Abs(MassTolerance.CalculateMassError(new_peaks[p].MZ, new_peaks[q].MZ + Constants.C12_C13_MASS_DIFFERENCE, isotopicMZTolerance.Units)) <= isotopicMZTolerance.Value)
                            {
                                new_peaks.RemoveAt(p);
                                removed = true;
                                break;
                            }
                        }
                        else
                        {
                            for(int c = polarity; polarity > 0 ? c <= maxAbsoluteCharge : c >= -maxAbsoluteCharge; c += polarity)
                            {
                                if(Math.Abs(MassTolerance.CalculateMassError(new_peaks[p].MZ, new_peaks[q].MZ + Constants.C12_C13_MASS_DIFFERENCE / Math.Abs(c), isotopicMZTolerance.Units)) <= isotopicMZTolerance.Value)
                                {
                                    new_peaks.RemoveAt(p);
                                    removed = true;
                                    break;
                                }
                            }
                        }
                        if(removed)
                        {
                            break;
                        }
                    }

                    q--;
                }

                p--;
            }

            return new_peaks;
        }
All Usage Examples Of Morpheus.MassTolerance::CalculateMassError