private void FinishCalculation() { double totalArea = _peaks.Values.Sum(p => p.Area); double tracerPercent = 0; double totalScore = 0; var tracerChromatograms = GetTracerChromatograms(); foreach (var entry in _peaks.ToArray()) { var peak = entry.Value; peak.RelativeAmount = totalArea == 0 ? 0 : peak.Area / totalArea; tracerPercent += peak.RelativeAmount * peak.TracerPercent; totalScore += peak.Area * tracerChromatograms.GetScore( tracerChromatograms.ChromatogramSet.IndexFromTime(peak.StartTime), tracerChromatograms.ChromatogramSet.IndexFromTime(peak.EndTime)); _peaks[entry.Key] = peak; } TracerPercent = tracerPercent; DeconvolutionScore = totalArea == 0 ? 0 : totalScore / totalArea; IDictionary <TracerFormula, double> bestMatch; var peaksDict = ToDictionary(); double turnover; double turnoverScore; PrecursorEnrichmentFormula = PeptideAnalysis.GetTurnoverCalculator().ComputePrecursorEnrichmentAndTurnover(peaksDict, out turnover, out turnoverScore, out bestMatch); if (PrecursorEnrichmentFormula != null) { PrecursorEnrichment = PrecursorEnrichmentFormula.Values.Sum() / 100.0; Turnover = turnover; TurnoverScore = turnoverScore; } }
public TracerChromatograms(PeptideFileAnalysis peptideFileAnalysis, ChromatogramSetData chromatogramSet, bool smoothed) { Smoothed = smoothed; ChromatogramSet = chromatogramSet; PeptideFileAnalysis = peptideFileAnalysis; var pointDict = new Dictionary <TracerFormula, IList <double> >(); var chromatogramsDict = new Dictionary <MzKey, IList <double> >(); var turnoverCalculator = PeptideAnalysis.GetTurnoverCalculator(); double massAccuracy = PeptideAnalysis.GetMassAccuracy(); foreach (var chromatogramEntry in ChromatogramSet.Chromatograms) { if (PeptideAnalysis.ExcludedMasses.Contains(chromatogramEntry.Key.MassIndex)) { continue; } var chromatogram = chromatogramEntry.Value; var mzRange = turnoverCalculator.GetMzs(chromatogramEntry.Key.Charge)[chromatogramEntry.Key.MassIndex]; var intensities = chromatogram.ChromatogramPoints.Select(point => point.GetIntensity(mzRange, massAccuracy)).ToArray(); if (smoothed) { intensities = SavitzkyGolaySmooth(intensities); } chromatogramsDict.Add(chromatogramEntry.Key, intensities); } int massCount = PeptideFileAnalysis.PeptideAnalysis.GetMassCount(); var times = chromatogramSet.Times.ToArray(); var scores = new List <double>(); var tracerFormulas = turnoverCalculator.ListTracerFormulas(); var theoreticalIntensities = turnoverCalculator.GetTheoreticalIntensities(tracerFormulas); for (int i = 0; i < times.Length; i++) { var intensities = new List <double>(); for (int iMass = 0; iMass < massCount; iMass++) { double intensity = 0; for (int charge = PeptideAnalysis.MinCharge; charge <= PeptideAnalysis.MaxCharge; charge++) { IList <double> chromatogram; if (chromatogramsDict.TryGetValue(new MzKey(charge, iMass), out chromatogram)) { intensity += chromatogram[i]; } else { intensity = double.NaN; } } intensities.Add(intensity); } double score; IDictionary <TracerFormula, IList <double> > predictedIntensities; PeptideAnalysis.GetTurnoverCalculator().GetTracerAmounts(intensities, out score, out predictedIntensities, tracerFormulas, theoreticalIntensities); foreach (var entry in predictedIntensities) { IList <double> list; if (!pointDict.TryGetValue(entry.Key, out list)) { list = new List <double>(); pointDict.Add(entry.Key, list); } list.Add(entry.Value.Sum()); } scores.Add(score); } var points = new SortedDictionary <TracerFormula, IList <double> >(); var peaks = new Dictionary <TracerFormula, IList <CrawdadPeak> >(); foreach (var entry in pointDict) { points.Add(entry.Key, entry.Value); CrawPeakFinderWrapper peakFinder = new CrawPeakFinderWrapper(); peakFinder.SetChromatogram(times, entry.Value); peaks.Add(entry.Key, peakFinder.CalcPeaks(MaxPeaks)); } Points = points; Scores = scores; Times = chromatogramSet.Times; RawPeaks = peaks; }