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 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; } } }