public void PlotAnotatedSpectrum(MSLight msExperimental, double ppm, string peptide) { //Predict the spectrum //Find PTMs List <ModificationItem> mods = SpectraPredictor.GetVMods(peptide); SpectralPredictionParameters spp = new SpectralPredictionParameters(false, true, false, false, true, false, true, true, 2, true, mods); SpectraPredictor sp = new SpectraPredictor(spp); List <PredictedIon> theoreticalSpectrum = sp.PredictPeaks(peptide, 2, 1950, msExperimental, 500); DataGridResultTable.ItemsSource = theoreticalSpectrum; SpectrumEye1.Plot(msExperimental.Ions, msExperimental.Ions[0].MZ, msExperimental.Ions.Last().MZ, ppm, theoreticalSpectrum); }
private void buttonPlot_Click(object sender, RoutedEventArgs e) { Plot(); //Evaluate the spectrum quality PatternTools.SpectraPrediction.SpectralPredictionParameters spm = new SpectralPredictionParameters( true, true, true, true, true, true, false, false, 1, true, Modifications ); PatternTools.SpectraPrediction.SpectraPredictor sp = new SpectraPredictor(spm); List <PredictedIon> theoretical = sp.PredictPeaks(textBoxSequence.Text, ChargeState, TheoreticalMH); List <Ion> filteredList = myMS.FindAll(a => a.Intensity > double.Parse(textBoxRelativeIntensityThreshold.Text)); List <SpectralMatchEvaluator.TheTests> evaluationTests = new List <SpectralMatchEvaluator.TheTests>() { SpectralMatchEvaluator.TheTests.AllTests }; PatternTools.SpectralMatchEvaluator.SpectrumComparisonResult spectrumEvaluationResult = PatternTools.SpectralMatchEvaluator.Compare.Do( evaluationTests, theoretical, filteredList, double.Parse(textBoxPPM.Text), textBoxSequence.Text.Length, RelativeIntensityThreshold ); PatternTools.SpectralMatchEvaluator.Compare.PrintResults(spectrumEvaluationResult); }
/// <summary> /// /// </summary> /// <param name="experimentalIons">List of Ions</param> /// <param name="sMZ">Start M/Z</param> /// <param name="fMZ">Finish M/Z</param> /// <param name="PPM">ppm</param> /// <param name="tIons">TheoreticalIons</param> public void Plot(List <Ion> experimentalIons, double sMZ, double fMZ, double PPM, List <PredictedIon> tIons = null) { if (tIons != null) { //Get a B Series List <PredictedIon> bions = tIons.FindAll(a => a.Series == IonSeries.B && a.Number > -1); bions.Sort((a, b) => a.Number.CompareTo(b.Number)); string peptide = string.Join("", bions.FindAll(b => b.Charge == 1).Select(a => a.FinalAA)); List <Tuple <string, string, string> > anotations = new List <Tuple <string, string, string> >(); List <string> splitPeptide = SpectraPredictor.SplitPeptide(peptide); for (int i = 0; i < splitPeptide.Count; i++) { string a = ""; string b = ""; if (tIons.Exists(x => x.MZ >= sMZ && x.MZ <= fMZ && x.Number == i + 1 && x.Matched && (x.Series == IonSeries.X || x.Series == IonSeries.Y || x.Series == IonSeries.Z))) { a = "y1"; } if (tIons.Exists(x => x.MZ >= sMZ && x.MZ <= fMZ && x.Number == i + 1 && x.Matched && (x.Series == IonSeries.A || x.Series == IonSeries.B || x.Series == IonSeries.C))) { b = "b2"; } anotations.Add(new Tuple <string, string, string>(splitPeptide[i], a, b)); } MySequenceAnotation.Plot(anotations); } ZoomInProcess = false; CanvasPeakDisplay.Children.Clear(); startMZ = sMZ; finishMZ = fMZ; ppm = PPM; theoreticalSpectrum = tIons; //Lets keep the original spectrum if (OriginalIons == null) { OriginalIons = experimentalIons; } IonsInDisplay = experimentalIons.FindAll(a => a.MZ >= startMZ && a.MZ <= finishMZ); if (IonsInDisplay.Count == 0) { //Return to the original spectrum PlotOriginal(); } double maxIntensity = IonsInDisplay.Max(a => a.Intensity); List <Tuple <double, double> > addedPositions = new List <Tuple <double, double> >(); //Used for printing labels in the peaks double minimumHorizonalPixelsBetweenLable = 10; IonsInDisplay.Sort((a, b) => b.Intensity.CompareTo(a.Intensity)); foreach (Ion i in IonsInDisplay) { Line peak = new Line(); peak.Stroke = System.Windows.Media.Brushes.Black; peak.StrokeThickness = 1; double relativeIntensity = Math.Round(i.Intensity / maxIntensity, 3); peak.ToolTip = "M/Z: " + i.MZ + "\n"; peak.ToolTip += "Intensity: " + i.Intensity + "\n"; peak.ToolTip += "Relative Intensity: " + relativeIntensity + "\n"; Tuple <double, double> p = ConvertMZToPixel(i, maxIntensity, startMZ, finishMZ); peak.X1 = 0; peak.X2 = 0; peak.Y1 = 0; peak.Y2 = p.Item2; //Verify if there is a theoretical ion within the ppm tolerance - choose color int matching = -1; if (!object.Equals(theoreticalSpectrum, null)) { matching = theoreticalSpectrum.FindIndex(a => Math.Abs(PatternTools.pTools.PPM(a.MZ, i.MZ)) < ppm); if (matching >= 0) { peak.StrokeThickness = 2; if (theoreticalSpectrum[matching].Series == IonSeries.A || theoreticalSpectrum[matching].Series == IonSeries.B || theoreticalSpectrum[matching].Series == IonSeries.C) { peak.Stroke = System.Windows.Media.Brushes.Red; } if (theoreticalSpectrum[matching].Series == IonSeries.X || theoreticalSpectrum[matching].Series == IonSeries.Y || theoreticalSpectrum[matching].Series == IonSeries.Z) { peak.Stroke = System.Windows.Media.Brushes.Blue; } if (theoreticalSpectrum[matching].FinalAA.Contains("-NH3") || theoreticalSpectrum[matching].FinalAA.Contains("-H20")) { peak.Stroke = System.Windows.Media.Brushes.Green; } peak.ToolTip += "Z : " + theoreticalSpectrum[matching].Charge + "\n"; peak.ToolTip += "Series: " + theoreticalSpectrum[matching].Series + theoreticalSpectrum[matching].Number.ToString() + "\n"; peak.ToolTip += "Sequence Item: " + theoreticalSpectrum[matching].FinalAA; } } Canvas.SetLeft(peak, p.Item1); Canvas.SetBottom(peak, 0); CanvasPeakDisplay.Children.Add(peak); if (relativeIntensity > 0.02) { TextBlock tb = new TextBlock(); tb.HorizontalAlignment = HorizontalAlignment.Center; tb.FontSize = 10; tb.Text = Math.Round(i.MZ, 3).ToString(); if (matching > -1) { tb.Text += "\n" + theoreticalSpectrum[matching].Series + theoreticalSpectrum[matching].Number.ToString(); } tb.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); Rect measureRect = new Rect(tb.DesiredSize); double addedPos = p.Item1 - measureRect.Width / 2; Tuple <double, double> thisRange = new Tuple <double, double>(p.Item1 - measureRect.Width / 2, p.Item1 + measureRect.Width / 2); if (!addedPositions.Exists( a => (Math.Abs(a.Item1 - thisRange.Item1) < minimumHorizonalPixelsBetweenLable) || (Math.Abs(a.Item2 - thisRange.Item2) < minimumHorizonalPixelsBetweenLable) || ((thisRange.Item1 > a.Item1) && (thisRange.Item1 < a.Item2)) || ((thisRange.Item2 > a.Item1)) && (thisRange.Item2 < a.Item2)) ) { CanvasPeakDisplay.Children.Add(tb); Canvas.SetLeft(tb, addedPos); Canvas.SetBottom(tb, p.Item2); addedPositions.Add(thisRange); } } } }