Пример #1
0
        public static void TestMetaDrawReadPsmFile()
        {
            SearchTask searchTask = new SearchTask();

            string myFile     = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PrunedDbSpectra.mzml");
            string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\DbForPrunedDb.fasta");
            string folderPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMetaDrawReadPsmFile");

            DbForTask db = new DbForTask(myDatabase, false);

            Directory.CreateDirectory(folderPath);

            searchTask.RunTask(folderPath, new List <DbForTask> {
                db
            }, new List <string> {
                myFile
            }, "metadraw");
            string psmFile = Directory.GetFiles(folderPath).First(f => f.Contains("AllPSMs.psmtsv"));

            List <PsmFromTsv> parsedPsms = PsmTsvReader.ReadTsv(psmFile, out var warnings);

            Assert.AreEqual(11, parsedPsms.Count);
            Assert.AreEqual(0, warnings.Count);

            Directory.Delete(folderPath, true);
        }
Пример #2
0
        public static void TestMetaDrawReadCrossPsmFile()
        {
            XLSearchTask searchTask = new XLSearchTask();

            searchTask.XlSearchParameters.Crosslinker = GlobalVariables.Crosslinkers.ToList()[1];

            string myFile     = Path.Combine(TestContext.CurrentContext.TestDirectory, @"XlTestData\BSA_DSS_23747.mzML");
            string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"XlTestData\BSA.fasta");
            string folderPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMetaDrawReadPsmFile");

            DbForTask db = new DbForTask(myDatabase, false);

            Directory.CreateDirectory(folderPath);

            searchTask.RunTask(folderPath, new List <DbForTask> {
                db
            }, new List <string> {
                myFile
            }, "metadraw");

            string psmFile = Directory.GetFiles(folderPath).First(f => f.Contains("XL_Intralinks.tsv"));

            List <PsmFromTsv> parsedPsms = PsmTsvReader.ReadTsv(psmFile, out var warnings);

            Directory.Delete(folderPath, true);
        }
Пример #3
0
        public static void ReadOGlycoPsms()
        {
            string            psmFile    = @"TestData\oglyco.psmtsv";
            List <PsmFromTsv> parsedPsms = PsmTsvReader.ReadTsv(psmFile, out var warnings);

            Assert.AreEqual(9, parsedPsms.Count);
        }
Пример #4
0
        private void LoadAndDisplayPsms(string filename)
        {
            allPsms.Clear();

            string fileNameWithExtension    = Path.GetFileName(spectraFilePath);
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(spectraFilePath);

            try
            {
                // TODO: print warnings
                foreach (var psm in PsmTsvReader.ReadTsv(filename, out List <string> warnings))
                {
                    if (spectraFilePath == null || psm.Filename == fileNameWithExtension || psm.Filename == fileNameWithoutExtension || psm.Filename.Contains(fileNameWithoutExtension))
                    {
                        allPsms.Add(psm);
                        FilterPsm(psm);
                    }
                }

                GroupAmbiguousPsms();
            }
            catch (Exception e)
            {
                MessageBox.Show("Could not open PSM file:\n" + e.Message);
            }
        }
Пример #5
0
        public static void TestMetaDrawErrors()
        {
            string outputFolder    = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMetaDrawErrors");
            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 (skipping spectra file, to produce an error msg)
            var metadrawLogic = new MetaDrawLogic();

            metadrawLogic.PsmResultFilePaths.Add(psmFile);

            // this should produce an error because an expected spectra file is not present
            var errors = metadrawLogic.LoadFiles(loadSpectra: true, loadPsms: true);

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

            // this should not produce an error because we said not to load spectra
            errors = metadrawLogic.LoadFiles(loadSpectra: false, loadPsms: true);
            Assert.That(!errors.Any());

            var psmsFromTsv = PsmTsvReader.ReadTsv(psmFile, out var warnings);
            var plotView    = new OxyPlot.Wpf.PlotView();
            var canvas      = new Canvas();
            var parentChildScanPlotsView = new ParentChildScanPlotsView();

            // plotting PSM should produce an error because spectra are not loaded
            metadrawLogic.DisplaySpectrumMatch(plotView, canvas, psmsFromTsv.First(), parentChildScanPlotsView, out errors);
            Assert.That(errors.Any());

            // export to PDF should produce an error because spectra are not loaded
            metadrawLogic.ExportToPdf(plotView, canvas, new List <PsmFromTsv> {
                psmsFromTsv.First()
            }, parentChildScanPlotsView, outputFolder, out errors);
            Assert.That(errors.Any());

            // clean up resources
            metadrawLogic.CleanUpResources();

            // delete output
            Directory.Delete(outputFolder, true);
        }
