private void SetIsotopeDistributionToZero(PeakData peakData, ThrashV1Peak peak, double zeroingStartMz, double zeroingStopMz, double monoMw, int chargeState, bool clearSpectrum, HornTransformResults record, bool debug = false) { var peakIndices = new List <int>(); peakIndices.Add(peak.PeakIndex); var mzDelta = record.DeltaMz; if (debug) { Console.Error.WriteLine("Clearing peak data for " + peak.Mz + " Delta = " + mzDelta); Console.Error.WriteLine("Zeroing range = " + zeroingStartMz + " to " + zeroingStopMz); } double maxMz = 0; if (IsO16O18Data) { maxMz = (monoMw + 3.5) / chargeState + ChargeCarrierMass; } var numUnprocessedPeaks = peakData.GetNumUnprocessedPeaks(); if (numUnprocessedPeaks == 0) { record.IsotopePeakIndices.Add(peak.PeakIndex); return; } if (clearSpectrum) { if (debug) { Console.Error.WriteLine("Deleting main peak :" + peak.Mz); } SetPeakToZero(peak.DataIndex, ref peakData.IntensityList, ref peakData.MzList, debug); } peakData.RemovePeaks(peak.Mz - peak.FWHM, peak.Mz + peak.FWHM, debug); if (1 / (peak.FWHM * chargeState) < 3) // gord: ?? { record.IsotopePeakIndices.Add(peak.PeakIndex); peakData.RemovePeaks(zeroingStartMz, zeroingStopMz, debug); return; } // Delete isotopes of mzs higher than mz of starting isotope for (var peakMz = peak.Mz + 1.003 / chargeState; (!IsO16O18Data || peakMz <= maxMz) && peakMz <= zeroingStopMz + 2 * peak.FWHM; peakMz += 1.003 / chargeState) { if (debug) { Console.Error.WriteLine("\tFinding next peak top from " + (peakMz - 2 * peak.FWHM) + " to " + (peakMz + 2 * peak.FWHM) + " pk = " + peakMz + " FWHM = " + peak.FWHM); } ThrashV1Peak nextPeak; peakData.GetPeakFromAll(peakMz - 2 * peak.FWHM, peakMz + 2 * peak.FWHM, out nextPeak); if (nextPeak.Mz.Equals(0)) { if (debug) { Console.Error.WriteLine("\t\tNo peak found."); } break; } if (debug) { Console.Error.WriteLine("\t\tFound peak to delete =" + nextPeak.Mz); } // Before assuming that the next peak is indeed an isotope, we must check for the height of this // isotope. If the height is greater than expected by a factor of 3, lets not delete it. peakIndices.Add(nextPeak.PeakIndex); SetPeakToZero(nextPeak.DataIndex, ref peakData.IntensityList, ref peakData.MzList, debug); peakData.RemovePeaks(nextPeak.Mz - peak.FWHM, nextPeak.Mz + peak.FWHM, debug); peakMz = nextPeak.Mz; } // Delete isotopes of mzs lower than mz of starting isotope // TODO: Use the delta m/z to make sure to remove 1- peaks from the unprocessed list, but not from the list of peaks? for (var peakMz = peak.Mz - 1.003 / chargeState; peakMz > zeroingStartMz - 2 * peak.FWHM; peakMz -= 1.003 / chargeState) { if (debug) { Console.Error.WriteLine("\tFinding previous peak top from " + (peakMz - 2 * peak.FWHM) + " to " + (peakMz + 2 * peak.FWHM) + " pk = " + peakMz + " FWHM = " + peak.FWHM); } ThrashV1Peak nextPeak; peakData.GetPeakFromAll(peakMz - 2 * peak.FWHM, peakMz + 2 * peak.FWHM, out nextPeak); if (nextPeak.Mz.Equals(0)) { if (debug) { Console.Error.WriteLine("\t\tNo peak found."); } break; } if (debug) { Console.Error.WriteLine("\t\tFound peak to delete =" + nextPeak.Mz); } peakIndices.Add(nextPeak.PeakIndex); SetPeakToZero(nextPeak.DataIndex, ref peakData.IntensityList, ref peakData.MzList, debug); peakData.RemovePeaks(nextPeak.Mz - peak.FWHM, nextPeak.Mz + peak.FWHM, debug); peakMz = nextPeak.Mz; } if (debug) { Console.Error.WriteLine("Done Clearing peak data for " + peak.Mz); } peakIndices.Sort(); // now insert into array. var numPeaksObserved = peakIndices.Count; var numIsotopesObserved = 0; var lastIsotopeNumObserved = int.MinValue; for (var i = 0; i < numPeaksObserved; i++) { var currentIndex = peakIndices[i]; var currentPeak = new ThrashV1Peak(peakData.PeakTops[currentIndex]); var isotopeNum = (int)(Math.Abs((currentPeak.Mz - peak.Mz) * chargeState / 1.003) + 0.5); if (currentPeak.Mz < peak.Mz) { isotopeNum = -1 * isotopeNum; } if (isotopeNum > lastIsotopeNumObserved) { lastIsotopeNumObserved = isotopeNum; numIsotopesObserved++; if (numIsotopesObserved > MaxIsotopes) { break; } record.IsotopePeakIndices.Add(peakIndices[i]); } else { record.IsotopePeakIndices[numIsotopesObserved - 1] = peakIndices[i]; } } if (debug) { Console.Error.WriteLine("Copied " + record.NumIsotopesObserved + " isotope peak indices into record "); } }