private void CalculateMassesForIsotopicProfile(IsotopicProfile iso) { if (iso?.Peaklist == null) { return; } //start with most abundant peak. var indexMostAbundantPeak = iso.GetIndexOfMostIntensePeak(); var mzMostAbundantPeak = iso.MostAbundantIsotopeMass / iso.ChargeState + Globals.PROTON_MASS; //start with most abundant peak and move to the LEFT and calculate m/z values for (var peakIndex = indexMostAbundantPeak; peakIndex >= 0; peakIndex--) { var numPeaksToLeft = indexMostAbundantPeak - peakIndex; var calcMZ = mzMostAbundantPeak - numPeaksToLeft * 1.00235 / iso.ChargeState; iso.Peaklist[peakIndex].XValue = calcMZ; } //move to the RIGHT and calculate m/z values for (var peakIndex = indexMostAbundantPeak + 1; peakIndex < iso.Peaklist.Count; peakIndex++) { var numPeaksToRight = peakIndex - indexMostAbundantPeak; var calcMZ = mzMostAbundantPeak + numPeaksToRight * 1.00235 / iso.ChargeState; iso.Peaklist[peakIndex].XValue = calcMZ; } iso.MonoPeakMZ = iso.getMonoPeak().XValue; iso.MonoIsotopicMass = (iso.MonoPeakMZ - Globals.PROTON_MASS) * iso.ChargeState; }
private MSPeak GetPeakToTheLeftIfExists(IsotopicProfile isotopicProfile, IEnumerable <Peak> peakList) { if (isotopicProfile == null) { return(null); } var monoPeak = isotopicProfile.getMonoPeak(); const double maxPossiblePeakWidth = 0.1; var mzTol = Math.Min(maxPossiblePeakWidth, monoPeak.Width); var targetMZ = monoPeak.XValue - (1.003 / isotopicProfile.ChargeState); MSPeak peakToTheLeft = null; foreach (var peak in peakList) { var msPeak = (MSPeak)peak; if (Math.Abs(msPeak.XValue - targetMZ) < mzTol) { peakToTheLeft = msPeak; break; } } //peak to the left height must be greater than half the mono peak if (peakToTheLeft?.Height > monoPeak.Height * 0.5) //if peak-to-the-left exceeds min Ratio, then consider it { return(peakToTheLeft); } return(null); }
private void lookForMissingPeaksAndInsertZeroIntensityPeaksWhenMissing(IsotopicProfile o16o18Profile, IsotopicProfile theorFeature) { if (o16o18Profile.Peaklist.Count == 0) { return; } var mzDistanceBetweenIsotopes = 1.003 / o16o18Profile.ChargeState; var monoMZ = theorFeature.getMonoPeak().XValue; var indexOfLastPeak = o16o18Profile.Peaklist.Count - 1; var toleranceInDa = 0.1; //this will iterate over the first five expected m/z values of a theoretical profile //and loosely try to the corresponding peak within the observed profile. //If missing, will add one at the expected m/z. This ensures no missing peaks within the O16O18 profile //so that looking up the first peak will always give you the intensity of the O16 peak (even if //it never existed in the real data - in this case the intensity is 0); for (var i = 0; i < 6; i++) { var currentMZ = monoMZ + mzDistanceBetweenIsotopes * i; var peaksWithinTol = PeakUtilities.GetMSPeaksWithinTolerance(o16o18Profile.Peaklist, currentMZ, toleranceInDa); if (peaksWithinTol.Count == 0) // { o16o18Profile.Peaklist.Insert(i, new MSPeak(currentMZ, 0, 0, 0)); } } }
private double getIScore(List <MSPeak> peakList, IsotopicProfile iso) { var monoPeak = iso.getMonoPeak(); var lastPeak = iso.Peaklist[iso.Peaklist.Count - 1]; var leftMZBoundary = monoPeak.XValue - 1.1; var rightMZBoundary = lastPeak.XValue + lastPeak.Width / 2.35 * 2; // 2 sigma var interferenceVal = iScorer.GetInterferenceScore(peakList, iso.Peaklist, leftMZBoundary, rightMZBoundary); return(interferenceVal); }
private List <double> GetTargetMzList(IsotopicProfile theorIso) { List <double> targetMZList; switch (ChromatogramGeneratorMode) { case Globals.ChromatogramGeneratorMode.MZ_BASED: { throw new NotSupportedException("Don't use this method if you already know your MZ target."); } case Globals.ChromatogramGeneratorMode.TOP_N_PEAKS: { targetMZList = getTargetMZListForTopNPeaks(theorIso); } break; case Globals.ChromatogramGeneratorMode.O16O18_THREE_MONOPEAKS: { targetMZList = getTargetMZListForO16O18ThreeMonoPeaks(theorIso); } break; case Globals.ChromatogramGeneratorMode.MONOISOTOPIC_PEAK: { var targetMZ = theorIso.getMonoPeak().XValue; targetMZList = new List <double> { targetMZ }; break; } case Globals.ChromatogramGeneratorMode.MOST_ABUNDANT_PEAK: { var targetMZ = theorIso.getMostIntensePeak().XValue; targetMZList = new List <double> { targetMZ }; break; } default: { throw new NotSupportedException( "Chromatogram generation failed. Selected ChromatogramGeneratorMode is not supported"); } } return(targetMZList); }
public double GetInterferenceScore(IsotopicProfile observedIso, List <Peak> observedMSPeaks) { if (observedIso == null) { return(1.0); } if (!observedMSPeaks.Any()) { return(1.0); } var leftBoundary = observedIso.getMonoPeak().XValue - 1.1; var rightMostPeak = observedIso.Peaklist[observedIso.Peaklist.Count - 1]; var rightBoundary = rightMostPeak.XValue + rightMostPeak.Width / 2.35 * 2; // 2 * sigma return(GetInterferenceScore(observedIso, observedMSPeaks, leftBoundary, rightBoundary)); }
private void PerformIterativeFittingAndGetAlignedProfile(XYData xyData, XYData theorXYData, int chargeState, ref IsotopicProfile theorIso, ref double bestFitVal) { if (xyData == null || xyData.Xvalues.Length == 0) { bestFitVal = 1; return; } double relIntensityUseForFitting = 0; int ionCountUsed; var fitval = _areafitter.GetFit(theorXYData, xyData, relIntensityUseForFitting, out ionCountUsed); if (fitval < bestFitVal) { bestFitVal = fitval; } double bestOffsetForTheorProfile = 0; // move fitting window to the left for (var numPeaksToTheLeft = 1; numPeaksToTheLeft < 10; numPeaksToTheLeft++) { var offsetForTheorProfile = -1 * numPeaksToTheLeft * Globals.MASS_DIFF_BETWEEN_ISOTOPICPEAKS / chargeState; //negative offset fitval = _areafitter.GetFit(theorXYData, xyData, relIntensityUseForFitting, out ionCountUsed, offsetForTheorProfile); if (fitval > bestFitVal || fitval >= 1 || double.IsNaN(fitval)) { break; } bestFitVal = fitval; bestOffsetForTheorProfile = offsetForTheorProfile; } //move fitting window to the right for (var numPeaksToTheRight = 1; numPeaksToTheRight < 10; numPeaksToTheRight++) { var offsetForTheorProfile = numPeaksToTheRight * Globals.MASS_DIFF_BETWEEN_ISOTOPICPEAKS / chargeState; fitval = _areafitter.GetFit(theorXYData, xyData, relIntensityUseForFitting, out ionCountUsed, offsetForTheorProfile); if (fitval >= bestFitVal || fitval >= 1 || double.IsNaN(fitval)) { break; } bestFitVal = fitval; bestOffsetForTheorProfile = offsetForTheorProfile; } foreach (var theorMSPeak in theorIso.Peaklist) { theorMSPeak.XValue = theorMSPeak.XValue + bestOffsetForTheorProfile; } theorIso.MonoPeakMZ = theorIso.getMonoPeak().XValue; theorIso.MonoIsotopicMass = (theorIso.MonoPeakMZ - Globals.PROTON_MASS) * chargeState; theorIso.MostAbundantIsotopeMass = (theorIso.getMostIntensePeak().XValue - Globals.PROTON_MASS) * chargeState; }
public virtual IsotopicProfile FindMSFeature(List <Peak> peakList, IsotopicProfile theorFeature) { Check.Require(theorFeature != null, "Theoretical feature hasn't been defined."); if (theorFeature == null) { return(null); } Check.Require(theorFeature.Peaklist != null && theorFeature.Peaklist.Count > 0, "Theoretical feature hasn't been defined."); var outFeature = new IsotopicProfile { ChargeState = theorFeature.ChargeState }; var indexOfMaxTheorPeak = theorFeature.GetIndexOfMostIntensePeak(); var toleranceInMZ = theorFeature.getMonoPeak().XValue *ToleranceInPPM / 1e6; var foundMatchingMaxPeak = false; double massDefect = 0; // this is the m/z diff between the max peak of theor feature and the max peak of the experimental feature var failedResult = false; for (var i = indexOfMaxTheorPeak; i >= 0; i--) { //find experimental peak(s) within range var peaksWithinTol = PeakUtilities.GetPeaksWithinTolerance(peakList, theorFeature.Peaklist[i].XValue, toleranceInMZ); if (i == indexOfMaxTheorPeak) { foundMatchingMaxPeak = peaksWithinTol.Count > 0; } if (!foundMatchingMaxPeak) // can't even find the observed peak that matches the most intense theor peak. { failedResult = true; break; } if (peaksWithinTol.Count == 0) { if (NeedMonoIsotopicPeak) { //here, we are looking to the left of most intense theor peak. If we have the prerequisite of finding the monoIsotopic peak and fail here, we'll return a failed result failedResult = true; } break; // stop looking to the left of the most intense peak. } if (peaksWithinTol.Count == 1) { if (outFeature.Peaklist.Count == 0) { outFeature.Peaklist.Add((MSPeak)peaksWithinTol[0]); } else { outFeature.Peaklist.Insert(0, (MSPeak)peaksWithinTol[0]); } } else // when we have several peaks within tolerance, we'll need to decide what to do { MSPeak bestPeak; if (i == indexOfMaxTheorPeak) //when matching to most intense peak, we will use the most intense peak { bestPeak = (MSPeak)findMostIntensePeak(peaksWithinTol); } else { bestPeak = (MSPeak)findClosestToXValue(peaksWithinTol, theorFeature.Peaklist[i].XValue - massDefect); } if (outFeature.Peaklist.Count == 0) { outFeature.Peaklist.Add(bestPeak); } else { outFeature.Peaklist.Insert(0, bestPeak); } } if (i == indexOfMaxTheorPeak) //when matching to most intense peak, we will get the mass defect using the most intense peak { massDefect = theorFeature.Peaklist[i].XValue - outFeature.Peaklist[0].XValue; } } //------------------------- look right ------------------------------------------- for (var i = indexOfMaxTheorPeak + 1; i < theorFeature.Peaklist.Count; i++) //start one peak to the right of the max intense theor peak { var peaksWithinTol = PeakUtilities.GetPeaksWithinTolerance(peakList, theorFeature.Peaklist[i].XValue, toleranceInMZ); if (peaksWithinTol.Count == 0) { if (i == indexOfMaxTheorPeak + 1) // first peak to the right of the max peak. We need this one or we declare it to be a failure (= null) { failedResult = true; } break; // finished. Exit loop. } if (peaksWithinTol.Count == 1) { outFeature.Peaklist.Add((MSPeak)peaksWithinTol[0]); //here, we tack peaks onto the profile } else //two or more peaks are within tolerance. Need to get the best one, which is based on the distance from the { outFeature.Peaklist.Add((MSPeak)findClosestToXValue(peaksWithinTol, theorFeature.Peaklist[i].XValue - massDefect)); } } //for higher mass peptides, we will return the profile if there is 2 or more peaks, regardless if none are found to the right of the most abundant if (indexOfMaxTheorPeak > 0 && outFeature.Peaklist.Count > 1) { failedResult = false; } if (failedResult) { return(null); // return a null Isotopic profile, indicating a failed result } addMassInfoToIsotopicProfile(theorFeature, outFeature); return(outFeature); }
private void UpdateMonoisotopicMassData(IsotopicProfile iso) { iso.MonoIsotopicMass = (iso.getMonoPeak().XValue - Globals.PROTON_MASS) * iso.ChargeState; iso.MonoPeakMZ = iso.getMonoPeak().XValue; iso.MostAbundantIsotopeMass = (iso.getMostIntensePeak().XValue - Globals.PROTON_MASS) * iso.ChargeState; }
private static void UpdateMonoisotopicMassData(IsotopicProfile iso) { iso.MonoIsotopicMass = (iso.getMonoPeak().XValue - Globals.PROTON_MASS) * iso.ChargeState; iso.MonoPeakMZ = iso.getMonoPeak().XValue; iso.MostAbundantIsotopeMass = (iso.getMostIntensePeak().XValue - Globals.PROTON_MASS) * iso.ChargeState; }