コード例 #1
0
        private static GraphML_List <MsMsPeak> Deisotopebkp(GraphML_List <MsMsPeak> peaks, int maxCharge, MassTolerance isotopicMzTolerance)
        {
            GraphML_List <MsMsPeak> new_peaks = new GraphML_List <MsMsPeak>(peaks);

            peaks.Sort(MsMsPeak.AscendingMzComparison);

            for (int lowMassIndex = 0; lowMassIndex < new_peaks.Count - 1; lowMassIndex++)
            {
                if (new_peaks[lowMassIndex].Charge > 0)
                {
                    int    toRemove      = -1;
                    double bestMassError = isotopicMzTolerance.Value;
                    double aim           = Numerics.IsotopicMassShift(1, new_peaks[lowMassIndex].Charge) + new_peaks[lowMassIndex].MZ;

                    int potentialIsotopeIndex = lowMassIndex + 1;
                    while (potentialIsotopeIndex < new_peaks.Count && new_peaks[potentialIsotopeIndex].MZ < aim + bestMassError)
                    {
                        if (new_peaks[lowMassIndex].Intensity > new_peaks[potentialIsotopeIndex].Intensity)
                        {
                            double massError = Math.Abs(Numerics.CalculateMassError(new_peaks[potentialIsotopeIndex].MZ, aim, isotopicMzTolerance.Units));
                            if (massError < bestMassError)
                            {
                                bestMassError = massError;
                                toRemove      = potentialIsotopeIndex;
                            }
                        }
                        potentialIsotopeIndex++;
                    }
                    if (toRemove > 0)
                    {
                        new_peaks[lowMassIndex].Intensity += new_peaks[toRemove].Intensity;
                        new_peaks.RemoveAt(toRemove);
                    }
                }
            }
            return(new_peaks);
        }
コード例 #2
0
        private static GraphML_List <MsMsPeak> AssignChargeStatesAndDeisotope(GraphML_List <MsMsPeak> peaks, int maxCharge, MassTolerance isotopicMzTolerance)
        {
            GraphML_List <MsMsPeak> new_peaks = new GraphML_List <MsMsPeak>(peaks);

            //peaks.Sort(MSPeak.AscendingMzComparison);

            int[] bestIsotopes    = new int[4];
            int[] currentIsotopes = new int[4];
            for (int lowMassIndex = 0; lowMassIndex < new_peaks.Count - 1; lowMassIndex++)
            {
                double bestChargeScore = 0;
                int    bestCharge      = 0;
                bestIsotopes[0] = 0; bestIsotopes[1] = 0; bestIsotopes[2] = 0; bestIsotopes[3] = 0;
                for (int charge = maxCharge; charge > 0; charge--)
                {
                    currentIsotopes[0] = 0; currentIsotopes[1] = 0; currentIsotopes[2] = 0; currentIsotopes[3] = 0;
                    double score = 0;
                    int    potentialIsotopeIndex = lowMassIndex + 1;
                    for (int isotope = 1; isotope <= 4; isotope++)
                    {
                        double bestMassError = isotopicMzTolerance.Value;
                        double aim           = Numerics.IsotopicMassShift(isotope, charge) + new_peaks[lowMassIndex].MZ;

                        while (potentialIsotopeIndex < new_peaks.Count && new_peaks[potentialIsotopeIndex].MZ < aim + bestMassError)
                        {
                            if (new_peaks[lowMassIndex].Intensity > new_peaks[potentialIsotopeIndex].Intensity)
                            {
                                double massError = Math.Abs(Numerics.CalculateMassError(new_peaks[potentialIsotopeIndex].MZ, aim, isotopicMzTolerance.Units));
                                if (massError < bestMassError)
                                {
                                    bestMassError = massError;
                                    currentIsotopes[isotope - 1] = potentialIsotopeIndex;
                                }
                            }
                            potentialIsotopeIndex++;
                        }
                        score += isotopicMzTolerance.Value - bestMassError;
                        if (score == 0)
                        {
                            break;
                        }
                        ;
                    }
                    if (score > bestChargeScore)
                    {
                        bestIsotopes[0] = currentIsotopes[0];
                        bestIsotopes[1] = currentIsotopes[1];
                        bestIsotopes[2] = currentIsotopes[2];
                        bestIsotopes[3] = currentIsotopes[3];
                        bestChargeScore = score;
                        bestCharge      = charge;
                    }
                }

                new_peaks[lowMassIndex].Charge = bestCharge;
                for (int i = 3; i >= 0; i--)
                {
                    if (bestIsotopes[i] > 0)
                    {
                        new_peaks[lowMassIndex].Intensity += new_peaks[bestIsotopes[i]].Intensity;
                        new_peaks.RemoveAt(bestIsotopes[i]);
                    }
                }
            }
            return(new_peaks);
        }