/// <summary> /// will calculate the delta mz (referenced to the theor) based on several of the observed peaks /// </summary> /// <param name="startingDelta"></param> /// <param name="peakWidth"></param> /// <param name="obsPeakData"></param> /// <param name="theorPeakData"></param> /// <param name="theorIntensityCutOff"></param> /// <returns></returns> public double CalculateDeltaFromSeveralObservedPeaks(double startingDelta, double peakWidth, PeakData obsPeakData, PeakData theorPeakData, double theorIntensityCutOff) { //the idea is to use a selected number of theor peaks //and for each theor peak, use the delta (mz offset) info //to find the obs peak data and determine the delta value for that peak. //accumulate delta values in an array and then calculate a weighted average var numTheorPeaks = theorPeakData.GetNumPeaks(); var filteredTheorPeakData = new PeakData(); //filter the theor list var numFilteredTheorPeaks = 0; for (var i = 0; i < numTheorPeaks; i++) { ThrashV1Peak peak; theorPeakData.GetPeak(i, out peak); if (peak.Intensity >= theorIntensityCutOff) { filteredTheorPeakData.AddPeak(peak); numFilteredTheorPeaks++; } } if (numFilteredTheorPeaks == 0) { return(startingDelta); } var deltaArray = new double[numFilteredTheorPeaks]; var intensityArray = new double[numFilteredTheorPeaks]; double intensitySum = 0; //double weightedSumOfDeltas = 0; for (var i = 0; i < numFilteredTheorPeaks; i++) { ThrashV1Peak theorPeak; filteredTheorPeakData.GetPeak(i, out theorPeak); var targetMzLower = theorPeak.Mz + startingDelta - peakWidth; var targetMzUpper = theorPeak.Mz + startingDelta + peakWidth; ThrashV1Peak foundPeak; obsPeakData.FindPeak(targetMzLower, targetMzUpper, out foundPeak); if (foundPeak.Mz > 0) { deltaArray[i] = foundPeak.Mz - theorPeak.Mz; intensityArray[i] = foundPeak.Intensity; intensitySum += foundPeak.Intensity; } else { deltaArray[i] = startingDelta; intensityArray[i] = 0; //obs peak was not found; therefore assign 0 intensity (will have no effect on delta calc) } } if (intensitySum.Equals(0)) { return(startingDelta); // no obs peaks found at all; return default } //now perform a weighted average double weightedDelta = 0; for (var i = 0; i < numFilteredTheorPeaks; i++) { weightedDelta += intensityArray[i] / intensitySum * deltaArray[i]; } return(weightedDelta); }
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; }