Example #1
0
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            string txt = (sender as TextBox).Text;

            MetaDrawLogic.FilterPsmsByString(txt);
        }
Example #2
0
        public static void MetaDraw_XlSearchTaskWithChildScansTest()
        {
            string outputFolder    = Path.Combine(TestContext.CurrentContext.TestDirectory, @"MetaDraw_XlSearchTaskTest");
            string proteinDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"XlTestData\BSA.fasta");
            string spectraFile     = Path.Combine(TestContext.CurrentContext.TestDirectory, @"XlTestData\ms2mixed_bsa_xlink.mzML");

            // run task
            CommonParameters commonParameters = new CommonParameters(dissociationType: DissociationType.CID, ms2childScanDissociationType: DissociationType.ETD,
                                                                     trimMsMsPeaks: false);

            Directory.CreateDirectory(outputFolder);
            var xlSearchTask = new XLSearchTask()
            {
                CommonParameters = commonParameters
            };

            xlSearchTask.RunTask(outputFolder, new List <DbForTask> {
                new DbForTask(proteinDatabase, false)
            }, new List <string> {
                spectraFile
            }, "");

            //TODO: test other files (XL_Interlinks.tsv, Deadends.tsv, Looplinks.tsv, SinglePeptides.tsv)
            var csmFile = Path.Combine(outputFolder, @"XL_Intralinks.tsv");

            // load results into metadraw
            var metadrawLogic = new MetaDrawLogic();

            metadrawLogic.SpectraFilePaths.Add(spectraFile);
            metadrawLogic.PsmResultFilePaths.Add(csmFile);
            var errors = metadrawLogic.LoadFiles(true, true);

            Assert.That(!errors.Any());
            Assert.That(metadrawLogic.FilteredListOfPsms.Any());

            // test results filter
            MetaDrawSettings.QValueFilter = 0.01;
            MetaDrawSettings.ShowDecoys   = false;
            metadrawLogic.FilterPsms();
            Assert.That(metadrawLogic.FilteredListOfPsms.All(p => p.DecoyContamTarget == "T"));
            Assert.That(metadrawLogic.FilteredListOfPsms.All(p => p.QValue <= 0.01));

            // test text search filter (filter by full sequence)
            string filterString = @"SLGKVGTR";

            metadrawLogic.FilterPsmsByString(filterString);

            int c = 0;

            foreach (var filteredPsm in metadrawLogic.PeptideSpectralMatchesView)
            {
                var psmObj = (PsmFromTsv)filteredPsm;
                Assert.That(psmObj.FullSequence.Contains(filterString));
                c++;
            }
            Assert.That(c > 0);

            // test text search filter (filter by MS2 scan number)
            filterString = @"2";
            metadrawLogic.FilterPsmsByString(filterString);

            c = 0;
            foreach (var filteredPsm in metadrawLogic.PeptideSpectralMatchesView)
            {
                var psmObj = (PsmFromTsv)filteredPsm;
                Assert.That(psmObj.Ms2ScanNumber.ToString().Contains(filterString));
                c++;
            }
            Assert.That(c > 0);

            // draw PSM
            var plotView        = new OxyPlot.Wpf.PlotView();
            var canvas          = new Canvas();
            var parentChildView = new ParentChildScanPlotsView();
            var csm             = metadrawLogic.FilteredListOfPsms.First();

            metadrawLogic.DisplaySpectrumMatch(plotView, canvas, csm, parentChildView, out errors);
            Assert.That(errors == null || !errors.Any());

            // test that plot was drawn
            var peak       = (LineSeries)plotView.Model.Series[0]; // the first m/z peak
            var peakPoints = peak.Points;

            Assert.That(Math.Round(peakPoints[0].X, 2) == 142.12); // m/z
            Assert.That(Math.Round(peakPoints[1].X, 2) == 142.12);
            Assert.That((int)peakPoints[0].Y == 0);                // intensity
            Assert.That((int)peakPoints[1].Y == 1114);

            var plotAxes = plotView.Model.Axes;

            Assert.That(plotAxes.Count == 2);

            // test that base sequence annotation was drawn
            Assert.That(canvas.Children.Count > 0);

            // test that the plots were drawn in the parent/child view
            Assert.That(parentChildView.Plots.Count == 2);

            // test parent scan
            var parentPlot = parentChildView.Plots[0];

            Assert.That(parentPlot.SpectrumLabel == "Scan: 2 Dissociation Type: CID MsOrder: 2 Selected Mz: 492.02 Retention Time: 23.9");
            int numAnnotatedResidues = csm.BaseSeq.Length;
            int numAnnotatedIons     = csm.MatchedIons.Count(p => p.NeutralTheoreticalProduct.ProductType != ProductType.M);
            int numAnnotatedMods     = csm.FullSequence.Count(p => p == '[');

            Assert.That(parentPlot.TheCanvas.Children.Count == numAnnotatedResidues + numAnnotatedIons + numAnnotatedMods);

            peak       = (LineSeries)parentPlot.Plot.Model.Series[0]; // the first m/z peak
            peakPoints = peak.Points;
            Assert.That(Math.Round(peakPoints[0].X, 2) == 142.12);    // m/z
            Assert.That(Math.Round(peakPoints[1].X, 2) == 142.12);
            Assert.That((int)peakPoints[0].Y == 0);                   // intensity
            Assert.That((int)peakPoints[1].Y == 1114);

            // test child scan
            var childPlot = parentChildView.Plots[1];

            Assert.That(childPlot.SpectrumLabel == "Scan: 3 Dissociation Type: ETD MsOrder: 2 Selected Mz: 492.02 RetentionTime: 23.9");
            Assert.That(childPlot.TheCanvas.Children.Count > 0);
            numAnnotatedResidues = csm.BaseSeq.Length;
            numAnnotatedIons     = csm.ChildScanMatchedIons[3].Concat(csm.BetaPeptideChildScanMatchedIons[3])
                                   .Count(p => p.NeutralTheoreticalProduct.ProductType != ProductType.M);
            numAnnotatedMods = csm.FullSequence.Count(p => p == '[');
            Assert.That(childPlot.TheCanvas.Children.Count == numAnnotatedResidues + numAnnotatedIons + numAnnotatedMods);

            peak       = (LineSeries)childPlot.Plot.Model.Series[0]; // the first m/z peak
            peakPoints = peak.Points;
            Assert.That(Math.Round(peakPoints[0].X, 2) == 122.92);   // m/z
            Assert.That(Math.Round(peakPoints[1].X, 2) == 122.92);
            Assert.That((int)peakPoints[0].Y == 0);                  // intensity
            Assert.That((int)peakPoints[1].Y == 857);

            // write pdf
            var psmsToExport = metadrawLogic.FilteredListOfPsms.Where(p => p.FullSequence == "SLGKVGTR(4)").ToList();

            metadrawLogic.ExportToPdf(plotView, canvas, psmsToExport, parentChildView, outputFolder, out errors);

            // test that pdf exists
            Assert.That(File.Exists(Path.Combine(outputFolder, @"2_SLGKVGTR(4).pdf"))); // parent scan
            Assert.That(File.Exists(Path.Combine(outputFolder, @"3_SLGKVGTR(4).pdf"))); // child scan

            // clean up resources
            metadrawLogic.CleanUpResources();
            Assert.That(!metadrawLogic.FilteredListOfPsms.Any());
            Assert.That(!metadrawLogic.PsmResultFilePaths.Any());
            Assert.That(!metadrawLogic.SpectraFilePaths.Any());

            // delete output
            Directory.Delete(outputFolder, true);
        }
