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 addMZInfoToTheorProfile(IsotopicProfile unlabeledProfile, IsotopicProfile labeledTheorProfile, int numDeuteriums, int chargeState) { if (labeledTheorProfile.Peaklist == null || labeledTheorProfile.Peaklist.Count < 3) { return; } //assign the baseD mass labeledTheorProfile.MonoPeakMZ = unlabeledProfile.Peaklist[0].XValue + (Globals.Deuterium_MASS - Globals.Hydrogen_MASS) * (double)numDeuteriums / (double)chargeState; labeledTheorProfile.Peaklist[numDeuteriums].XValue = labeledTheorProfile.MonoPeakMZ; labeledTheorProfile.MonoIsotopicMass = (labeledTheorProfile.MonoPeakMZ - Globals.PROTON_MASS) * chargeState; //Assign m/z values to the left of the monoDMass var counter = 1; for (var i = numDeuteriums - 1; i >= 0; i--) { labeledTheorProfile.Peaklist[i].XValue = labeledTheorProfile.Peaklist[numDeuteriums].XValue - (double)counter * (1.003 / (double)chargeState); counter++; } //Assign m/z values to the right of the monoDMass counter = 1; for (var i = numDeuteriums + 1; i < labeledTheorProfile.Peaklist.Count; i++) { labeledTheorProfile.Peaklist[i].XValue = labeledTheorProfile.Peaklist[numDeuteriums].XValue + (double)counter * (1.003 / (double)chargeState); counter++; } }
/// <summary> /// Aligns an isotopic profile based on a source isotopic profile. /// </summary> /// <param name="iso1">Source isotopic profile</param> /// <param name="iso2">isotopic profile to be offset</param> public static void AlignTwoIsotopicProfiles(IsotopicProfile iso1, IsotopicProfile iso2) { double offset; if (iso2?.Peaklist == null || iso2.Peaklist.Count == 0) { return; } var mostIntensePeak = iso2.getMostIntensePeak(); var indexOfMostIntensePeak = iso2.Peaklist.IndexOf(mostIntensePeak); if (iso1.Peaklist == null || iso1.Peaklist.Count == 0) { return; } var enoughPeaksInTarget = (indexOfMostIntensePeak <= iso1.Peaklist.Count - 1); if (enoughPeaksInTarget) { var targetPeak = iso1.Peaklist[indexOfMostIntensePeak]; offset = targetPeak.XValue - mostIntensePeak.XValue; //offset = observedIsotopicProfile.Peaklist[0].XValue - theorIsotopicProfile.Peaklist[0].XValue; //want to test to see if Thrash is same as rapid } else { offset = iso1.Peaklist[0].XValue - iso2.Peaklist[0].XValue; } foreach (var peak in iso2.Peaklist) { peak.XValue = peak.XValue + offset; } }
private int GetIndexOfTargetPeak(IsotopicProfile mixedIso, double xValue, out bool peakWasFound, double toleranceInPPM = 1) { var toleranceInMZ = toleranceInPPM * xValue / 1e6; var indexOfPeak = 0; peakWasFound = false; for (var i = 0; i < mixedIso.Peaklist.Count; i++) { var currentPeakMZ = mixedIso.Peaklist[i].XValue; if (Math.Abs(currentPeakMZ - xValue) <= toleranceInMZ) { indexOfPeak = i; peakWasFound = true; break; } if (currentPeakMZ > xValue) // purpose is to report index of the peak that { indexOfPeak = i; peakWasFound = false; break; } } return(indexOfPeak); }
private IsotopicProfile AdjustIsotopicProfileMassesFromChargeState(IsotopicProfile iso, int existingCharge, int chargeNew) { if (iso != null) { //step 1, scale origional iso from mz to mono incease the input target is allready charged var massProton = DeconTools.Backend.Globals.PROTON_MASS; if (existingCharge > 0) { foreach (var peak in iso.Peaklist) { peak.XValue = (peak.XValue * existingCharge) - massProton * existingCharge; //gives us a monoisotopic mass } } //step 2, scale to mono back to mz using new charge iso.ChargeState = chargeNew; foreach (var peak in iso.Peaklist) { peak.XValue = (peak.XValue + chargeNew * massProton) / chargeNew;//gives us m/z } return(iso); } return(null); }
private List <Peak> getTopPeaks(IsotopicProfile iso, int numPeaks) { var sortedList = new List <Peak>(); //add peaks to new List so we don't mess up the old one for (var i = 0; i < iso.Peaklist.Count; i++) { sortedList.Add(iso.Peaklist[i]); } sortedList.Sort(delegate(Peak peak1, Peak peak2) { return(peak2.Height.CompareTo(peak1.Height)); } ); //sortedList.Reverse(); //take top n peaks sortedList = sortedList.Take(numPeaks).ToList(); return(sortedList); }
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; }
public void compareTomIsotopicDist_with_Mercury() { double mz = 1154.98841279744; //mono MZ int chargestate = 2; double fwhm = 0.0290254950523376; //from second peak of isotopic profile double monoMass = 1154.98841279744 * chargestate - chargestate * 1.00727649; double resolution = mz / fwhm; MercuryDistributionCreator distcreator = new MercuryDistributionCreator(); distcreator.CreateDistribution(monoMass, chargestate, resolution); distcreator.getIsotopicProfile(); Assert.AreEqual(8, distcreator.IsotopicProfile.GetNumOfIsotopesInProfile()); StringBuilder sb = new StringBuilder(); TestUtilities.ReportIsotopicProfileData(sb, distcreator.IsotopicProfile); IsotopicProfile cluster = TomIsotopicPattern.GetAvnPattern(monoMass, false); sb.Append(Environment.NewLine); TestUtilities.ReportIsotopicProfileData(sb, cluster); Console.Write(sb.ToString()); }
public override void Execute(ResultCollection resultList) { Check.Require(resultList.Run.CurrentMassTag != null, this.Name + " failed; CurrentMassTag is empty"); Check.Require(resultList.Run.XYData != null && resultList.Run.XYData.Xvalues != null && resultList.Run.XYData.Xvalues.Length > 0, this.Name + " failed; Run's XY data is empty. Need to Run an MSGenerator"); Check.Require(resultList.CurrentTargetedResult != null, "No MassTagResult has been generated for CurrentMassTag"); var theorProfile = new IsotopicProfile(); switch (IsotopicProfileType) { case DeconTools.Backend.Globals.IsotopicProfileType.UNLABELLED: Check.Require(resultList.Run.CurrentMassTag.IsotopicProfile != null, "Target's theoretical isotopic profile has not been established"); theorProfile = resultList.Run.CurrentMassTag.IsotopicProfile; break; case DeconTools.Backend.Globals.IsotopicProfileType.LABELLED: //Check.Require(resultList.Run.CurrentMassTag.IsotopicProfileLabelled != null, this.Name + " failed; Theor isotopic profile is empty. Run a TheorFeatureGenerator"); Check.Require(resultList.Run.CurrentMassTag.IsotopicProfileLabelled != null, "Target's labelled theoretical isotopic profile has not been established"); theorProfile = resultList.Run.CurrentMassTag.IsotopicProfileLabelled; break; default: theorProfile = resultList.Run.CurrentMassTag.IsotopicProfile; break; } resultList.CurrentTargetedResult.Score = CalculateFitScore(theorProfile, resultList.CurrentTargetedResult.IsotopicProfile, resultList.Run.XYData, NumberOfPeaksToLeftForPenalty); }
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)); } } }
public void test1() { Run run = new XCaliburRun(bsaO16O18file1); MSGeneratorFactory msgenFact = new MSGeneratorFactory(); Task msgen = msgenFact.CreateMSGenerator(run.MSFileType); DeconToolsPeakDetector peakDet = new DeconToolsPeakDetector(1.3, 2, DeconTools.Backend.Globals.PeakFitType.QUADRATIC, true); O16O18FeatureFinder finder = new O16O18FeatureFinder(); List <MassTag> massTagList = TestUtilities.CreateO16O18TestMassTagList1(); run.CurrentMassTag = massTagList[0]; TomTheorFeatureGenerator theorFeatureGen = new TomTheorFeatureGenerator(); theorFeatureGen.GenerateTheorFeature(run.CurrentMassTag); run.CurrentScanSet = new ScanSet(3294); msgen.Execute(run.ResultCollection); peakDet.Execute(run.ResultCollection); IsotopicProfile o16O18profile = finder.FindFeature(run.PeakList, run.CurrentMassTag.IsotopicProfile, 10, true); TestUtilities.DisplayIsotopicProfileData(o16O18profile); }
private double sumPeaks(IsotopicProfile profile, int numPeaksUsedInAbundance, int defaultVal) { if (profile.Peaklist == null || profile.Peaklist.Count < numPeaksUsedInAbundance) { return(defaultVal); } var peakListIntensities = new List <float>(); foreach (var peak in profile.Peaklist) { peakListIntensities.Add(peak.Height); } peakListIntensities.Sort(); peakListIntensities.Reverse(); // i know... this isn't the best way to do this! double summedIntensities = 0; for (var i = 0; i < peakListIntensities.Count; i++) { if (i < numPeaksUsedInAbundance) { summedIntensities += peakListIntensities[i]; } } return(summedIntensities); }
private IsotopicProfile GetUnlabelledIsotopicProfile(TargetBase mt) { var iso = new IsotopicProfile(); try { //empirical formula may contain non-integer values for iso = _isotopicDistCalculator.GetIsotopePattern(mt.EmpiricalFormula); } catch (Exception ex) { throw new Exception("Theoretical feature generator failed. Details: " + ex.Message); } PeakUtilities.TrimIsotopicProfile(iso, LowPeakCutOff); iso.ChargeState = mt.ChargeState; if (iso.ChargeState != 0) { calculateMassesForIsotopicProfile(iso, mt.MonoIsotopicMass, mt.ChargeState); } return(iso); }
public IsotopicProfile FindFeature(List <Peak> peakList, IsotopicProfile theorFeature, double toleranceInPPM, bool requireMonoPeak) { var basicFeatureFinder = new BasicMSFeatureFinder(); var o16profile = basicFeatureFinder.FindMSFeature(peakList, theorFeature, toleranceInPPM, false); if (o16profile == null) { return(null); } o16profile.ChargeState = theorFeature.ChargeState; var theorO18SingleLabel = convertO16ProfileToO18(theorFeature, 2); var theorO18DoubleLabel = convertO16ProfileToO18(theorFeature, 4); var o18SingleLabelProfile = basicFeatureFinder.FindMSFeature(peakList, theorO18SingleLabel, toleranceInPPM, false); var o18DoubleLabelProfile = basicFeatureFinder.FindMSFeature(peakList, theorO18DoubleLabel, toleranceInPPM, false); var foundO16O18Profile = new IsotopicProfile { ChargeState = theorFeature.ChargeState }; addIsotopePeaks(foundO16O18Profile, o16profile, 2); addIsotopePeaks(foundO16O18Profile, o18SingleLabelProfile, 2); addIsotopePeaks(foundO16O18Profile, o18DoubleLabelProfile, 100); // add as many peaks as possible lookForMissingPeaksAndInsertZeroIntensityPeaksWhenMissing(foundO16O18Profile, theorFeature); return(foundO16O18Profile); }
private void addIsotopePeaks(IsotopicProfile foundO16O18Profile, IsotopicProfile profileToAdd, int numIsotopePeaksToAdd) { if (profileToAdd?.Peaklist == null || profileToAdd.Peaklist.Count == 0) { return; } for (var i = 0; i < numIsotopePeaksToAdd; i++) { if (i < profileToAdd.Peaklist.Count) { var peakMz = profileToAdd.Peaklist[i].XValue; var toleranceInMZ = ToleranceInPPM / 1e6 * peakMz; var peaksAlreadyThere = PeakUtilities.GetMSPeaksWithinTolerance(foundO16O18Profile.Peaklist, peakMz, toleranceInMZ); if (peaksAlreadyThere == null || peaksAlreadyThere.Count == 0) { foundO16O18Profile.Peaklist.Add(profileToAdd.Peaklist[i]); } } else // if profileToAdd doesn't have enough peaks { break; } } foundO16O18Profile.Peaklist = foundO16O18Profile.Peaklist.OrderBy(p => p.XValue).ToList(); }
private int GetContiguousnessScore(IsotopicProfile subtractedIsoData) { var contiguousScore = 0; if (subtractedIsoData == null || subtractedIsoData.Peaklist.Count == 0) { return(contiguousScore); } var lastPeakWasAboveZero = false; foreach (var peak in subtractedIsoData.Peaklist) { if (peak.Height > 0) { contiguousScore++; lastPeakWasAboveZero = true; } else { if (lastPeakWasAboveZero) { contiguousScore--; } lastPeakWasAboveZero = false; } } return(contiguousScore); }
public void test2() { Peptide testPeptide = new Peptide("TTPSIIAYTDDETIVGQPAKR"); IsotopicProfile cluster = TomIsotopicPattern.GetIsotopePattern(testPeptide.GetEmpiricalFormulaIntArray(), TomIsotopicPattern.aafIsos); TestUtilities.DisplayIsotopicProfileData(cluster); }
private double SumPeaks(IsotopicProfile profile, double defaultVal) { if (profile.Peaklist == null || profile.Peaklist.Count == 0) { return(defaultVal); } var peakListIntensities = new List <float>(); foreach (var peak in profile.Peaklist) { peakListIntensities.Add(peak.Height); } // Provide a custom sort function to sort it in reverse order peakListIntensities.Sort((x, y) => y.CompareTo(x)); double summedIntensities = 0; for (var i = 0; i < peakListIntensities.Count; i++) { if (i < NumPeaksUsedInAbundance) { summedIntensities += peakListIntensities[i]; } } return(summedIntensities); }
public static void AdjustSaturatedIsotopicProfile(IsotopicProfile iso, IsotopicProfile theorIsotopicProfile, int indexOfIsotopeToUse, bool updatePeakMasses = true, bool updatePeakIntensities = true) { //ensure targetPeak is within range if (indexOfIsotopeToUse >= theorIsotopicProfile.Peaklist.Count) { return; } MSPeak observedPeakOfIsotopeToUse = iso.Peaklist[indexOfIsotopeToUse]; float intensityObsPeakForExtrapolation = observedPeakOfIsotopeToUse.Height; float widthObsPeakForExtrapolation = observedPeakOfIsotopeToUse.Width; var xValueObsPeakForExteapolation = observedPeakOfIsotopeToUse.XValue; float intensityTheorPeakForExtrapolation = theorIsotopicProfile.Peaklist[indexOfIsotopeToUse].Height; for (int i = 0; i < iso.Peaklist.Count; i++) { if (i < indexOfIsotopeToUse) { MSPeak currentPeak = iso.Peaklist[i]; if (updatePeakIntensities) { if (i >= theorIsotopicProfile.Peaklist.Count) { currentPeak.Height = 0; } else { currentPeak.Height = theorIsotopicProfile.Peaklist[i].Height * intensityObsPeakForExtrapolation / intensityTheorPeakForExtrapolation; } currentPeak.Width = widthObsPeakForExtrapolation; //repair the width too, because it can get huge. Width can be used in determining tolerances. } //correct the m/z value, to more accurately base it on the non-saturated peak. See Chernushevich et al. 2001 http://onlinelibrary.wiley.com/doi/10.1002/jms.207/abstract if (updatePeakMasses) { // formula is MZ0 = MZ3 - (1.003/z)*n, where MZ0 is the m/z of the saturated peak and MZ3 the m/z of the nonSaturated peak and z is charge state and n is the difference in peak number currentPeak.XValue = xValueObsPeakForExteapolation - ((Globals.MASS_DIFF_BETWEEN_ISOTOPICPEAKS) / iso.ChargeState * (indexOfIsotopeToUse - i)); } } } iso.IntensityMostAbundant = iso.getMostIntensePeak().Height; int indexMostAbundantPeakTheor = theorIsotopicProfile.GetIndexOfMostIntensePeak(); if (iso.Peaklist.Count > indexMostAbundantPeakTheor) { iso.IntensityMostAbundantTheor = iso.Peaklist[indexMostAbundantPeakTheor].Height; } else { iso.IntensityMostAbundantTheor = iso.IntensityMostAbundant; } UpdateMonoisotopicMassData(iso); }
public void GetRatioBasedOnTopPeaks(IsotopicProfile iso1, IsotopicProfile iso2, IsotopicProfile theorIso1, IsotopicProfile theorIso2, double backgroundIntensity, int numPeaks, out double ratio, out double ratioContribForIso1, out double ratioContribForIso2) { //Find top n peaks of the theor profile. Reference them by their peak index so that they can be looked up in the experimental. //List<int> sortedTheorIso1Indexes = getIndexValsOfTopPeaks(theorIso1); //List<int> sortedTheorIso2Indexes = getIndexValsOfTopPeaks(theorIso2); IList <Peak> topTheorIso1Peaks = GetTopPeaks(theorIso1, numPeaks); IList <Peak> topTheorIso2Peaks = GetTopPeaks(theorIso2, numPeaks); //get the top n peaks of the experimental profile, based on peaks of the theor profile //adjust intensity (subtract background intensity) var topIso1Peaks = GetTopPeaksBasedOnTheor(iso1, topTheorIso1Peaks, MSToleranceInPPM); var topIso2Peaks = GetTopPeaksBasedOnTheor(iso2, topTheorIso2Peaks, MSToleranceInPPM); //Since the number of top experimental iso peaks may be less than the number of top theor iso peaks, //we have to filter and ensure that they have the same peak numbers, so that the correction factor // (applied below) is properly applied. HOWEVER, this may induce some differences between runs var filteredTopTheorIso1Peaks = GetTopPeaksBasedOnTheor(theorIso1, topIso1Peaks, MSToleranceInPPM); var filteredTopTheorIso2Peaks = GetTopPeaksBasedOnTheor(theorIso2, topIso2Peaks, MSToleranceInPPM); var summedTopIso1PeakIntensities = PeakUtilities.GetSumOfIntensities(topIso1Peaks, backgroundIntensity); var summedTopIso2PeakIntensities = PeakUtilities.GetSumOfIntensities(topIso2Peaks, backgroundIntensity); //Console.WriteLine(backgroundIntensity); //need to find out the contribution of the top n peaks to the overall isotopic envelope. Base this on the theor profile double summedTheorIso1Intensities = filteredTopTheorIso1Peaks.Sum(p => (p.Height)); double summedTheorIso2Intensities = filteredTopTheorIso2Peaks.Sum(p => (p.Height)); var fractionTheor1 = summedTheorIso1Intensities / theorIso1.Peaklist.Sum(p => p.Height); var fractionTheor2 = summedTheorIso2Intensities / theorIso2.Peaklist.Sum(p => p.Height); //use the above ratio to correct the intensities based on how much the top n peaks contribute to the profile. var correctedIso1SummedIntensity = summedTopIso1PeakIntensities / fractionTheor1; var correctedIso2SummedIntensity = summedTopIso2PeakIntensities / fractionTheor2; var summedAllIsos1PeakIntensities = iso1.Peaklist.Sum(p => (p.Height - backgroundIntensity)); var summedAllIsos2PeakIntensities = iso2.Peaklist.Sum(p => (p.Height - backgroundIntensity)); switch (RatioType) { case RatioType.ISO1_OVER_ISO2: ratio = correctedIso1SummedIntensity / correctedIso2SummedIntensity; break; case RatioType.ISO2_OVER_ISO1: ratio = correctedIso2SummedIntensity / correctedIso1SummedIntensity; break; default: ratio = correctedIso1SummedIntensity / correctedIso2SummedIntensity; break; } ratioContribForIso1 = summedTopIso1PeakIntensities / summedAllIsos1PeakIntensities * 1 / fractionTheor1; //we expect a value of '1' ratioContribForIso2 = summedTopIso2PeakIntensities / summedAllIsos2PeakIntensities * 1 / fractionTheor2; }
public override double GetRatio(double[] xVals, double[] yVals, IsotopicProfile iso1, IsotopicProfile iso2, double backgroundIntensity) { var returnVal = GetRatioBasedOnAreaUnderPeaks(xVals, yVals, iso1, iso2, backgroundIntensity); return(returnVal); }
public void tester1() { int[] empIntArray = { 43, 67, 12, 13, 0 }; IsotopicProfile iso = TomIsotopicPattern.GetIsotopePattern(empIntArray, TomIsotopicPattern.aafIsos); TestUtilities.DisplayIsotopicProfileData(iso); }
private void ConvertToNewChargeState(IsotopicProfile pretendProfile, int chargeState) { for (var i = 0; i < pretendProfile.Peaklist.Count; i++) { pretendProfile.Peaklist[i].XValue = GetMZOfAnotherChargeState(pretendProfile, i, chargeState); } pretendProfile.MonoIsotopicMass = pretendProfile.Peaklist[pretendProfile.MonoIsotopicPeakIndex].XValue * chargeState; }
public virtual IsotopicProfile IterativelyFindMSFeature(XYData massSpecXyData, IsotopicProfile theorIso, out List <Peak> peakList) { if (massSpecXyData == null) { peakList = new List <Peak>(); return(null); } IsotopicProfile iso = null; this.MSPeakDetector.MinX = theorIso.MonoPeakMZ - 10; this.MSPeakDetector.MaxX = theorIso.MonoPeakMZ + 20; //start with high PeakBR and rachet it down, so as to detect more peaks with each pass. Stop when you find the isotopic profile. peakList = new List <Peak>(); for (var d = PeakDetectorPeakBR; d >= PeakBRMin; d = d - PeakBRStep) { this.MSPeakDetector.PeakToBackgroundRatio = d; peakList = MSPeakDetector.FindPeaks(massSpecXyData.Xvalues, massSpecXyData.Yvalues); iso = FindMSFeature(peakList, theorIso); bool isoIsGoodEnough; if (iso == null) { isoIsGoodEnough = false; } else if (iso.Peaklist.Count < 2) { isoIsGoodEnough = false; } else { double maxIntensity = iso.getMostIntensePeak().Height; double minIntensityPeak = iso.Peaklist.Min(p => p.Height); if (minIntensityPeak / maxIntensity < MinRelIntensityForPeakInclusion) { isoIsGoodEnough = true; } else { isoIsGoodEnough = false; } } if (isoIsGoodEnough) { break; } } return(iso); }
private void addInfoToResult(IsotopicProfile iso, PeptideTarget mt) { if (iso != null) { iso.ChargeState = mt.ChargeState; iso.MonoIsotopicMass = (iso.GetMZ() - Globals.PROTON_MASS) * mt.ChargeState; iso.IntensityMostAbundant = iso.getMostIntensePeak().Height; // may need to change this to sum the top n peaks. } }
private IsotopicProfile MakePotentialFeature(int chargeState, double monoPeakMZ, int monoIsotpoicPeakIndex, List <MSPeak> peakList) { var isopo = new IsotopicProfile(); isopo.ChargeState = chargeState; isopo.MonoPeakMZ = monoPeakMZ; isopo.MonoIsotopicPeakIndex = monoIsotpoicPeakIndex; isopo.Peaklist = peakList; return(isopo); }
private List <double> getTargetMZListForTopNPeaks(IsotopicProfile iso) { var msPeakListAboveThreshold = IsotopicProfileUtilities.GetTopMSPeaks(iso.Peaklist, TopNPeaksLowerCutOff); Check.Require(msPeakListAboveThreshold != null && msPeakListAboveThreshold.Count > 0, "PeakChromatogramGenerator failed. Attempted to generate chromatogram on unlabeled isotopic profile, but profile was never defined."); var targetMZList = (from n in msPeakListAboveThreshold select n.XValue).ToList(); return(targetMZList); }
public XYData GenerateChromatogram(Run run, IsotopicProfile theorProfile, double elutionTimeCenter = 0.5, Globals.ElutionTimeUnit elutionTimeUnit = Globals.ElutionTimeUnit.NormalizedElutionTime) { if (ChromatogramGeneratorMode == Globals.ChromatogramGeneratorMode.MZ_BASED) { throw new NotSupportedException("Don't use this method for MZ_BASED chromatogram generation. Use a different overload"); } var targetMZList = GetTargetMzList(theorProfile); return(GenerateChromatogram(run, targetMZList, elutionTimeCenter, elutionTimeUnit)); }
public XYData GenerateChromatogram(Run run, IsotopicProfile theorProfile, int lowerScan, int upperScan, double tolerance, Globals.ToleranceUnit toleranceUnit = Globals.ToleranceUnit.PPM) { if (ChromatogramGeneratorMode == Globals.ChromatogramGeneratorMode.MZ_BASED) { throw new NotSupportedException("Don't use this method for MZ_BASED chromatogram generation. Use a different overload"); } var targetMZList = GetTargetMzList(theorProfile); return(GenerateChromatogram(run, targetMZList, lowerScan, upperScan, tolerance, toleranceUnit)); }
public IsotopicProfile GetMixedIsotopicProfile() { IsotopicProfile mixedIso = null; foreach (var isotopicProfileComponent in IsotopicProfiles) { if (mixedIso == null) { mixedIso = isotopicProfileComponent.IsotopicProfile.CloneIsotopicProfile(); mixedIso.Peaklist.Clear(); } //we need to first make sure all the intensities of the peaks add up to 1 for each isotopic profile //then we need to adjust the ratios of each peak according to the fractional amount the isotopic profile contributes to the mixture var iso = isotopicProfileComponent.IsotopicProfile.CloneIsotopicProfile(); var sumIntensities = iso.Peaklist.Sum(p => p.Height); foreach (var msPeak in iso.Peaklist) { msPeak.Height = (float)(msPeak.Height / sumIntensities * isotopicProfileComponent.Fraction); } for (var i = 0; i < iso.Peaklist.Count; i++) { var currentPeak = iso.Peaklist[i]; var indexOfPeak = GetIndexOfTargetPeak(mixedIso, currentPeak.XValue, out var mixedIsoContainsMZ); if (mixedIsoContainsMZ) { mixedIso.Peaklist[indexOfPeak].Height += currentPeak.Height; } else { var addedPeak = new MSPeak(currentPeak.XValue, currentPeak.Height, currentPeak.Width, currentPeak.SignalToNoise) { MSFeatureID = currentPeak.MSFeatureID, DataIndex = currentPeak.DataIndex }; var insertionIndex = indexOfPeak - 1; //the above method returns the m/z of the next highest peak if (insertionIndex >= 0) { mixedIso.Peaklist.Insert(insertionIndex, addedPeak); } else { mixedIso.Peaklist.Add(addedPeak); } } } } return(mixedIso); }
public void test1() { Run run = new MSScanFromTextFileRun(imfMSScanTextfile); ResultCollection resultcollection = new ResultCollection(run); Task msgen = new GenericMSGenerator(); msgen.Execute(resultcollection); DeconToolsV2.Peaks.clsPeakProcessorParameters detectorParams = new DeconToolsV2.Peaks.clsPeakProcessorParameters(); detectorParams.PeakBackgroundRatio = 3; detectorParams.PeakFitType = DeconToolsV2.Peaks.PEAK_FIT_TYPE.QUADRATIC; detectorParams.SignalToNoiseThreshold = 3; detectorParams.ThresholdedData = false; Task peakdetector = new DeconToolsPeakDetector(detectorParams); peakdetector.Execute(resultcollection); Task rapidDecon = new RapidDeconvolutor(); rapidDecon.Execute(resultcollection); int counter = 0; foreach (StandardIsosResult result in resultcollection.ResultList) { IsotopicProfile profile = result.IsotopicProfile; Console.Write("------------ profile" + counter + "; Charge state = " + profile.ChargeState + "; Score= " + profile.Score.ToString("0.00") + " ----------------\n"); int peakcounter = 0; Console.Write("idx" + "\t" + "mz" + "\t" + "intensity" + "\t" + "SN" + "\t" + "FWHM" + "\n"); foreach (MSPeak peak in profile.Peaklist) { Console.Write(peakcounter + "\t" + peak.XValue + "\t" + peak.Height + "\t" + peak.SN + "\t" + peak.Width + "\n"); peakcounter++; } counter++; } Assert.AreEqual(9, resultcollection.ResultList.Count); Assert.AreEqual(582.820684517665, Convert.ToDecimal(resultcollection.ResultList[0].IsotopicProfile.Peaklist[0].XValue)); Assert.AreEqual(2984.0, resultcollection.ResultList[0].IsotopicProfile.Peaklist[0].Height); Assert.AreEqual(0.05905123, (decimal)resultcollection.ResultList[0].IsotopicProfile.Peaklist[0].Width); Assert.AreEqual(157.0526, (decimal)resultcollection.ResultList[0].IsotopicProfile.Peaklist[0].SN); Assert.AreEqual(4593, resultcollection.ResultList[0].IsotopicProfile.GetAbundance()); Assert.AreEqual(1, resultcollection.ResultList[8].IsotopicProfile.GetNumOfIsotopesInProfile()); Assert.AreEqual(2488.07303881522, Convert.ToDecimal(resultcollection.ResultList[8].IsotopicProfile.AverageMass)); Assert.AreEqual(3, resultcollection.ResultList[8].IsotopicProfile.ChargeState); Assert.AreEqual(18802, Convert.ToDecimal(resultcollection.ResultList[8].IsotopicProfile.IntensityAggregate)); Assert.AreEqual(2486.09777364184, Convert.ToDecimal(resultcollection.ResultList[8].IsotopicProfile.MonoIsotopicMass)); }
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; }
/// <summary> /// Executes the cross-link search for LC-IMS-TOF data. /// </summary> /// <param name="settings">Settings object to control parameters for cross-linking.</param> /// <param name="proteinSequenceEnumerable">IEnumerable of protein sequences, as a .NET Bio ISequence object.</param> /// <param name="featureList">List of LC-IMS-MS Features, as LcImsMsFeature.</param> /// <param name="peakList">List of Isotopic Peaks, as IsotopicPeak.</param> /// <returns>An enumerable of CrossLinkResult objects.</returns> public static IList<CrossLinkResult> Execute( CrossLinkSettings settings, IEnumerable<ISequence> proteinSequenceEnumerable, List<LcImsMsFeature> featureList, List<IsotopicPeak> peakList) { var massToleranceBase = settings.MassTolerance; var maxMissedCleavages = settings.MaxMissedCleavages; var digestionRule = settings.TrypticType; CrossLinkUtil.StaticDeltaMass = settings.StaticDeltaMass; CrossLinkUtil.UseC13 = settings.UseC13; CrossLinkUtil.UseN15 = settings.UseN15; Console.WriteLine(); Console.WriteLine("Mass Tolerance: " + massToleranceBase + " ppm"); Console.WriteLine("Max missed cleavages: " + maxMissedCleavages); Console.WriteLine("Digestion rule: " + settings.TrypticType ); Console.WriteLine("Delta mass uses C13: " + settings.UseC13); Console.WriteLine("Delta mass uses N15: " + settings.UseN15); Console.WriteLine("Static delta mass addon: " + settings.StaticDeltaMass + " Da"); // Used for finding Isotopic Profiles in the data var msFeatureFinder = new BasicTFF(); var crossLinkList = new List<CrossLink>(); var lastProgress = DateTime.UtcNow; var proteinsProcessed = 0; // Create CrossLink objects from all of the protein sequences foreach (var proteinSequence in proteinSequenceEnumerable) { var proteinSequenceString = new string(proteinSequence.Select((a => (char)a)).ToArray()); var proteinId = proteinSequence.ID; // Get a List of Peptides from the Protein Sequence var peptideList = SequenceUtil.DigestProtein(proteinSequenceString, digestionRule, maxMissedCleavages); // Find all possible cross links from the peptide list var crossLinkEnumerable = CrossLinkUtil.GenerateTheoreticalCrossLinks(peptideList, proteinSequenceString, proteinId); crossLinkList.AddRange(crossLinkEnumerable); proteinsProcessed++; if (DateTime.UtcNow.Subtract(lastProgress).TotalSeconds >= 15) { lastProgress = DateTime.UtcNow; Console.WriteLine("Creating cross linked peptide list; " + proteinsProcessed + " proteins processed"); } } Console.WriteLine("Sorting cross-linked peptides"); // Sort the CrossLinks by mass so that the results are ordered in a friendly way IEnumerable<CrossLink> orderedCrossLinkEnumerable = crossLinkList.OrderBy(x => x.Mass); // Sort Feature by mass so we can use binary search featureList = featureList.OrderBy(x => x.MassMonoisotopic).ToList(); // Set up a Feature Comparer and Peak Comparer to use for binary search later on var featureComparer = new AnonymousComparer<LcImsMsFeature>((x, y) => x.MassMonoisotopic.CompareTo(y.MassMonoisotopic)); var peakComparer = new AnonymousComparer<IsotopicPeak>((x, y) => x.ScanLc != y.ScanLc ? x.ScanLc.CompareTo(y.ScanLc) : x.ScanIms != y.ScanIms ? x.ScanIms.CompareTo(y.ScanIms) : x.Mz.CompareTo(y.Mz)); // Sort the Isotopic Peaks by LC Scan, IMS Scan, and m/z to set them up for binary search later on peakList.Sort(peakComparer); var crossLinkResultList = new List<CrossLinkResult>(); var totalCandidatePeptides = crossLinkList.Count; Console.WriteLine("Searching isotopic data vs. " + totalCandidatePeptides.ToString("#,##0") + " candidate cross-linked peptides"); lastProgress = DateTime.UtcNow; var crosslinkCandidatesProcessed = 0; // Search the data for the existence of cross-links foreach (var crossLink in orderedCrossLinkEnumerable) { // Calculate mass tolerance to use for binary search var massTolerance = massToleranceBase * crossLink.Mass / GeneralConstants.PPM_DIVISOR; var lowFeature = new LcImsMsFeature { MassMonoisotopic = crossLink.Mass - massTolerance }; var highFeature = new LcImsMsFeature { MassMonoisotopic = crossLink.Mass + massTolerance }; var lowFeaturePosition = featureList.BinarySearch(lowFeature, featureComparer); var highFeaturePosition = featureList.BinarySearch(highFeature, featureComparer); lowFeaturePosition = lowFeaturePosition < 0 ? ~lowFeaturePosition : lowFeaturePosition; highFeaturePosition = highFeaturePosition < 0 ? ~highFeaturePosition : highFeaturePosition; // Iterate over all LC-IMS-MS Features that match the Unmodified cross-link mass for (var i = lowFeaturePosition; i < highFeaturePosition; i++) { var feature = featureList[i]; // Search for a mass shift in each of the LC Scans the unmodified cross-link mass was found for (var currentScanLc = feature.ScanLcStart; currentScanLc <= feature.ScanLcEnd; currentScanLc++) { var crossLinkResult = new CrossLinkResult(crossLink, feature, currentScanLc); var candidatePeaks = PeakUtil.FindCandidatePeaks(peakList, feature.MzMonoisotopic, currentScanLc, feature.ScanImsRep); var massShiftList = crossLink.MassShiftList; var shiftedMassList = new List<double>(); // Calculate the shifted mass values that we want to search for switch (massShiftList.Count) { case 1: { var firstNewMass = feature.MassMonoisotopic + massShiftList[0]; shiftedMassList.Add(firstNewMass); } break; case 2: { var firstNewMass = feature.MassMonoisotopic + massShiftList[0]; var secondNewMass = feature.MassMonoisotopic + massShiftList[1]; var thirdNewMass = feature.MassMonoisotopic + massShiftList[0] + massShiftList[1]; shiftedMassList.Add(firstNewMass); shiftedMassList.Add(secondNewMass); shiftedMassList.Add(thirdNewMass); } break; } // Search for shifted mass values in Isotopic Peaks foreach (var shiftedMass in shiftedMassList) { var shiftedMz = (shiftedMass / feature.ChargeState) + GeneralConstants.MASS_OF_PROTON; // Create theoretical Isotopic Peaks that will later form a theoretical Isotopic Profile var theoreticalPeakList = new List<MSPeak> { new MSPeak { XValue = shiftedMz, Height = 1 } }; for (double k = 1; k < 4; k++) { theoreticalPeakList.Add(new MSPeak { XValue = shiftedMz + (k * 1.003 / feature.ChargeState), Height = (float)(1.0 - (k / 4)) }); theoreticalPeakList.Add(new MSPeak { XValue = shiftedMz - (k * 1.003 / feature.ChargeState), Height = (float)(1.0 - (k / 4)) }); } // Sort peaks by m/z var sortPeaksQuery = from peak in theoreticalPeakList orderby peak.XValue select peak; // Create a theoretical Isotopic Profile for DeconTools to search for var isotopicProfile = new IsotopicProfile { MonoIsotopicMass = shiftedMass, MonoPeakMZ = shiftedMz, ChargeState = feature.ChargeState, Peaklist = sortPeaksQuery.ToList() }; // Search for the theoretical Isotopic Profile var foundProfile = msFeatureFinder.FindMSFeature(candidatePeaks, isotopicProfile, massToleranceBase, false); /* * It is possible that the set mono pass of the previous theoretical distribution was the right-most peak of the actual distribution * If so, we should be able to shift the theoretical distribution over to the left and find the actual distribution */ if (foundProfile == null) { foreach (var msPeak in sortPeaksQuery) { msPeak.XValue -= (1.003 / feature.ChargeState); } isotopicProfile = new IsotopicProfile { MonoIsotopicMass = shiftedMass - 1.003, MonoPeakMZ = shiftedMz - (1.003 / feature.ChargeState), ChargeState = feature.ChargeState, Peaklist = sortPeaksQuery.ToList() }; foundProfile = msFeatureFinder.FindMSFeature(candidatePeaks, isotopicProfile, massToleranceBase, false); } // Add to results, even if we did not find it. var didFindProfile = foundProfile != null; crossLinkResult.MassShiftResults.KvpList.Add(new KeyValuePair<double, bool>(shiftedMass, didFindProfile)); } crossLinkResultList.Add(crossLinkResult); } } crosslinkCandidatesProcessed++; if (DateTime.UtcNow.Subtract(lastProgress).TotalSeconds >= 10) { lastProgress = DateTime.UtcNow; var percentComplete = crosslinkCandidatesProcessed / (double)totalCandidatePeptides * 100; Console.WriteLine("Searching isotopic data; " + percentComplete.ToString("0.0") + "% complete"); } } return crossLinkResultList; }