/// <summary> /// Build the isotope plot showing theoretical isotopic profile and /// actual isotopic profile. /// </summary> /// <param name="theoretical">Actual isotopic profile.</param> /// <param name="observed">Actual isotopic profile.</param> /// <param name="isProfile">A value indicating whether the peak list is profile mode.</param> public void BuildPlot(PeakDataPoint[] theoretical, PeakDataPoint[] observed, bool isProfile) { PlotModel.Series.Clear(); // Create series for theoretical isotope profile var theoSeries = new PeakPointSeries { Title = "Theoretical", ItemsSource = theoretical, Color = OxyColor.FromArgb(120, 0, 0, 0), StrokeThickness = 3.0, TrackerFormatString = "{0}" + Environment.NewLine + "{1}: {2:0.###}" + Environment.NewLine + "{3}: {4:0.###}" + Environment.NewLine + "Index: {Index:0.###}" }; PlotModel.Series.Add(theoSeries); if (isProfile) { // Create series for actual isotope profile var actSeries = new ProfilePeakPointSeries { Title = "Observed", ItemsSource = observed, Color = OxyColor.FromArgb(120, 255, 0, 0), StrokeThickness = 1.0, TrackerFormatString = "{0}" + Environment.NewLine + "{1}: {2:0.###}" + Environment.NewLine + "{3}: {4:0.###}" + Environment.NewLine + "Index: {Index:0.###}" }; PlotModel.Series.Add(actSeries); } else { // Create series for actual isotope profile var actSeries = new PeakPointSeries { Title = "Observed", ItemsSource = observed, Color = OxyColor.FromArgb(120, 255, 0, 0), StrokeThickness = 3.0, TrackerFormatString = "{0}" + Environment.NewLine + "{1}: {2:0.###}" + Environment.NewLine + "{3}: {4:0.###}" + Environment.NewLine + "Index: {Index:0.###}" }; PlotModel.Series.Add(actSeries); } // Calculate min and max boundaries for plot var min = theoretical.Min(p => p.X); var max = theoretical.Max(p => p.X); min -= (max - min) / 3; var absMin = Math.Max(0, min - 10); max += (max - min) / 3; var absMax = max + 10; xaxis.Minimum = min; xaxis.AbsoluteMinimum = absMin; xaxis.Maximum = max; xaxis.AbsoluteMaximum = absMax; xaxis.Zoom(min, max); PlotModel.IsLegendVisible = true; PlotModel.InvalidatePlot(true); PlotModel.AdjustForZoom(); }
/// <summary> /// Build spectrum plot model. /// </summary> /// <param name="peakDataPoints">Ion peaks to highlight and annotate on spectrum plot.</param> private void UpdatePlotModel(IList <PeakDataPoint>[] peakDataPoints) { if (this.Spectrum == null) { return; } this.errorMapViewModel.SetData(this.FragmentationSequenceViewModel.FragmentationSequence.Sequence, peakDataPoints); this.PlotModel.Series.Clear(); this.PlotModel.Annotations.Clear(); this.currentSpectrum = this.GetSpectrum(); this.peakDataPoints = peakDataPoints; var spectrumPeaks = currentSpectrum.Peaks.Select(peak => new PeakDataPoint(peak.Mz, peak.Intensity, 0.0, 0.0, string.Empty)); var spectrumSeries = new PeakPointSeries { ItemsSource = spectrumPeaks, Color = OxyColors.Black, StrokeThickness = 0.5, TrackerFormatString = "{0}" + Environment.NewLine + "{1}: {2:0.###}" + Environment.NewLine + "{3}: {4:0.##E0}" }; if (this.ShowUnexplainedPeaks) { this.PlotModel.Series.Add(spectrumSeries); } if (this.autoZoomXAxis && this.spectrumDirty) { // zoom spectrum if this plot is supposed to be auto zoomed, and only if spectrum has changed var peaks = currentSpectrum.Peaks; var ms2MaxMz = 1.0; // plot maximum needs to be bigger than 0 if (peaks.Length > 0) { ms2MaxMz = peaks.Max().Mz * 1.1; } this.XAxis.AbsoluteMinimum = 0; this.XAxis.AbsoluteMaximum = ms2MaxMz; this.XAxis.Zoom(0, ms2MaxMz); this.spectrumDirty = false; } var maxCharge = peakDataPoints.Length > 0 ? this.ions.Max(x => x.IonType.Charge) : 2; maxCharge = Math.Max(maxCharge, 2); var colors = new IonColorDictionary(maxCharge); foreach (var points in peakDataPoints) { if (points.Count == 0 || points[0].Error.Equals(double.NaN)) { continue; } var firstPoint = points[0]; var color = firstPoint.IonType != null?colors.GetColor(firstPoint.IonType.BaseIonType, firstPoint.IonType.Charge) : colors.GetColor(firstPoint.Index); var ionSeries = new PeakPointSeries { Color = color, StrokeThickness = 1.5, ItemsSource = points, Title = points[0].Title, TrackerFormatString = "{0}" + Environment.NewLine + "{1}: {2:0.###}" + Environment.NewLine + "{3}: {4:0.##E0}" + Environment.NewLine + "Error: {Error:G4}ppm" + Environment.NewLine + "Correlation: {Correlation:0.###}" }; // Create ion name annotation var annotationName = points[0].Title.Contains("Precursor") ? string.Format("{0}\n{1,12:F3}", points[0].Title, points[0].X) : points[0].Title; var annotation = new TextAnnotation { Text = annotationName, TextColor = color, FontWeight = FontWeights.Bold, Layer = AnnotationLayer.AboveSeries, FontSize = 12, Background = OxyColors.White, Padding = new OxyThickness(0.1), TextPosition = new DataPoint(points[0].X, points[0].Y), TextHorizontalAlignment = HorizontalAlignment.Center, StrokeThickness = 0 }; this.PlotModel.Series.Add(ionSeries); this.PlotModel.Annotations.Add(annotation); } this.PlotModel.Title = this.Title; this.PlotModel.InvalidatePlot(true); this.PlotModel.AdjustForZoom(); }
private PlotModel GetPlotModel(PrSm id) { var lcms = id.LcMs; var fragSequence = id.GetFragmentationSequence(); var msLevel = lcms.GetMsLevel(id.Scan); var fragments = msLevel == 2 ? fragSequence.GetFragmentLabels(ionTypes.Where(ionType => ionType.Charge <= id.Charge).ToList()) : fragSequence.GetChargePrecursorLabels(); var spectrum = lcms.GetSpectrum(id.Scan, true); // Set up plot var plotModel = new PlotModel { Title = msLevel == 2 ? string.Format("MS/MS Scan {0}", id.Scan) : string.Format("MS Scan {0}", id.Scan), IsLegendVisible = false, }; // Add axes var xaxis = new LinearAxis { Title = "M/Z", Position = AxisPosition.Bottom }; var yaxis = new LinearAxis { Title = "Intensity", Position = AxisPosition.Left, Minimum = 0 }; plotModel.Axes.Add(xaxis); plotModel.Axes.Add(yaxis); // Add spectrum peaks var spectrumPeaks = spectrum.Peaks.Select(peak => new PeakDataPoint(peak.Mz, peak.Intensity, 0.0, 0.0, string.Empty)); var spectrumStemSeries = new StemSeries { ItemsSource = spectrumPeaks, Color = OxyColors.Black, StrokeThickness = 0.5, }; plotModel.Series.Add(spectrumStemSeries); // Add ion highlights var colors = new IonColorDictionary(id.Charge); foreach (var fragment in fragments) { var points = fragment.GetPeaks(spectrum, false, false); if (points.Count == 0 || points[0].Error.Equals(double.NaN)) { continue; } var firstPoint = points[0]; var color = firstPoint.IonType != null?colors.GetColor(firstPoint.IonType.BaseIonType, firstPoint.IonType.Charge) : colors.GetColor(firstPoint.Index); var ionSeries = new PeakPointSeries { Color = color, StrokeThickness = 1.5, ItemsSource = points, Title = points[0].Title, }; // Create ion name annotation var annotation = new TextAnnotation { Text = points[0].Title, TextColor = color, FontWeight = FontWeights.Bold, Layer = AnnotationLayer.AboveSeries, FontSize = 12, Background = OxyColors.White, Padding = new OxyThickness(0.1), TextPosition = new DataPoint(points[0].X, points[0].Y), StrokeThickness = 0 }; plotModel.Series.Add(ionSeries); plotModel.Annotations.Add(annotation); } return(plotModel); }