Example #3
0
        public static void MetaDraw_GlycoSearchTaskWithChildScansTest()
        {
            string outputFolder    = Path.Combine(TestContext.CurrentContext.TestDirectory, @"MetaDraw_GlycoSearchTaskTest");
            string proteinDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"GlycoTestData\leukosialin.fasta");
            string spectraFile     = Path.Combine(TestContext.CurrentContext.TestDirectory, @"GlycoTestData\sliced_glyco_hcd_ethcd.raw");

            // run task
            CommonParameters commonParameters = new CommonParameters(dissociationType: DissociationType.HCD, ms2childScanDissociationType: DissociationType.EThcD);

            Directory.CreateDirectory(outputFolder);
            var glycoSearchTask = new GlycoSearchTask()
            {
                CommonParameters = commonParameters
            };

            glycoSearchTask.RunTask(outputFolder, new List <DbForTask> {
                new DbForTask(proteinDatabase, false)
            }, new List <string> {
                spectraFile
            }, "");

            var psmFile = Path.Combine(outputFolder, @"oglyco.psmtsv");

            // load results into metadraw
            var metadrawLogic = new MetaDrawLogic();

            metadrawLogic.SpectraFilePaths.Add(spectraFile);
            metadrawLogic.PsmResultFilePaths.Add(psmFile);
            var errors = metadrawLogic.LoadFiles(true, true);

            Assert.That(!errors.Any());
            Assert.That(metadrawLogic.FilteredListOfPsms.Any());

            // test results filter
            MetaDrawSettings.QValueFilter = 0.01;
            MetaDrawSettings.ShowDecoys   = false;
            metadrawLogic.FilterPsms();
            Assert.That(metadrawLogic.FilteredListOfPsms.All(p => p.DecoyContamTarget == "T"));
            Assert.That(metadrawLogic.FilteredListOfPsms.All(p => p.QValue <= 0.01));

            // test text search filter (filter by full sequence)
            string filterString = @"STTAVQ";

            metadrawLogic.FilterPsmsByString(filterString);

            int c = 0;

            foreach (var filteredPsm in metadrawLogic.PeptideSpectralMatchesView)
            {
                var psmObj = (PsmFromTsv)filteredPsm;
                Assert.That(psmObj.FullSequence.Contains(filterString));
                c++;
            }
            Assert.Greater(c, 0);

            // test text search filter (filter by MS2 scan number)
            filterString = @"2";
            metadrawLogic.FilterPsmsByString(filterString);

            c = 0;
            foreach (var filteredPsm in metadrawLogic.PeptideSpectralMatchesView)
            {
                var psmObj = (PsmFromTsv)filteredPsm;
                Assert.That(psmObj.Ms2ScanNumber.ToString().Contains(filterString));
                c++;
            }
            Assert.Greater(c, 0);

            // draw PSM
            var plotView        = new OxyPlot.Wpf.PlotView();
            var canvas          = new Canvas();
            var parentChildView = new ParentChildScanPlotsView();
            var psm             = metadrawLogic.FilteredListOfPsms.First();

            metadrawLogic.DisplaySpectrumMatch(plotView, canvas, psm, parentChildView, out errors);
            Assert.That(errors == null || !errors.Any());

            // test that plot was drawn
            var peak       = (LineSeries)plotView.Model.Series[0]; // the first m/z peak
            var peakPoints = peak.Points;

            Assert.That(Math.Round(peakPoints[0].X, 2) == 101.07); // m/z
            Assert.That(Math.Round(peakPoints[1].X, 2) == 101.07);
            Assert.That((int)peakPoints[0].Y == 0);                // intensity
            Assert.That((int)peakPoints[1].Y == 3847);

            var plotAxes = plotView.Model.Axes;

            Assert.AreEqual(2, plotAxes.Count);

            // test that base sequence annotation was drawn
            Assert.Greater(canvas.Children.Count, 0);

            // test that the plots were drawn in the parent/child view
            Assert.AreEqual(2, parentChildView.Plots.Count);

            // test parent scan
            var parentPlot = parentChildView.Plots[0];

            Assert.AreEqual("Scan: 27 Dissociation Type: HCD MsOrder: 2 Selected Mz: 924.12 Retention Time: 32.65", parentPlot.SpectrumLabel);
            int numAnnotatedResidues = psm.BaseSeq.Length;
            int numAnnotatedIons     = psm.MatchedIons.Count(p => p.NeutralTheoreticalProduct.ProductType != ProductType.M &&
                                                             p.NeutralTheoreticalProduct.ProductType != ProductType.D);
            int numAnnotatedMods = psm.FullSequence.Count(p => p == '[');

            Assert.AreEqual(numAnnotatedResidues + numAnnotatedIons + numAnnotatedMods, parentPlot.TheCanvas.Children.Count);

            peak       = (LineSeries)parentPlot.Plot.Model.Series[0]; // the first m/z peak
            peakPoints = peak.Points;
            Assert.AreEqual(101.07, Math.Round(peakPoints[0].X, 2));  // m/z
            Assert.AreEqual(101.07, (Math.Round(peakPoints[1].X, 2)));
            Assert.AreEqual(0, (int)peakPoints[0].Y);                 // intensity
            Assert.AreEqual(3847, (int)peakPoints[1].Y);

            // test child scan
            var childPlot = parentChildView.Plots[1];

            Assert.AreEqual("Scan: 30 Dissociation Type: EThcD MsOrder: 2 Selected Mz: 924.12 RetentionTime: 32.66",
                            childPlot.SpectrumLabel);
            Assert.Greater(childPlot.TheCanvas.Children.Count, 0);
            numAnnotatedResidues = psm.BaseSeq.Length;
            numAnnotatedIons     = psm.ChildScanMatchedIons[30]
                                   .Count(p => p.NeutralTheoreticalProduct.ProductType != ProductType.M &&
                                          p.NeutralTheoreticalProduct.ProductType != ProductType.D);
            numAnnotatedMods = psm.FullSequence.Count(p => p == '[');
            Assert.AreEqual(numAnnotatedResidues + numAnnotatedIons + numAnnotatedMods, childPlot.TheCanvas.Children.Count);

            peak       = (LineSeries)childPlot.Plot.Model.Series[0]; // the first m/z peak
            peakPoints = peak.Points;
            Assert.AreEqual(126.06, Math.Round(peakPoints[0].X, 2)); // m/z
            Assert.AreEqual(126.06, Math.Round(peakPoints[1].X, 2));
            Assert.AreEqual(0, (int)peakPoints[0].Y);                // intensity
            Assert.AreEqual(8496, (int)peakPoints[1].Y);

            // write pdf
            var psmsToExport = metadrawLogic.FilteredListOfPsms.Where(p => p.FullSequence == "STTAVQTPTSGEPLVST[O-Glycosylation:H1N1 on X]SEPLSSK").ToList();

            metadrawLogic.ExportToPdf(plotView, canvas, psmsToExport, parentChildView, outputFolder, out errors);

            // test that pdf exists
            Assert.That(File.Exists(Path.Combine(outputFolder, @"27_STTAVQTPTSGEPLVST[O-Glycosylat.pdf"))); // parent scan
            Assert.That(File.Exists(Path.Combine(outputFolder, @"30_STTAVQTPTSGEPLVST[O-Glycosylat.pdf"))); // child scan

            // clean up resources
            metadrawLogic.CleanUpResources();
            Assert.That(!metadrawLogic.FilteredListOfPsms.Any());
            Assert.That(!metadrawLogic.PsmResultFilePaths.Any());
            Assert.That(!metadrawLogic.SpectraFilePaths.Any());

            // delete output
            Directory.Delete(outputFolder, true);
        }