Пример #6
0
        private void LoadPsms(out List <string> errors, bool haveLoadedSpectra)
        {
            errors = new List <string>();

            HashSet <string> fileNamesWithoutExtension = new HashSet <string>(
                SpectraFilePaths.Select(p => System.IO.Path.GetFileName(p.Replace(GlobalVariables.GetFileExtension(p), string.Empty))));
            List <PsmFromTsv> psmsThatDontHaveMatchingSpectraFile = new List <PsmFromTsv>();

            try
            {
                foreach (var resultsFile in PsmResultFilePaths)
                {
                    lock (ThreadLocker)
                    {
                        foreach (PsmFromTsv psm in PsmTsvReader.ReadTsv(resultsFile, out List <string> warnings))
                        {
                            if (fileNamesWithoutExtension.Contains(psm.FileNameWithoutExtension) || !haveLoadedSpectra)
                            {
                                AllPsms.Add(psm);
                            }
                            else
                            {
                                psmsThatDontHaveMatchingSpectraFile.Add(psm);
                            }

                            if (PsmsGroupedByFile.TryGetValue(psm.FileNameWithoutExtension, out var psmsForThisFile))
                            {
                                psmsForThisFile.Add(psm);
                            }
                            else
                            {
                                PsmsGroupedByFile.Add(psm.FileNameWithoutExtension, new ObservableCollection <PsmFromTsv> {
                                    psm
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                errors.Add("Error reading PSM file:\n" + e.Message);
            }

            if (psmsThatDontHaveMatchingSpectraFile.Any())
            {
                foreach (var file in psmsThatDontHaveMatchingSpectraFile.GroupBy(p => p.FileNameWithoutExtension))
                {
                    errors.Add(file.Count() + " PSMs from " + file.Key + " were not loaded because this spectra file was not found");
                }
            }

            FilterPsms();
        }
Пример #7
0
        private void LoadPsms(string filename, bool loadPsmsOfAllSpectraFiles)
        {
            allPsms.Clear();

            string fileNameWithExtension    = Path.GetFileName(spectraFilePath);
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(spectraFilePath);

            try
            {
                // TODO: print warnings
                foreach (var psm in PsmTsvReader.ReadTsv(filename, out List <string> warnings))
                {
                    if (loadPsmsOfAllSpectraFiles || Path.GetFileName(psm.Filename) == fileNameWithExtension || psm.Filename == fileNameWithExtension || psm.Filename == fileNameWithoutExtension || psm.Filename.Equals(fileNameWithoutExtension + "-calib")) // in case results are from a calibrated file
                    {
                        allPsms.Add(psm);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Could not open PSM file:\n" + e.Message);
            }
        }
Пример #8
0
        public static void TestFindVariantCrossingIons()
        {
            string            myFile   = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\VariantCrossTest.psmtsv");
            List <string>     warnings = new List <string>();
            List <PsmFromTsv> psms;

            psms = PsmTsvReader.ReadTsv(myFile, out warnings);  // test will fail if the order of psms is changed to something other than top to bottom row

            // check that variant psm properties are being parsed correctly
            Assert.AreEqual("", psms[0].IdentifiedSequenceVariations);
            Assert.AreEqual("A147T", psms[1].IdentifiedSequenceVariations);

            Assert.AreEqual("541-541", psms[0].SpliceSites);
            Assert.AreEqual("", psms[1].SpliceSites);

            // check that the correct ions are being added to VariantCrossingIons
            List <List <string> > expected = new List <List <string> >();

            expected.Add(new List <string>()
            {
            });                                                             // no variant (7527)
            expected.Add(new List <string>()
            {
                "b3"
            });                                                             // b fragments before and after variant (4211)
            expected.Add(new List <string>()
            {
                "y3"
            });                                                             // y fragments before and after variant (7759)
            expected.Add(new List <string>()
            {
                "b4", "b16"
            });                                                             // variant at 1st position (9221)
            expected.Add(new List <string>()
            {
                "y1", "y9"
            });                                                             // variant at last position (6778)
            expected.Add(new List <string>()
            {
                "b4", "y35"
            });                                                             // peptide comes from multiple proteins (8613)
            expected.Add(new List <string>()
            {
                "b1", "b10", "y1", "y6"
            });                                                             // variation spans the whole peptide (8765)
            expected.Add(new List <string>()
            {
            });                                                             // variant before peptide (8169)
            expected.Add(new List <string>()
            {
            });                                                             // variant after peptide (6532)
            expected.Add(new List <string>()
            {
                "a3"
            });                                                             // a fragments before and after variant (4212)
            expected.Add(new List <string>()
            {
                "c3"
            });                                                             // c fragments before and after variant (4213)
            expected.Add(new List <string>()
            {
                "x3"
            });                                                             // x fragments before and after variant (7760)
            expected.Add(new List <string>()
            {
                "zDot3"
            });                                                             // z fragments before and after variant (7761)
            expected.Add(new List <string>()
            {
            });                                     // M fragment with length almost the whole peptide and variant in the middle (7762)
            expected.Add(new List <string>()
            {
            });                                     // D fragment with length almost the whole peptide and variant in the middle (7763)

            for (int i = 0; i < psms.Count; i++)
            {
                IEnumerable <string> actualIons = psms[i].VariantCrossingIons.Select(p => p.NeutralTheoreticalProduct.Annotation);
                foreach (string expectedIon in expected[i])
                {
                    Assert.IsTrue(actualIons.Contains(expectedIon),
                                  "VariantCrossingIons should contain ion " + expectedIon + " in file " + psms[i].Filename + ".");
                }
                foreach (string actualIon in actualIons)
                {
                    Assert.IsTrue(expected[i].Contains(actualIon),
                                  "VariantCrossingIons should not contain ion " + actualIon + " in file " + psms[i].Filename + ".");
                }
            }
        }
Пример #9
0
        public static void InternalFragmentIonTest()
        {
            SearchTask searchTask = new SearchTask()
            {
                SearchParameters = new SearchParameters
                {
                    MinAllowedInternalFragmentLength = 1
                },
                CommonParameters = new CommonParameters(
                    digestionParams: new DigestionParams("top-down"),
                    listOfModsVariable: new List <(string, string)> {
                    ("Common Variable", "Oxidation on M"),
                    ("Common Biological", "Acetylation on K"),
                    ("Common Biological", "Acetylation on X")
                })
            };

            string    myFile     = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\InternalTest.mgf");
            string    myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\InternalTest.fasta");
            DbForTask db         = new DbForTask(myDatabase, false);

            List <(string, MetaMorpheusTask)> taskList = new List <(string, MetaMorpheusTask)> {
                ("TestInternal", searchTask)
            };


            var engine = new EverythingRunnerEngine(taskList, new List <string> {
                myFile
            }, new List <DbForTask> {
                new DbForTask(myDatabase, false)
            }, Environment.CurrentDirectory);

            engine.Run();

            string outputPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestInternal\AllPSMs.psmtsv");
            //var output = File.ReadAllLines(outputPath);
            //read the psmtsv
            List <PsmFromTsv> psms = PsmTsvReader.ReadTsv(outputPath, out var warning);

            Assert.IsTrue(psms.Count == 1);
            //check that it's been disambiguated
            Assert.IsFalse(psms[0].FullSequence.Contains("|"));
            int numTotalFragments = psms[0].MatchedIons.Count;

            //test again but no variable acetyl on K. Make sure that internal fragments are still searched even without ambiguity
            searchTask = new SearchTask()
            {
                SearchParameters = new SearchParameters
                {
                    MinAllowedInternalFragmentLength = 1
                },
                CommonParameters = new CommonParameters(
                    digestionParams: new DigestionParams("top-down"),
                    listOfModsVariable: new List <(string, string)> {
                    ("Common Variable", "Oxidation on M"),
                    ("Common Biological", "Acetylation on X")
                })
            };
            taskList = new List <(string, MetaMorpheusTask)> {
                ("TestInternal", searchTask)
            };
            engine = new EverythingRunnerEngine(taskList, new List <string> {
                myFile
            }, new List <DbForTask> {
                new DbForTask(myDatabase, false)
            }, Environment.CurrentDirectory);
            engine.Run();
            psms = PsmTsvReader.ReadTsv(outputPath, out warning);
            Assert.IsTrue(psms.Count == 1);
            Assert.IsTrue(psms[0].MatchedIons.Count == numTotalFragments);

            Directory.Delete(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestInternal"), true);
        }