CalculateMassError() public static method

public static CalculateMassError ( double experimental, double theoretical, MassToleranceUnits massErrorUnits ) : double
experimental double
theoretical double
massErrorUnits MassToleranceUnits
return double
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;
        }
Example #2
0
        private static List<MSPeak> AssignChargeStates(IList<MSPeak> peaks, int maxAbsoluteCharge, int polarity, MassTolerance isotopicMZTolerance)
        {
            List<MSPeak> new_peaks = new List<MSPeak>();

            for(int i = 0; i < peaks.Count; i++)
            {
                int j = i + 1;
                List<int> charges = new List<int>();
                while(j < peaks.Count)
                {
                    if(peaks[j].MZ > (peaks[i].MZ + Constants.C12_C13_MASS_DIFFERENCE) + isotopicMZTolerance)
                    {
                        break;
                    }

                    for(int c = polarity * maxAbsoluteCharge; polarity > 0 ? c >= 1 : c <= -1; c -= polarity)
                    {
                        // remove harmonic charges, e.g. don't consider peak as a +2 (0.5 Th spacing) if it could be a +4 (0.25 Th spacing)
                        if(HARMONIC_CHARGE_DETECTION)
                        {
                            bool harmonic = false;
                            foreach(int c2 in charges)
                            {
                                if(c2 % c == 0)
                                {
                                    harmonic = true;
                                    break;
                                }
                            }
                            if(harmonic)
                            {
                                continue;
                            }
                        }

                        if(Math.Abs(MassTolerance.CalculateMassError(peaks[j].MZ, peaks[i].MZ + Constants.C12_C13_MASS_DIFFERENCE / c, isotopicMZTolerance.Units)) <= isotopicMZTolerance.Value)
                        {
                            new_peaks.Add(new MSPeak(peaks[i].MZ, peaks[i].Intensity, c, polarity));
                            charges.Add(c);
                        }
                    }

                    j++;
                }
                if(charges.Count == 0)
                {
                    new_peaks.Add(new MSPeak(peaks[i].MZ, peaks[i].Intensity, 0, polarity));
                }
            }

            return new_peaks;
        }