Example #1
0
        public void DisplaySpectrumMatch(PlotView plotView, Canvas canvas, PsmFromTsv psm, ParentChildScanPlotsView parentChildScanPlotsView, out List <string> errors)
        {
            errors = null;

            // clear old parent/child scans
            parentChildScanPlotsView.Plots.Clear();
            CurrentlyDisplayedPlots.Clear();

            // get the scan
            if (!MsDataFiles.TryGetValue(psm.FileNameWithoutExtension, out DynamicDataConnection spectraFile))
            {
                errors = new List <string>();
                errors.Add("The spectra file could not be found for this PSM: " + psm.FileNameWithoutExtension);
                return;
            }

            MsDataScan scan = spectraFile.GetOneBasedScanFromDynamicConnection(psm.Ms2ScanNumber);

            LibrarySpectrum librarySpectrum = null;

            // plot the annotated spectrum match
            PeptideSpectrumMatchPlot plot;

            //if not crosslinked
            if (psm.BetaPeptideBaseSequence == null)
            {
                // get the library spectrum if relevant
                if (SpectralLibrary != null)
                {
                    SpectralLibrary.TryGetSpectrum(psm.FullSequence, psm.PrecursorCharge, out var librarySpectrum1);
                    librarySpectrum = librarySpectrum1;
                }

                plot = new PeptideSpectrumMatchPlot(plotView, canvas, psm, scan, psm.MatchedIons, librarySpectrum: librarySpectrum);
            }
            else //crosslinked
            {
                plot = new CrosslinkSpectrumMatchPlot(plotView, canvas, psm, scan);
            }

            CurrentlyDisplayedPlots.Add(plot);

            // plot parent/child scans
            if (psm.ChildScanMatchedIons != null)
            {
                // draw parent scan
                string parentAnnotation = "Scan: " + scan.OneBasedScanNumber
                                          + " Dissociation Type: " + scan.DissociationType
                                          + " MsOrder: " + scan.MsnOrder
                                          + " Selected Mz: " + scan.SelectedIonMZ.Value.ToString("0.##")
                                          + " Retention Time: " + scan.RetentionTime.ToString("0.##");

                var parentPlotView = new PlotView(); // placeholder
                var parentCanvas   = new Canvas();
                var item           = new ParentChildScanPlotTemplate()
                {
                    Plot          = new PeptideSpectrumMatchPlot(parentPlotView, parentCanvas, psm, scan, psm.MatchedIons),
                    SpectrumLabel = parentAnnotation,
                    TheCanvas     = parentCanvas
                };

                parentChildScanPlotsView.Plots.Add(item);

                // remove model from placeholder (the model can only be referenced by 1 plotview at a time)
                parentPlotView.Model = null;

                // draw child scans
                HashSet <int> scansDrawn = new HashSet <int>();
                var           allChildScanMatchedIons = psm.ChildScanMatchedIons;

                if (psm.BetaPeptideChildScanMatchedIons != null)
                {
                    allChildScanMatchedIons = allChildScanMatchedIons.Concat(psm.BetaPeptideChildScanMatchedIons)
                                              .GroupBy(p => p.Key)
                                              .ToDictionary(p => p.Key, q => q.SelectMany(p => p.Value).ToList());
                }

                foreach (var childScanMatchedIons in allChildScanMatchedIons)
                {
                    int childScanNumber = childScanMatchedIons.Key;

                    if (scansDrawn.Contains(childScanNumber))
                    {
                        continue;
                    }

                    scansDrawn.Add(childScanNumber);

                    List <MatchedFragmentIon> matchedIons = childScanMatchedIons.Value;

                    MsDataScan childScan = spectraFile.GetOneBasedScanFromDynamicConnection(childScanNumber);

                    string childAnnotation = "Scan: " + childScan.OneBasedScanNumber
                                             + " Dissociation Type: " + childScan.DissociationType
                                             + " MsOrder: " + childScan.MsnOrder
                                             + " Selected Mz: " + childScan.SelectedIonMZ.Value.ToString("0.##")
                                             + " RetentionTime: " + childScan.RetentionTime.ToString("0.##");

                    Canvas   childCanvas   = new Canvas();
                    PlotView childPlotView = new PlotView(); // placeholder

                    // make the plot
                    var childPlot = new PeptideSpectrumMatchPlot(childPlotView, childCanvas, psm, childScan, matchedIons, annotateProperties: false);
                    childPlot.Model.Title    = null;
                    childPlot.Model.Subtitle = null;

                    item = new ParentChildScanPlotTemplate()
                    {
                        Plot = childPlot, SpectrumLabel = childAnnotation, TheCanvas = childCanvas
                    };

                    // remove model from placeholder (the model can only be referenced by 1 plotview at a time)
                    childPlotView.Model = null;

                    parentChildScanPlotsView.Plots.Add(item);

                    CurrentlyDisplayedPlots.Add(childPlot);
                }
            }
        }
        public PeptideSpectrumMatchPlot(OxyPlot.Wpf.PlotView plotView, Canvas sequenceDrawingCanvas, PsmFromTsv psm, MsDataScan scan,
                                        List <MatchedFragmentIon> matchedFragmentIons, bool annotateProperties = true, LibrarySpectrum librarySpectrum = null) : base(plotView)
        {
            Model.Title                  = string.Empty;
            Model.Subtitle               = string.Empty;
            SpectrumMatch                = psm;
            Scan                         = scan;
            SequenceDrawingCanvas        = sequenceDrawingCanvas;
            SequenceDrawingCanvas.Height = 60;
            sequenceDrawingCanvas.Width  = 600;

            ClearCanvas(SequenceDrawingCanvas);
            DrawSpectrum();
            AnnotateBaseSequence(psm.BaseSeq, psm.FullSequence, 10, matchedFragmentIons);
            AnnotateMatchedIons(isBetaPeptide: false, matchedFragmentIons);

            if (annotateProperties)
            {
                AnnotateProperties();
            }

            ZoomAxes(matchedFragmentIons);

            if (librarySpectrum != null)
            {
                AnnotateLibraryIons(isBetaPeptide: false, librarySpectrum.MatchedFragmentIons);
            }

            RefreshChart();
        }