public void EasyDecision() { var fileName = @"\\Protoapps\UserData\Slysz\DeconTools_TestFiles\Orbitrap\QC_Shew_08_04-pt5-2_11Jan09_Sphinx_08-11-18.RAW"; //Run run = RunUtilities.CreateAndLoadPeaks(fileName); var run = new RunFactory().CreateRun(fileName); List <IsotopicProfile> potentialFeatures; EasyDecisionSetUp(out potentialFeatures); ChargeStateDecider chargestatedecider = new ChromCorrelatingChargeDecider(run); var msFeature = chargestatedecider.DetermineCorrectIsotopicProfile(potentialFeatures); Assert.AreEqual(msFeature.ChargeState, 2); }
public void MediumDecision() { var fileName = @"C:\Users\Klin638\Documents\BobsFolder\bob.raw"; fileName = @"\\protoapps\UserData\Slysz\DeconTools_TestFiles\Orbitrap\QC_Shew_08_04-pt5-2_11Jan09_Sphinx_08-11-18.raw"; //Run run = RunUtilities.CreateAndLoadPeaks(fileName); var run = new RunFactory().CreateRun(fileName); run.CurrentScanSet = new ScanSet(1000); List <IsotopicProfile> potentialFeatures; MediumDecisionSetup(out potentialFeatures); ChargeStateDecider chargestatedecider = new ChromCorrelatingChargeDecider(run); var msFeature = chargestatedecider.DetermineCorrectIsotopicProfile(potentialFeatures); //Assert something here. }
/// <summary> /// The main Thrash algorithm. /// </summary> /// <param name="originalXYData">Mass spec XY data</param> /// <param name="mspeakList">Mass spec peak data</param> /// <param name="backgroundIntensity"></param> /// <param name="minPeptideIntensity"></param> /// <param name="minMSFeatureToBackgroundRatio"></param> /// <returns>List of isotopic profiles</returns> public List <IsotopicProfile> PerformThrash(XYData originalXYData, List <Peak> mspeakList, double backgroundIntensity = 0, double minPeptideIntensity = 0, double minMSFeatureToBackgroundRatio = 3) { var isotopicProfiles = new List <IsotopicProfile>(); #region Paul Addition var myIsotopicProfiles = new List <IsotopicProfile>(); var otherIsotopicProfiles = new List <IsotopicProfile>(); #endregion if (Parameters.AreAllTheoreticalProfilesCachedBeforeStarting) { CreateAllTheoreticalProfilesForMassRange(); } var minMSFeatureIntensity = backgroundIntensity * minMSFeatureToBackgroundRatio; var xyData = new XYData(); xyData.Xvalues = originalXYData.Xvalues; xyData.Yvalues = originalXYData.Yvalues; var peaksThatWereProcessedInfo = new Dictionary <Peak, bool>(); var sortedPeaklist = new List <Peak>(mspeakList).OrderByDescending(p => p.Height).ToList(); var peaksAlreadyProcessed = new HashSet <Peak>(); var stringBuilder = new StringBuilder(); var listOfMonoMZs = new SortedDictionary <int, double>(); var currentUniqueMSFeatureIDNum = 0; var peakCounter = -1; foreach (var msPeak in sortedPeaklist) { //if (msPeak.XValue > 579.53 && msPeak.XValue < 579.54) //{ // int x = 90; //} var indexOfCurrentPeak = mspeakList.IndexOf(msPeak); if (peaksAlreadyProcessed.Contains(msPeak)) { continue; } var peakIsBelowIntensityThreshold = (msPeak.Height < minMSFeatureIntensity); if (peakIsBelowIntensityThreshold) { break; } peakCounter++; if (peakCounter == 465) { // Console.WriteLine(peakCounter); } //get potential charge states var ppmTolerance = (msPeak.Width / 2.35) / msPeak.XValue * 1e6; // peak's sigma value / mz * 1e6 HashSet <int> potentialChargeStates; // HashSet<int> potentialChargeStatesbyPaul; if (UseAutocorrelationChargeDetermination && false) { var chargeState = PattersonChargeStateCalculator.GetChargeState(xyData, mspeakList, msPeak as MSPeak); potentialChargeStates = new HashSet <int>(); potentialChargeStates.Add(chargeState); } else { //Paul subtraction IqLogger.Log.Debug("MZ value: " + msPeak.XValue + "\n"); potentialChargeStates = GetPotentialChargeStates(indexOfCurrentPeak, mspeakList, ppmTolerance); #region Paul Addition // ChromCorrelatingChargeDecider chargeDecider= new ChromCorrelatingChargeDecider(_run); // potentialChargeStatesbyPaul=chargeDecider.GetPotentialChargeState(indexOfCurrentPeak, mspeakList, ppmTolerance); //potentialChargeStates = potentialChargeStatesbyPaul; #endregion } var reportString201 = "potentialChargeStates: "; foreach (var charge in potentialChargeStates) { reportString201 += charge + "\t"; } IqLogger.Log.Debug(reportString201 + "\n"); var potentialMSFeaturesForGivenChargeState = new List <IsotopicProfile>(); foreach (var potentialChargeState in potentialChargeStates) { var bestFitVal = 1.0; // 1.0 is worst fit value. Start with 1.0 and see if we can find better fit value IsotopicProfile theorIso; //TODO: there could be a problem here var msFeature = GetMSFeature(mspeakList, xyData, potentialChargeState, msPeak, ref bestFitVal, out theorIso); if (msFeature != null) { msFeature.Score = bestFitVal; msFeature.IntensityMostAbundant = msFeature.getMostIntensePeak().Height; var indexMostAbundantPeakTheor = theorIso.GetIndexOfMostIntensePeak(); //Paul edit. "&& indexMostAbundantPeakTheor>=0" if (msFeature.Peaklist.Count > indexMostAbundantPeakTheor && indexMostAbundantPeakTheor >= 0) { msFeature.IntensityMostAbundantTheor = msFeature.Peaklist[indexMostAbundantPeakTheor].Height; } else { msFeature.IntensityMostAbundantTheor = msFeature.IntensityMostAbundant; } var msFeatureAlreadyPresentInAnotherChargeState = listOfMonoMZs.ContainsValue(msFeature.MonoPeakMZ); if (!msFeatureAlreadyPresentInAnotherChargeState) { potentialMSFeaturesForGivenChargeState.Add(msFeature); } else { //Console.WriteLine( "Nope... not using this charge state... MSFeature already found with same MonoMZ. \tcurrent peak= \t" +msPeak.XValue.ToString("0.0000") + "\tmsfeature= " + msFeature); } } } IsotopicProfile msfeature = null;//Paul Addition "=null" if (potentialMSFeaturesForGivenChargeState.Count == 0) { stringBuilder.Append(msPeak.XValue.ToString("0.00000") + "\tNo profile found.\n"); msfeature = null; } else if (potentialMSFeaturesForGivenChargeState.Count == 1) { msfeature = potentialMSFeaturesForGivenChargeState[0]; stringBuilder.Append(msPeak.XValue.ToString("0.00000") + "\t" + msfeature.MonoPeakMZ.ToString("0.0000") + "\t" + msfeature.ChargeState + "\t" + msfeature.Score + "\t" + ppmTolerance + "\n"); } else { stringBuilder.Append("Multiple candidates found...." + "\n"); foreach (var isotopicProfile in potentialMSFeaturesForGivenChargeState) { stringBuilder.Append(msPeak.XValue.ToString("0.00000") + "\t" + isotopicProfile.MonoPeakMZ.ToString("0.0000") + "\t" + isotopicProfile.ChargeState + "\t" + isotopicProfile.Score + "\t" + ppmTolerance + "\n"); } stringBuilder.Append(Environment.NewLine); if (Parameters.CheckAllPatternsAgainstChargeState1) { msfeature = potentialMSFeaturesForGivenChargeState.FirstOrDefault(n => n.ChargeState == 1); } else { #region Paul addition //TODO: [Paul] This is the major means of deciding between charge states and where we need to do better. //We need some test cases to capture this problem. var stopwatch = new Stopwatch(); if (doPaulMethod) { var peaksNotLoaded = _run.ResultCollection.MSPeakResultList == null || _run.ResultCollection.MSPeakResultList.Count == 0; if (peaksNotLoaded)// || !importedFULLPeaks) { stopwatch.Start(); LoadPeaks(_run); //importedFULLPeaks = true; stopwatch.Stop(); IqLogger.Log.Debug("stopwatch: " + stopwatch.Elapsed); } var brain = new ChromCorrelatingChargeDecider(_run); msfeature = brain.DetermineCorrectIsotopicProfile(potentialMSFeaturesForGivenChargeState.Where(n => n.Score < .50).ToList()); //if (msfeature==null) //{ // msfeature = brain.DetermineCorrectIsotopicProfile(potentialMSFeaturesForGivenChargeState); //} //hitcounter2++; } else//do it the regular way. { #endregion msfeature = (from n in potentialMSFeaturesForGivenChargeState where n.Score < 0.15 orderby n.ChargeState descending select n).FirstOrDefault(); if (msfeature == null) { msfeature = (from n in potentialMSFeaturesForGivenChargeState orderby n.Score select n).First(); } #region Paul Addition } //line outputs. if (null != msfeature) { var reportString309 = "\nM/Z = " + msfeature.MonoPeakMZ + "\nCHOSEN CHARGE: " + msfeature.ChargeState + "\n\n"; IqLogger.Log.Debug(reportString309); //tabular output //string reportString309 = "\tM/Z = \t" + msfeature.MonoPeakMZ + // "\tCHOSEN CHARGE: \t" + msfeature.ChargeState+ "\n"; //IqLogger.Log.Debug(reportString309); } #endregion } } if (msfeature != null) { listOfMonoMZs.Add(currentUniqueMSFeatureIDNum, msfeature.MonoPeakMZ); currentUniqueMSFeatureIDNum++; isotopicProfiles.Add(msfeature); //hitcounter++;//Paul Addition foreach (var peak in msfeature.Peaklist) { //For debugging //if (peak.XValue > 534.76515 && peak.XValue < 534.78515) //(peak.XValue>579.62 && peak.XValue<579.65) || (peak.XValue>579.75 && peak.XValue<579.8)) //{ // int x = 39843; //} peaksAlreadyProcessed.Add(peak); } } }//end of foreach peak loop //Console.WriteLine(stringBuilder.ToString()); var uniqueIsotopicProfiles = removeDuplicatesFromFoundMSFeatures(isotopicProfiles); #region Paul Addition //IqLogger.Log.Debug("Hit counter: " + hitcounter); //IqLogger.Log.Debug("Hit counter2: " + hitcounter2); //var uniqueOtherIsotopicProfiles = removeDuplicatesFromFoundMSFeatures(isotopicProfiles); //IqLogger.Log.Debug("old non unique count: " + otherIsotopicProfiles.Count + "\n" + // "new non unique count: " + myIsotopicProfiles.Count + "\n"); //var uniqueMyIsotopicProfiles = removeDuplicatesFromFoundMSFeatures(myIsotopicProfiles); //IqLogger.Log.Debug("\nOld unique profile count: " + uniqueOtherIsotopicProfiles.Count + "\n" + // "New unique profile count: " + uniqueMyIsotopicProfiles.Count); //IqLogger.Log.Debug("\nunique profile count: " + uniqueIsotopicProfiles.Count + "\n"); #endregion //NOTE: we don't need to do the reordering, but I do this so I can compare to the old THRASH uniqueIsotopicProfiles = uniqueIsotopicProfiles.OrderByDescending(p => p.IntensityMostAbundantTheor).ToList(); return(uniqueIsotopicProfiles); }