protected List <PeakList <Peak> > MergePeakList(List <PeakList <Peak> > pklList)
        {
            int index = 0;

            Progress.SetRange(0, pklList.Count);
            Progress.Begin();
            try
            {
                while (index < pklList.Count)
                {
                    if (Progress.IsCancellationPending())
                    {
                        throw new UserTerminatedException();
                    }
                    Progress.SetPosition(index);

                    PeakList <Peak> currentPkl = pklList[index];
                    double          maxGap     = PrecursorUtils.ppm2mz(currentPkl.PrecursorMZ, this.ppmPrecursorTolerance);

                    int next = index + 1;
                    while (next < pklList.Count)
                    {
                        PeakList <Peak> nextPkl          = pklList[next];
                        double          retentionTimeGap = nextPkl.ScanTimes[0].RetentionTime -
                                                           currentPkl.ScanTimes[0].RetentionTime;
                        if (retentionTimeGap > this.retentionTimeTolerance)
                        {
                            break;
                        }

                        if (nextPkl.PrecursorCharge != currentPkl.PrecursorCharge)
                        {
                            next++;
                            continue;
                        }

                        double precursorMzGap = Math.Abs(nextPkl.PrecursorMZ - currentPkl.PrecursorMZ);
                        if (precursorMzGap < maxGap)
                        {
                            currentPkl.MergeByMZFirst(nextPkl, this.ppmPeakTolerance);
                            pklList.RemoveAt(next);
                            continue;
                        }

                        next++;
                    }
                    index++;
                }
                Progress.SetPosition(pklList.Count);
            }
            finally
            {
                Progress.End();
            }

            return(pklList);
        }
Ejemplo n.º 2
0
    public void TestMergeWith()
    {
      PeakList<Peak> pl1 = new PeakList<Peak>();
      pl1.Add(new Peak(420, 10, 1));
      pl1.Add(new Peak(445, 10, 1));

      PeakList<Peak> pl2 = new PeakList<Peak>();
      pl2.Add(new Peak(420.004, 30, 2));
      pl2.Add(new Peak(445.004, 30, 1));

      pl1.MergeByMZFirst(pl2, 50);

      Assert.AreEqual(3, pl1.Count);
      Assert.AreEqual(420, pl1[0].Mz, 0.001);
      Assert.AreEqual(1, pl1[0].Charge);
      Assert.AreEqual(420.004, pl1[1].Mz, 0.001);
      Assert.AreEqual(2, pl1[1].Charge);
      Assert.AreEqual(445.003, pl1[2].Mz, 0.001);
      Assert.AreEqual(1, pl1[2].Charge);

      Assert.AreEqual(10, pl1[0].Intensity);
      Assert.AreEqual(30, pl1[1].Intensity);
      Assert.AreEqual(40, pl1[2].Intensity);
    }