private void RemoveIsotopicIons(PeakList <T> t, T ion)
        {
            var is1     = ion.Mz + Atom.C13_GAP / ion.Charge;
            var is1Ions = FindPeakConsideringCharge(t, is1, ion.Charge, ion.Intensity);

            if (is1Ions.Count > 0)
            {
                is1Ions.ForEach(m => t.Remove(m));

                var is2     = ion.Mz + Atom.C13_GAP * 2 / ion.Charge;
                var is2Ions = FindPeakConsideringCharge(t, is2, ion.Charge, ion.Intensity);

                is2Ions.ForEach(m => t.Remove(m));
            }
        }
Esempio n. 2
0
        public static List <PeakList <T> > GetEnvelopes <T>(PeakList <T> pkl, double ppmTolerance) where T : IPeak
        {
            var tmp = new PeakList <T>(pkl);

            var result = new List <PeakList <T> >();

            while (tmp.Count > 0)
            {
                double       mzTolerance = 2 * PrecursorUtils.ppm2mz(tmp[0].Mz, ppmTolerance);
                PeakList <T> envelope    = tmp.FindEnvelope(tmp[0], mzTolerance, true);
                result.Add(envelope);

                foreach (T peak in envelope)
                {
                    //Remove all peaks around current peak
                    PeakList <T> findPeaks = tmp.FindPeak(peak.Mz, peak.Charge, mzTolerance);
                    foreach (T findPeak in findPeaks)
                    {
                        tmp.Remove(findPeak);
                    }
                }
            }

            /*
             *    Console.Out.WriteLine("---before merge");
             *    foreach (PeakList<T> pkl in result)
             *    {
             *      Console.Out.WriteLine("---");
             *      foreach (Peak p in pkl)
             *      {
             *        Console.Out.WriteLine(p);
             *      }
             *    }
             *
             *    result.Sort(new PeakListMzAscendingComparer<T>());
             *
             *    int current = 0;
             *
             *    while (current < result.Count - 1)
             *    {
             *      PeakList<T> currentPkl = result[current];
             *      if (currentPkl[0].Charge > 0)
             *      {
             *        double expectMz = currentPkl[currentPkl.Count - 1].Mz + ChargeDeconvolution.C_GAP / currentPkl[0].Charge;
             *        double mzTolerance = 4 * Precursor.ppm2mz(currentPkl[0].Mz, ppmTolerance);
             *        int next = current + 1;
             *        while (next < result.Count)
             *        {
             *          double gap = result[next][0].Mz - expectMz;
             *          if (gap >= 2.0)
             *          {
             *            break;
             *          }
             *
             *          if (Math.Abs(gap) > mzTolerance)
             *          {
             *            next++;
             *            continue;
             *          }
             *
             *          if (result[next][0].Charge != currentPkl[0].Charge)
             *          {
             *            next++;
             *            continue;
             *          }
             *
             *          Console.Out.WriteLine("Current----");
             *          foreach (T p in currentPkl)
             *          {
             *            Console.Out.WriteLine(p);
             *          }
             *          Console.Out.WriteLine("Add----");
             *          foreach (T p in result[next])
             *          {
             *            Console.Out.WriteLine(p);
             *          }
             *
             *          currentPkl.AddRange(result[next]);
             *
             *          Console.Out.WriteLine("To----");
             *          foreach (T p in currentPkl)
             *          {
             *            Console.Out.WriteLine(p);
             *          }
             *
             *          result.RemoveAt(next);
             *        }
             *      }
             *
             *      current++;
             *    }
             *
             *    Console.Out.WriteLine("---after merge");
             *    foreach (PeakList<T> pkl in result)
             *    {
             *      Console.Out.WriteLine("---");
             *      foreach (Peak p in pkl)
             *      {
             *        Console.Out.WriteLine(p);
             *      }
             *    }
             */
            return(result);
        }
        public PeakList <T> Process(PeakList <T> t)
        {
            if (t.PrecursorCharge > 0)
            {
                var isobaricList  = new List <T>();
                var mzPrecursor   = PrecursorUtils.ppm2mz(t.PrecursorMZ, options.PPMTolerance);
                var precursurIons = FindPeakConsideringCharge(t, t.PrecursorMZ, t.PrecursorCharge, mzPrecursor);

                //First of all, we need to find precursor
                if (precursurIons.Count > 0)
                {
                    precursurIons.ForEach(m => { t.Remove(m); });

                    isobaricList.Add(new T()
                    {
                        Mz        = t.PrecursorMZ,
                        Charge    = t.PrecursorCharge,
                        Intensity = mzPrecursor
                    });

                    if (options.RemoveChargeMinus1Precursor && t.PrecursorCharge > 1)
                    {
                        //Get charge-1 precursor
                        var p1mz     = PrecursorUtils.MHToMz(PrecursorUtils.MzToMH(t.PrecursorMZ, t.PrecursorCharge, true), t.PrecursorCharge - 1, true);
                        var p1Window = PrecursorUtils.ppm2mz(p1mz, options.PPMTolerance);
                        var p1Ions   = FindPeakConsideringCharge(t, p1mz, t.PrecursorCharge - 1, p1Window);
                        if (p1Ions.Count > 0)
                        {
                            p1Ions.ForEach(m => { t.Remove(m); });

                            isobaricList.Add(new T()
                            {
                                Mz        = p1mz,
                                Charge    = t.PrecursorCharge - 1,
                                Intensity = p1Window
                            });
                        }
                    }

                    if (options.RemoveIsotopicIons)
                    {
                        foreach (var ion in isobaricList)
                        {
                            RemoveIsotopicIons(t, ion);
                        }
                    }
                }

                foreach (var offset in offsets)
                {
                    var mz       = t.PrecursorMZ + offset / t.PrecursorCharge;
                    var mzWindow = PrecursorUtils.ppm2mz(mz, options.PPMTolerance);

                    var minMz = mz - mzWindow;
                    var maxMz = mz + mzWindow;

                    t.RemoveAll(m =>
                    {
                        if (m.Charge == t.PrecursorCharge || m.Charge == 0)
                        {
                            return(m.Mz >= minMz && m.Mz <= maxMz);
                        }
                        else
                        {
                            return(false);
                        }
                    });
                }

                if (options.RemoveIonLargerThanPrecursor)
                {
                    var pmass = PrecursorUtils.MzToMH(t.PrecursorMZ, t.PrecursorCharge, true);
                    t.RemoveAll(m =>
                    {
                        var mass = m.Charge > 0 ? PrecursorUtils.MzToMH(m.Mz, m.Charge, true) : m.Mz;
                        return(mass >= pmass);
                    });
                }
            }

            return(t);
        }