Example #4
0
        public static void MetaDraw_SearchTaskTest()
        {
            string outputFolder    = Path.Combine(TestContext.CurrentContext.TestDirectory, @"MetaDraw_SearchTaskTest");
            string proteinDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\smalldb.fasta");
            string spectraFile     = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SmallCalibratible_Yeast.mzML");

            Directory.CreateDirectory(outputFolder);

            // run search task
            var searchtask = new SearchTask();

            searchtask.RunTask(outputFolder, new List <DbForTask> {
                new DbForTask(proteinDatabase, false)
            }, new List <string> {
                spectraFile
            }, "");

            var psmFile = Path.Combine(outputFolder, @"AllPSMs.psmtsv");

            // load results into metadraw
            var metadrawLogic = new MetaDrawLogic();

            metadrawLogic.SpectraFilePaths.Add(spectraFile);
            metadrawLogic.PsmResultFilePaths.Add(psmFile);
            var errors = metadrawLogic.LoadFiles(true, true);

            Assert.That(!errors.Any());
            Assert.That(metadrawLogic.FilteredListOfPsms.Any());

            // test results filter
            MetaDrawSettings.QValueFilter = 0.01;
            MetaDrawSettings.ShowDecoys   = false;
            metadrawLogic.FilterPsms();
            Assert.That(metadrawLogic.FilteredListOfPsms.All(p => p.DecoyContamTarget == "T"));
            Assert.That(metadrawLogic.FilteredListOfPsms.All(p => p.QValue <= 0.01));

            MetaDrawSettings.QValueFilter = 1.0;
            MetaDrawSettings.ShowDecoys   = true;
            metadrawLogic.FilterPsms();
            Assert.That(metadrawLogic.FilteredListOfPsms.Any(p => p.DecoyContamTarget == "D"));
            Assert.That(metadrawLogic.FilteredListOfPsms.Any(p => p.QValue > 0.01));

            // test text search filter (filter by full sequence)
            string filterString = @"QIVHDSGR";

            metadrawLogic.FilterPsmsByString(filterString);

            int c = 0;

            foreach (var filteredPsm in metadrawLogic.PeptideSpectralMatchesView)
            {
                var psmObj = (PsmFromTsv)filteredPsm;
                Assert.That(psmObj.FullSequence.Contains(filterString));
                c++;
            }
            Assert.That(c > 0);

            // test text search filter (filter by MS2 scan number)
            filterString = @"120";
            metadrawLogic.FilterPsmsByString(filterString);

            c = 0;
            foreach (var filteredPsm in metadrawLogic.PeptideSpectralMatchesView)
            {
                var psmObj = (PsmFromTsv)filteredPsm;
                Assert.That(psmObj.Ms2ScanNumber.ToString().Contains(filterString));
                c++;
            }
            Assert.That(c > 0);

            // draw PSM
            var plotView        = new OxyPlot.Wpf.PlotView();
            var canvas          = new Canvas();
            var parentChildView = new ParentChildScanPlotsView();
            var psm             = metadrawLogic.FilteredListOfPsms.First();

            metadrawLogic.DisplaySpectrumMatch(plotView, canvas, psm, parentChildView, out errors);
            Assert.That(errors == null || !errors.Any());

            // test that plot was drawn
            var plotSeries = plotView.Model.Series;
            var series     = plotSeries[0]; // the first m/z peak
            var peakPoints = ((LineSeries)series).Points;

            Assert.That(Math.Round(peakPoints[0].X, 2) == 101.07); // m/z
            Assert.That(Math.Round(peakPoints[1].X, 2) == 101.07);
            Assert.That((int)peakPoints[0].Y == 0);                // intensity
            Assert.That((int)peakPoints[1].Y == 35045);

            var plotAxes = plotView.Model.Axes;

            Assert.That(plotAxes.Count == 2);

            // test that base sequence annotation was drawn
            int numAnnotatedResidues = psm.BaseSeq.Length;
            int numAnnotatedIons     = psm.MatchedIons.Count;
            int numAnnotatedMods     = psm.FullSequence.Count(p => p == '[');

            Assert.That(canvas.Children.Count == numAnnotatedResidues + numAnnotatedIons + numAnnotatedMods);

            // write pdf
            var psmsToExport = metadrawLogic.FilteredListOfPsms.Where(p => p.FullSequence == "QIVHDSGR").Take(3).ToList();

            metadrawLogic.ExportToPdf(plotView, canvas, psmsToExport, parentChildView, outputFolder, out errors);

            // test that pdf exists
            Assert.That(File.Exists(Path.Combine(outputFolder, @"116_QIVHDSGR.pdf")));
            Assert.That(File.Exists(Path.Combine(outputFolder, @"120_QIVHDSGR.pdf")));
            Assert.That(File.Exists(Path.Combine(outputFolder, @"127_QIVHDSGR.pdf")));

            // test displaying a PSM with a mod
            var modPsm = metadrawLogic.FilteredListOfPsms.First(p => p.FullSequence.Contains("["));

            metadrawLogic.DisplaySpectrumMatch(plotView, canvas, modPsm, parentChildView, out errors);
            Assert.That(errors == null || !errors.Any());
            Assert.That(canvas.Children.Count == modPsm.BaseSeq.Length + modPsm.MatchedIons.Count + modPsm.FullSequence.Count(p => p == '['));

            // clean up resources
            metadrawLogic.CleanUpResources();
            Assert.That(!metadrawLogic.FilteredListOfPsms.Any());
            Assert.That(!metadrawLogic.PsmResultFilePaths.Any());
            Assert.That(!metadrawLogic.SpectraFilePaths.Any());

            // delete output
            Directory.Delete(outputFolder, true);
        }