private IsotopicProfile GetTheorIsotopicProfile(IsosResult saturatedFeature, double lowerIntensityCutoff = 0.0001) { var theorTarget = new PeptideTarget { ChargeState = (short)saturatedFeature.IsotopicProfile.ChargeState, MonoIsotopicMass = saturatedFeature.IsotopicProfile.MonoIsotopicMass }; theorTarget.MZ = (theorTarget.MonoIsotopicMass / theorTarget.ChargeState) + Globals.PROTON_MASS; var averagineFormula = _tomIsotopicPatternGenerator.GetClosestAvnFormula(saturatedFeature.IsotopicProfile.MonoIsotopicMass, false); theorTarget.IsotopicProfile = _tomIsotopicPatternGenerator.GetIsotopePattern(averagineFormula, _tomIsotopicPatternGenerator.aafIsos); theorTarget.EmpiricalFormula = averagineFormula; theorTarget.CalculateMassesForIsotopicProfile(saturatedFeature.IsotopicProfile.ChargeState); //NOTE: This is critical to choosing the optimum peak of the observed isotopic profile //A value of 0.001 will leave more peaks in the theor profile. This //can be bad with co-eluting peptides, so that a peak of the interfering peptide //is used to correct the intensity of our target peptide. //A value of 0.01 helps prevent this (by trimming the peaks of the theor profile, //and reducing the peaks to be considered for peak intensity extrapolation of the target peptide. PeakUtilities.TrimIsotopicProfile(theorTarget.IsotopicProfile, lowerIntensityCutoff); return(theorTarget.IsotopicProfile); }
public void PartialLabelingQuantifierTest1() { // see https://jira.pnnl.gov/jira/browse/OMCS-743 var peptideSeq = "SAMPLERSAMPLER"; var isoCreator = new LabeledIsotopicProfileUtilities(); var elementLabelled = "C"; var lightIsotope = 12; var heavyIsotope = 13; var target = new PeptideTarget(); target.Code = peptideSeq; target.EmpiricalFormula = target.GetEmpiricalFormulaFromTargetCode(); target.ChargeState = 2; target.CalculateMassesForIsotopicProfile(target.ChargeState); target.IsotopicProfile = isoCreator.CreateIsotopicProfileFromEmpiricalFormula(target.EmpiricalFormula, elementLabelled, 12, 13, 0, target.ChargeState); double[] obsMZVals = { 794.4027177, 794.9043951, 795.4060725, 795.9077499, 796.4094273, 796.9111047, 797.4127822, 797.9144596, 798.416137, 798.9178144, 799.4194918, 799.9211693, 800.4228467, 800.9245241, 801.4262015, 801.9278789, 802.4295564, 802.9312338, 803.4329112, 803.9345886, 804.436266, 804.9379435, 805.4396209, 805.9412983, 806.4429757, 806.9446531, 807.4463306, 807.948008, 808.4496854, 808.9513628, 809.4530402, 809.9547176, 810.4563951 }; double[] obsIntensities = { 0.202610146, 0.169786958, 0.10004317, 0.048528412, 0.023649271, 0.01375091, 0.011401505, 0.010165125, 0, 0, 0, 0,0, 0.016295369, 0.02039971, 0.02628524 , 0.034368448, 0.042300575, 0.050392505, 0.057402354, 0.061016738, 0.061990991, 0.059175713, 0.053291295, 0.046892873, 0.037952256, 0.030884989 , 0.024965924, 0.019531111, 0.01613184, 0, 0, 0 }; var peakList = obsMZVals.Select((t, i) => new Peak(t, (float)obsIntensities[i], 0)).ToList(); var partialLabelingQuantifier = new PartialLabelingQuantifier("C", 12, 13); var bestIso = partialLabelingQuantifier.FindBestLabeledProfile(target, peakList, null); var counter = 0; foreach (var currentFitScore in partialLabelingQuantifier.FitScoreData) { Console.WriteLine(currentFitScore.Key + "\t" + currentFitScore.Value); counter++; } }
public override void GetFitScores(IEnumerable <IsosResult> isosResults) { foreach (var result in isosResults) { //create a temporary mass tag, as a data object for storing relevant info, and using the CalculateMassesForIsotopicProfile() method. var mt = new PeptideTarget { ChargeState = (short)result.IsotopicProfile.ChargeState, MonoIsotopicMass = result.IsotopicProfile.MonoIsotopicMass }; mt.MZ = (mt.MonoIsotopicMass / mt.ChargeState) + Globals.PROTON_MASS; //TODO: use Josh's isotopicDistribution calculator after confirming averagine formula mt.EmpiricalFormula = _tomIsotopicPatternGenerator.GetClosestAvnFormula(result.IsotopicProfile.MonoIsotopicMass, false); mt.IsotopicProfile = _tomIsotopicPatternGenerator.GetIsotopePattern(mt.EmpiricalFormula, _tomIsotopicPatternGenerator.aafIsos); TheorIsotopicProfile = mt.IsotopicProfile; mt.CalculateMassesForIsotopicProfile(mt.ChargeState); var theorXYData = mt.IsotopicProfile.GetTheoreticalIsotopicProfileXYData(result.IsotopicProfile.GetFWHM()); offsetDistribution(theorXYData, mt.IsotopicProfile, result.IsotopicProfile); // Obsolete Class-wide variable: MercuryDistributionCreator distributionCreator; // //double resolution = result.IsotopicProfile.GetMZofMostAbundantPeak() / result.IsotopicProfile.GetFWHM(); //distributionCreator.CreateDistribution(result.IsotopicProfile.MonoIsotopicMass, result.IsotopicProfile.ChargeState, resolution); //distributionCreator.OffsetDistribution(result.IsotopicProfile); //XYData theorXYData = distributionCreator.Data; var areaFitter = new AreaFitter(); var fitVal = areaFitter.GetFit(theorXYData, result.Run.XYData, 0.1, out _); if (double.IsNaN(fitVal) || fitVal > 1) { result.IsotopicProfile.Score = 1; } else { result.IsotopicProfile.Score = fitVal; } } }
public void GetUnsummedIntensitiesAndDetectSaturation(Run run, IEnumerable <IsosResult> resultList) { Check.Require(run != null, "SaturationDetector failed. Run is null"); if (run == null) { return; } if (_msGenerator == null) { _msGenerator = MSGeneratorFactory.CreateMSGenerator(run.MSFileType); } if (run is UIMFRun uimfRun) { if (uimfRun.CurrentScanSet == null) { throw new NullReferenceException("CurrentScanSet is null. You need to set it."); } if (uimfRun.CurrentIMSScanSet == null) { throw new NullReferenceException("CurrentIMSScanSet is null. You need to set it."); } //this creates a FrameSet containing only the primary frame. Therefore no summing will occur var lcScanSet = new ScanSet(uimfRun.CurrentScanSet.PrimaryScanNumber); //this creates a ScanSet containing only the primary scan. Therefore no summing will occur var imsScanSet = new IMSScanSet(uimfRun.CurrentIMSScanSet.PrimaryScanNumber); //get the mass spectrum +/- 5 da from the range of the isotopicProfile uimfRun.CurrentScanSet = lcScanSet; uimfRun.CurrentIMSScanSet = imsScanSet; _msGenerator.Execute(run.ResultCollection); } else { if (run.CurrentScanSet == null) { throw new NullReferenceException("CurrentScanSet is null. You need to set it."); } //this creates a ScanSet containing only the primary scan. Therefore no summing will occur var scanSet = new ScanSet(run.CurrentScanSet.PrimaryScanNumber); run.CurrentScanSet = scanSet; _msGenerator.Execute(run.ResultCollection); } foreach (var result in resultList) { var indexOfObsMostAbundant = result.IsotopicProfile.GetIndexOfMostIntensePeak(); var mzOfMostAbundant = result.IsotopicProfile.Peaklist[indexOfObsMostAbundant].XValue; var indexOfUnsummedMostAbundantMZ = run.XYData.GetClosestXVal(mzOfMostAbundant); if (indexOfUnsummedMostAbundantMZ >= 0) { result.IsotopicProfile.OriginalIntensity = run.XYData.Yvalues[indexOfUnsummedMostAbundantMZ]; result.IsotopicProfile.IsSaturated = (result.IsotopicProfile.OriginalIntensity >= SaturationThreshold); if (result.IsotopicProfile.IsSaturated) { //problem is that with these saturated profiles, they are often truncated because another //isotopic profile was falsely assigned to the back end of it. So we need to find more peaks that should //belong to the saturated profile. var theorTarget = new PeptideTarget { ChargeState = (short)result.IsotopicProfile.ChargeState, MonoIsotopicMass = result.IsotopicProfile.MonoIsotopicMass }; theorTarget.MZ = (theorTarget.MonoIsotopicMass / theorTarget.ChargeState) + Globals.PROTON_MASS; var averagineFormula = _tomIsotopicPatternGenerator.GetClosestAvnFormula(result.IsotopicProfile.MonoIsotopicMass, false); theorTarget.IsotopicProfile = _tomIsotopicPatternGenerator.GetIsotopePattern(averagineFormula, _tomIsotopicPatternGenerator.aafIsos); theorTarget.EmpiricalFormula = averagineFormula; theorTarget.CalculateMassesForIsotopicProfile(result.IsotopicProfile.ChargeState); AssignMissingPeaksToSaturatedProfile(run.PeakList, result.IsotopicProfile, theorTarget.IsotopicProfile); //goal is to find the index of the isotopic profile peaks of a peak that is not saturated var indexOfGoodUnsaturatedPeak = -1; for (var i = indexOfObsMostAbundant + 1; i < result.IsotopicProfile.Peaklist.Count; i++) { var indexUnsummedData = run.XYData.GetClosestXVal(result.IsotopicProfile.Peaklist[i].XValue); var unsummedIntensity = run.XYData.Yvalues[indexUnsummedData]; if (unsummedIntensity < _minRelIntTheorProfile * SaturationThreshold) { indexOfGoodUnsaturatedPeak = i; break; } } AdjustSaturatedIsotopicProfile(result.IsotopicProfile, theorTarget.IsotopicProfile, indexOfGoodUnsaturatedPeak); } } //double summedIntensity = 0; //foreach (MSPeak peak in result.IsotopicProfile.Peaklist) //{ // int indexOfMZ = result.Run.XYData.GetClosestXVal(peak.XValue); // if (indexOfMZ >= 0) // { // summedIntensity += result.Run.XYData.Yvalues[indexOfMZ]; // } //} //result.IsotopicProfile.OriginalTotalIsotopicAbundance = summedIntensity; } }
public override void Deconvolute(ResultCollection resultList) { float[] xvals = new float[1]; float[] yvals = new float[1]; resultList.Run.XYData.GetXYValuesAsSingles(ref xvals, ref yvals); int sizeOfRapidArray = 10000; int[] chargeResults = new int[sizeOfRapidArray]; double[] intensityResults = new double[sizeOfRapidArray]; double[] mzResults = new double[sizeOfRapidArray]; double[] scoreResults = new double[sizeOfRapidArray]; double[] avgmassResults = new double[sizeOfRapidArray]; double[] massResults = new double[sizeOfRapidArray]; double[] mostAbundantMassResults = new double[sizeOfRapidArray]; if (resultList.Run.PeakList == null || resultList.Run.PeakList.Count == 0) { return; } rapidPeakList = ConvertPeakListToRapidPeakList(resultList.Run.PeakList); if (rapidPeakList == null || rapidPeakList.Length == 0) { return; } double rapidsBackgroundIntensityParameter = (resultList.Run.CurrentBackgroundIntensity * minPeptideToBackgroundRatio); Transformer.PerformTransform_cluster(Convert.ToSingle(rapidsBackgroundIntensityParameter), ref xvals, ref yvals, ref rapidPeakList, ref chargeResults, ref intensityResults, ref mzResults, ref scoreResults, ref avgmassResults, ref massResults, ref mostAbundantMassResults); GenerateResults(resultList, ref chargeResults, ref intensityResults, ref mzResults, ref scoreResults, ref avgmassResults, ref massResults, ref mostAbundantMassResults, this.resultCombiningMode); if (this.IsNewFitCalculationPerformed) { //HACK: RAPID doesn't return the peaks of the isotopic profile. And it's score is meaningless. So will iterate over //the results and 1) get the peaks of the isotopic profile and 2) get a least-squares fit of the isotopic profile. foreach (IsosResult result in resultList.IsosResultBin) { //create a temporary mass tag, as a data object for storing relevent info, and using the CalculateMassesForIsotopicProfile() method. PeptideTarget mt = new PeptideTarget(); mt.ChargeState = (short)result.IsotopicProfile.ChargeState; mt.MonoIsotopicMass = result.IsotopicProfile.MonoIsotopicMass; mt.MZ = (mt.MonoIsotopicMass / mt.ChargeState) + Globals.PROTON_MASS; mt.EmpiricalFormula = _TomIsotopicPatternCreator.GetClosestAvnFormula(result.IsotopicProfile.MonoIsotopicMass, false); mt.IsotopicProfile = _TomIsotopicPatternCreator.GetIsotopePattern(mt.EmpiricalFormula, _TomIsotopicPatternCreator.aafIsos); mt.CalculateMassesForIsotopicProfile(mt.ChargeState); double toleranceInPPM = calcToleranceInPPMFromIsotopicProfile(result.IsotopicProfile); //this finds the isotopic profile based on the theor. isotopic profile. BasicTFF bff = new BasicTFF(toleranceInPPM, false); IsotopicProfile iso = bff.FindMSFeature(resultList.Run.PeakList, mt.IsotopicProfile); if (iso != null && iso.Peaklist != null && iso.Peaklist.Count > 1) { //start at the second peak... and add the newly found peaks for (int i = 1; i < iso.Peaklist.Count; i++) { result.IsotopicProfile.Peaklist.Add(iso.Peaklist[i]); } //now that we have the peaks, we can get info for MonoPlusTwoAbundance result.IsotopicProfile.MonoPlusTwoAbundance = result.IsotopicProfile.GetMonoPlusTwoAbundance(); } XYData theorXYData = mt.IsotopicProfile.GetTheoreticalIsotopicProfileXYData(result.IsotopicProfile.GetFWHM()); //offset the theor isotopic profile offsetDistribution(theorXYData, mt.IsotopicProfile, result.IsotopicProfile); AreaFitter areafitter = new AreaFitter(); int ionCountUsed; double fitval = areafitter.GetFit(theorXYData, result.Run.XYData, 0.1, out ionCountUsed); if (fitval == double.NaN || fitval > 1) { fitval = 1; } result.IsotopicProfile.Score = fitval; } } }