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 "); } }
public void PerformTransform( float backgroundIntensity, float minPeptideIntensity, int maxProcessingTimeMinutes, ref float[] mzs, ref float[] intensities, ref ThrashV1Peak[] peaks, ref HornTransformResults[] transformResults, out bool processingAborted) { PercentDone = 0; processingAborted = false; var numPoints = mzs.Length; if (mzs.Length == 0) { return; } // mzs should be in sorted order double minMz = mzs[0]; double maxMz = mzs[numPoints - 1]; var mzList = new List <double>(mzs.Select(x => (double)x)); var intensityList = new List <double>(intensities.Select(x => (double)x)); var peakData = new PeakData(); peakData.SetPeaks(peaks); peakData.MzList = mzList; peakData.IntensityList = intensityList; if (IsMZRangeUsed) { minMz = MinMZ; maxMz = MaxMZ; } //loads 'currentPeak' with the most intense peak within minMZ and maxMZ ThrashV1Peak currentPeak; var found = peakData.GetNextPeak(minMz, maxMz, out currentPeak); //var fwhm_SN = currentPeak.FWHM; var transformRecords = new List <HornTransformResults>(); var numTotalPeaks = peakData.GetNumPeaks(); StatusMessage = "Performing Horn Transform on peaks"; var startTime = DateTime.UtcNow; while (found) { var numPeaksLeft = peakData.GetNumUnprocessedPeaks(); PercentDone = 100 * (numTotalPeaks - numPeaksLeft) / numTotalPeaks; if (PercentDone % 5 == 0) { StatusMessage = string.Concat("Done with ", Convert.ToString(numTotalPeaks - numPeaksLeft), " of ", Convert.ToString(numTotalPeaks), " peaks."); } if (currentPeak.Intensity < minPeptideIntensity) { break; } //--------------------- Transform performed ------------------------------ HornTransformResults transformRecord; var foundTransform = FindTransform(peakData, ref currentPeak, out transformRecord, backgroundIntensity); if (foundTransform && transformRecord.ChargeState <= MaxChargeAllowed) { if (IsActualMonoMZUsed) { //retrieve experimental monoisotopic peak var monoPeakIndex = transformRecord.IsotopePeakIndices[0]; ThrashV1Peak monoPeak; peakData.GetPeak(monoPeakIndex, out monoPeak); //set threshold at 20% less than the expected 'distance' to the next peak var errorThreshold = 1.003 / transformRecord.ChargeState; errorThreshold = errorThreshold - errorThreshold * 0.2; var calcMonoMz = transformRecord.MonoMw / transformRecord.ChargeState + 1.00727638; if (Math.Abs(calcMonoMz - monoPeak.Mz) < errorThreshold) { transformRecord.MonoMw = monoPeak.Mz * transformRecord.ChargeState - 1.00727638 * transformRecord.ChargeState; } } transformRecords.Add(transformRecord); } if (DateTime.UtcNow.Subtract(startTime).TotalMinutes > maxProcessingTimeMinutes) { processingAborted = true; found = false; } else { found = peakData.GetNextPeak(minMz, maxMz, out currentPeak); } } PercentDone = 100; // Done with the transform. Lets copy them all to the given memory structure. //Console.WriteLine("Done with Mass Transform. Found " + transformRecords.Count + " features"); transformResults = transformRecords.ToArray(); PercentDone = 100; }