private static SrmDocument InitMultiplePeptidesSameMzDocument(TestFilesDir testFilesDir, string fileName, out string docPath) { docPath = testFilesDir.GetTestPath(fileName); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); AssertEx.IsDocumentState(doc, 0, 3, 3, 6, 58); // int revision, int groups, int peptides, int tranGroups, int transitions return doc; }
public void DoTestDemux(bool asSmallMolecules) { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPathMsx = testFilesDir.GetTestPath("MsxTest.sky"); string dataPathMsx = testFilesDir.GetTestPath("MsxTest.mzML"); string cachePathMsx = ChromatogramCache.FinalPathForName(docPathMsx, null); FileEx.SafeDelete(cachePathMsx); SrmDocument docMsx = ResultsUtil.DeserializeDocument(docPathMsx); if (asSmallMolecules) { var refine = new RefinementSettings(); docMsx = refine.ConvertToSmallMolecules(docMsx); } var fullScanInitialMsx = docMsx.Settings.TransitionSettings.FullScan; Assert.IsTrue(fullScanInitialMsx.IsEnabledMsMs); TestMsx(docMsx, dataPathMsx); string docPathOverlap = testFilesDir.GetTestPath("OverlapTest.sky"); string dataPathOverlap = testFilesDir.GetTestPath("OverlapTest.mzML"); string cachePathOverlap = ChromatogramCache.FinalPathForName(docPathOverlap, null); FileEx.SafeDelete(cachePathOverlap); SrmDocument docOverlap = ResultsUtil.DeserializeDocument(docPathOverlap); if (asSmallMolecules) { var refine = new RefinementSettings(); docOverlap = refine.ConvertToSmallMolecules(docOverlap); } var fullScanInitialOverlap = docMsx.Settings.TransitionSettings.FullScan; Assert.IsTrue(fullScanInitialOverlap.IsEnabledMsMs); TestOverlap(docOverlap,dataPathOverlap); }
public void AgilentFormatsTest() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath; SrmDocument doc = InitAgilentDocument(testFilesDir, out docPath); var docContainer = new ResultsTestDocumentContainer(doc, docPath); const string replicateName = "AgilentTest"; string extRaw = ExtensionTestContext.ExtAgilentRaw; var chromSets = new[] { new ChromatogramSet(replicateName, new[] { new MsDataFilePath(testFilesDir.GetTestPath("081809_100fmol-MichromMix-05" + extRaw)), }), }; var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); docResults = docContainer.Document; AssertResult.IsDocumentResultsState(docResults, replicateName, doc.PeptideCount, doc.PeptideTransitionGroupCount, 0, doc.PeptideTransitionCount, 0); // Release file handles docContainer.Release(); testFilesDir.Dispose(); }
protected override void DoTest() { TestFilesPersistent = new[] { "Buck" }; var testFilesDir = new TestFilesDir(TestContext, TestFilesZip, null, TestFilesPersistent); string documentPath = testFilesDir.GetTestPath("CM Buck_Lum_Comm_fr III for MS1 paper_v1.sky"); // this will be in user download area as a persistent doc RunUI(() => SkylineWindow.OpenFile(documentPath)); WaitForConditionUI(() => SkylineWindow.DocumentUI.Settings.MeasuredResults.IsLoaded); Stopwatch loadStopwatch = new Stopwatch(); var doc = SkylineWindow.Document; var minimizedFile = testFilesDir.GetTestPath("minimized.sky"); // Not L10N var cacheFile = Path.ChangeExtension(minimizedFile, ChromatogramCache.EXT); { RunUI(() => SkylineWindow.SaveDocument(minimizedFile)); var manageResultsDlg = ShowDialog<ManageResultsDlg>(SkylineWindow.ManageResults); var minimizeResultsDlg = ShowDialog<MinimizeResultsDlg>(manageResultsDlg.MinimizeResults); RunUI(() => { minimizeResultsDlg.LimitNoiseTime = false; }); loadStopwatch.Start(); OkDialog(minimizeResultsDlg, () => minimizeResultsDlg.MinimizeToFile(minimizedFile)); WaitForCondition(() => File.Exists(cacheFile)); WaitForClosedForm(manageResultsDlg); loadStopwatch.Stop(); } WaitForDocumentChange(doc); DebugLog.Info("minimization time = {0}", loadStopwatch.ElapsedMilliseconds); }
public void WatersLockmassCmdlinePerfTest() { if (IsPerfTest && !RunPerfTests) { return; // Don't want to run this lengthy test right now } TestFilesZip = "https://skyline.gs.washington.edu/perftests/PerfTestLockmass.zip"; TestFilesPersistent = new[] { "ID19638_01_UCA195_2533_082715.raw" }; // List of files that we'd like to unzip alongside parent zipFile, and (re)use in place TestFilesDir = new TestFilesDir(TestContext, TestFilesZip, "CmdlineTest", TestFilesPersistent); var skyfile = GetTestPath("2533_FattyAcids.sky"); var rawPath = GetTestPath(TestFilesPersistent[0]); const double lockmassNegative = 554.2615; // Exercise the commandline var outPathUncorrected = TestFilesDir.GetTestPath("cmdlineTestUncorrected.sky"); var outPathCorrected = TestFilesDir.GetTestPath("cmdlineTestCorrected.sky"); RunCommand("--in=" + skyfile, "--import-file=" + rawPath, "--out=" + outPathUncorrected); FileEx.SafeDelete(Path.ChangeExtension(skyfile, ChromatogramCache.EXT)); var cmdDocUncorrected = ResultsUtil.DeserializeDocument(outPathUncorrected); RunCommand("--in=" + skyfile, "--import-file=" + rawPath, "--import-lockmass-negative=" + lockmassNegative, "--out=" + outPathCorrected); var cmdDocCorrected = ResultsUtil.DeserializeDocument(outPathCorrected); ComparePeaks(cmdDocCorrected, cmdDocUncorrected); }
public void DoTestOlderProteomeDb(TestContext testContext, bool doActualWebAccess) { using (var testFilesDir = new TestFilesDir(testContext, ZIP_FILE)) { string fastaPath = testFilesDir.GetTestPath("tiny.fasta"); string protDbPath = testFilesDir.GetTestPath("celegans_mini.protdb"); // a version 0 protdb file string blibPath = testFilesDir.GetTestPath("random.blib"); // a bibliospec file // What happens when you try to open a random file as a protdb file? AssertEx.ThrowsException<DbException>(() => ProteomeDb.OpenProteomeDb(fastaPath)); // What happens when you try to open a non-protdb database file as a protdb file? AssertEx.ThrowsException<FileLoadException>(() => ProteomeDb.OpenProteomeDb(blibPath)); using (ProteomeDb proteomeDb = ProteomeDb.OpenProteomeDb(protDbPath)) { Assert.IsTrue(proteomeDb.GetSchemaVersionMajor() == 0); // the initial db from our zipfile should be ancient Assert.IsTrue(proteomeDb.GetSchemaVersionMinor() == 0); // the initial db from our zipfile should be ancient Assert.AreEqual(9, proteomeDb.GetProteinCount()); var protein = proteomeDb.GetProteinByName("Y18D10A.20"); Assert.IsNotNull(protein); Assert.IsTrue(String.IsNullOrEmpty(protein.Accession)); // old db won't have this populated WebEnabledFastaImporter searcher = new WebEnabledFastaImporter(doActualWebAccess ? null :new WebEnabledFastaImporter.FakeWebSearchProvider()); Assert.IsTrue(proteomeDb.LookupProteinMetadata(Progress, searcher)); // add any missing protein metadata protein = proteomeDb.GetProteinByName("Y18D10A.20"); Assert.IsNotNull(protein); if (doActualWebAccess) // We can actually go to the web for metadata Assert.AreEqual( "Q9XW16", protein.Accession); using (var reader = new StreamReader(fastaPath)) { proteomeDb.AddFastaFile(reader, (msg, progress) => true); } // the act of writing should update to the current version Assert.AreEqual(ProteomeDb.SCHEMA_VERSION_MAJOR_CURRENT, proteomeDb.GetSchemaVersionMajor()); Assert.AreEqual(ProteomeDb.SCHEMA_VERSION_MINOR_CURRENT, proteomeDb.GetSchemaVersionMinor()); Assert.AreEqual(19, proteomeDb.GetProteinCount()); // check for propery processed protein metadata Assert.IsTrue(proteomeDb.LookupProteinMetadata(Progress,searcher)); protein = proteomeDb.GetProteinByName("IPI00000044"); Assert.IsNotNull(protein); Assert.AreEqual("P01127", protein.Accession); // We get this offline with our ipi->uniprot mapper if (doActualWebAccess) Assert.AreEqual("PDGFB_HUMAN", protein.PreferredName); // But this we get only with web access // TODO: bspratt fix this - GetDigestion has no notion of a Db that has been added to, doesn't digest the new proteins and returns immediately (issue #304) // Enzyme trypsin = EnzymeList.GetDefault(); //proteomeDb.Digest(new ProteaseImpl(trypsin), (msg, progress) => true); //Digestion digestion = proteomeDb.GetDigestion(trypsin.Name); //var digestedProteins0 = digestion.GetProteinsWithSequencePrefix("EDGWVK", 100); //Assert.IsTrue(digestedProteins0.Count >= 1); } } }
public void TestCollectStatistics() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath("BSA_Protea_label_free_20100323_meth3_multi.sky"); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); var docContainer = new ResultsTestDocumentContainer(doc, docPath); // Import the first RAW file (or mzML for international) string rawPath = testFilesDir.GetTestPath("ah_20101011y_BSA_MS-MS_only_5-2" + ExtensionTestContext.ExtThermoRaw); var measuredResults = new MeasuredResults(new[] {new ChromatogramSet("Single", new[] {MsDataFileUri.Parse(rawPath)})}); SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, 3, 3, 21); ChromCacheMinimizer chromCacheMinimizer = docResults.Settings.MeasuredResults.GetChromCacheMinimizer(docResults); ChromCacheMinimizer.Settings settings = new ChromCacheMinimizer.Settings().SetDiscardUnmatchedChromatograms(true); ChromCacheMinimizer.MinStatistics minStatistics = null; chromCacheMinimizer.Minimize(settings, s => minStatistics = s, null); Assert.AreEqual(100, minStatistics.PercentComplete); Assert.AreEqual(1.0, minStatistics.MinimizedRatio); var docMissingFirstPeptide = (SrmDocument) docResults.ReplaceChild( docResults.PeptideGroups.First().RemoveChild(docResults.PeptideGroups.First().Children[0])); var docWithOnlyFirstPeptide = (SrmDocument) docResults.ReplaceChild( docResults.PeptideGroups.First().ChangeChildren(new[] {docResults.PeptideGroups.First().Children[0]})); ChromCacheMinimizer.MinStatistics statsMissingFirstProtein = null; ChromCacheMinimizer.MinStatistics statsWithOnlyFirstProtein = null; settings = settings.SetDiscardUnmatchedChromatograms(true); ChromCacheMinimizer minimizerMissingFirstProtein = docMissingFirstPeptide.Settings.MeasuredResults.GetChromCacheMinimizer(docMissingFirstPeptide); ChromCacheMinimizer minimizerWithOnlyFirstProtein = docWithOnlyFirstPeptide.Settings.MeasuredResults.GetChromCacheMinimizer(docWithOnlyFirstPeptide); minimizerMissingFirstProtein.Minimize(settings, s => statsMissingFirstProtein = s, null); minimizerWithOnlyFirstProtein.Minimize(settings, s => statsWithOnlyFirstProtein = s, null); Assert.AreEqual(100, statsMissingFirstProtein.PercentComplete); Assert.AreEqual(100, statsWithOnlyFirstProtein.PercentComplete); Assert.AreEqual(1.0, statsMissingFirstProtein.MinimizedRatio + statsWithOnlyFirstProtein.MinimizedRatio, .00001); settings = settings.SetDiscardUnmatchedChromatograms(false); ChromCacheMinimizer.MinStatistics statsMissingFirstProteinKeepAll = null; ChromCacheMinimizer.MinStatistics statsWithOnlyFirstProteinKeepAll = null; minimizerMissingFirstProtein.Minimize(settings, s => statsMissingFirstProteinKeepAll = s, null); minimizerWithOnlyFirstProtein.Minimize(settings, s => statsWithOnlyFirstProteinKeepAll = s, null); Assert.AreEqual(100, statsMissingFirstProteinKeepAll.PercentComplete); Assert.AreEqual(1.0, statsMissingFirstProteinKeepAll.MinimizedRatio); Assert.AreEqual(100, statsWithOnlyFirstProteinKeepAll.PercentComplete); Assert.AreEqual(1.0, statsWithOnlyFirstProteinKeepAll.MinimizedRatio); docContainer.Release(); }
public void RefineConvertToSmallMoleculeMassesTest() { TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"TestA\Refine.zip"); var document = InitRefineDocument(testFilesDir); var refineSettings = new RefinementSettings(); var converted = refineSettings.ConvertToSmallMolecules(document, RefinementSettings.ConvertToSmallMoleculesMode.masses_only); AssertEx.ConvertedSmallMoleculeDocumentIsSimilar(document, converted); }
public void FullScanPrecursorTransitionsTest() { TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"TestA\FullScanPrecursor.zip"); string docPath = testFilesDir.GetTestPath("FullScanPrecursor.sky"); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); AssertEx.IsDocumentState(doc, 0, 1, 4, 5, 52); var docContainer = new ResultsTestDocumentContainer(doc, docPath); var mitoLibSpec = new BiblioSpecLiteSpec("mito2", testFilesDir.GetTestPath("mito2.blib")); doc = docContainer.ChangeLibSpecs(new [] { mitoLibSpec }); Assert.IsTrue(doc.IsLoaded); // Switch to only precursor ions var docPrecOnly = doc.ChangeSettings(doc.Settings.ChangeTransitionFilter(filter => filter.ChangeIonTypes(new[] { IonType.precursor }))); // All precursors should have 3 precursor transitions (M, M+1 and M+2) AssertEx.IsDocumentState(docPrecOnly, 3, 1, 4, 5, 15); Assert.IsFalse(docPrecOnly.PeptideTransitions.Any(nodeTran => nodeTran.Transition.IonType != IonType.precursor)); // Use low resolution MS1 filtering var docLowMs1 = docPrecOnly.ChangeSettings(docPrecOnly.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 1, null) .ChangePrecursorResolution(FullScanMassAnalyzerType.qit, 0.5, null))); // All precursors should have one precursor transition AssertEx.IsDocumentState(docLowMs1, 4, 1, 4, 5, 5); // Add y-ions to low resolution filtering var docLowMs1Y = docLowMs1.ChangeSettings(docLowMs1.Settings.ChangeTransitionFilter(filter => filter.ChangeIonTypes(new[] { IonType.precursor, IonType.y }))); AssertEx.IsDocumentState(docLowMs1Y, 5, 1, 4, 5, 33); // Turn off MS1 filtering var docNoMs1 = docPrecOnly.ChangeSettings(docPrecOnly.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.None, null, null))); // One of the precursors should have no transitions, since its spectrum has no precursor match AssertEx.IsDocumentState(docNoMs1, 4, 1, 4, 5, 4); // Turn off MS/MS library matching var docNoLibMatch = docNoMs1.ChangeSettings(docNoMs1.Settings.ChangeTransitionLibraries(lib => lib.ChangePick(TransitionLibraryPick.none))); // All precursors should have a single precursor transition AssertEx.IsDocumentState(docNoLibMatch, 5, 1, 4, 5, 5); // Use library plus filter matching var docLibPlusMatch = docNoMs1.ChangeSettings(docNoMs1.Settings.ChangeTransitionLibraries(lib => lib.ChangePick(TransitionLibraryPick.all_plus))); // All precursors should have a single precursor transition AssertEx.IsDocumentState(docLibPlusMatch, 5, 1, 4, 5, 5); // Release the library stream, and dispose of the directory docContainer.ChangeLibSpecs(new LibrarySpec[0]); testFilesDir.Dispose(); }
public void TestMeasuredDriftValues() { var testFilesDir = new TestFilesDir(TestContext, @"Test\Results\BlibDriftTimeTest.zip"); // Re-used from BlibDriftTimeTest // Open document with some peptides but no results var docPath = testFilesDir.GetTestPath("BlibDriftTimeTest.sky"); SrmDocument docOriginal = ResultsUtil.DeserializeDocument(docPath); var docContainer = new ResultsTestDocumentContainer(docOriginal, docPath); var doc = docContainer.Document; // Import an mz5 file that contains drift info const string replicateName = "ID12692_01_UCA168_3727_040714"; var chromSets = new[] { new ChromatogramSet(replicateName, new[] { new MsDataFilePath(testFilesDir.GetTestPath("ID12692_01_UCA168_3727_040714.mz5")), }), }; var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets)); Assert.IsTrue(docContainer.SetDocument(docResults, docOriginal, true)); docContainer.AssertComplete(); var document = docContainer.Document; document = document.ChangeSettings(document.Settings.ChangePeptidePrediction(prediction => new PeptidePrediction(null, DriftTimePredictor.EMPTY))); // Verify ability to extract predictions from raw data var newPred = document.Settings.PeptideSettings.Prediction.DriftTimePredictor.ChangeMeasuredDriftTimesFromResults( document, docContainer.DocumentFilePath); var result = newPred.MeasuredDriftTimePeptides; Assert.AreEqual(TestSmallMolecules? 2: 1, result.Count); const double expectedDT = 4.0019; var expectedOffset = .4829; Assert.AreEqual(expectedDT, result.Values.First().DriftTimeMsec(false).Value, .001); Assert.AreEqual(expectedOffset, result.Values.First().HighEnergyDriftTimeOffsetMsec, .001); // Check ability to update, and to preserve unchanged var revised = new Dictionary<LibKey, DriftTimeInfo>(); var libKey = result.Keys.First(); revised.Add(libKey, new DriftTimeInfo(4, 0.234)); var libKey2 = new LibKey("DEADEELS",2); revised.Add(libKey2, new DriftTimeInfo(5, 0.123)); document = document.ChangeSettings( document.Settings.ChangePeptidePrediction(prediction => new PeptidePrediction(null, new DriftTimePredictor("test", revised, null, null, 40)))); newPred = document.Settings.PeptideSettings.Prediction.ChangeDriftTimePredictor( document.Settings.PeptideSettings.Prediction.DriftTimePredictor.ChangeMeasuredDriftTimesFromResults( document, docContainer.DocumentFilePath)).DriftTimePredictor; result = newPred.MeasuredDriftTimePeptides; Assert.AreEqual(TestSmallMolecules ? 3 : 2, result.Count); Assert.AreEqual(expectedDT, result[libKey].DriftTimeMsec(false).Value, .001); Assert.AreEqual(expectedOffset, result[libKey].HighEnergyDriftTimeOffsetMsec, .001); Assert.AreEqual(5, result[libKey2].DriftTimeMsec(false).Value, .001); Assert.AreEqual(0.123, result[libKey2].HighEnergyDriftTimeOffsetMsec, .001); docContainer.Release(); }
public void AgilentFileTypeTest() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string extRaw = ExtensionTestContext.ExtAgilentRaw; // Do file type check using (var msData = new MsDataFileImpl(testFilesDir.GetTestPath("081809_100fmol-MichromMix-05" + extRaw))) { Assert.IsTrue(msData.IsAgilentFile); } }
public void TestExportMethodShimadzu() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); var docPath = testFilesDir.GetTestPath("bgal.sky"); var doc = ResultsUtil.DeserializeDocument(docPath); var outPath = testFilesDir.GetTestPath("out.lcm"); var templatePath = testFilesDir.GetTestPath("40.lcm"); var exporter = new ShimadzuMethodExporter(doc) {RunLength = 30}; exporter.ExportMethod(outPath, templatePath, null); Assert.AreEqual(540672, new FileInfo(outPath).Length); }
// [TestMethod] // disabling this since the test file URLs don't exist public void ConvertOpenSwathPerf() { if (!RunPerfTests) return; // PerfTests only run when the global "allow perf tests" flag is set TestFilesZip = @"http://proteome.gs.washington.edu/software/test/skyline-perf/HasmikProcessing.zip"; var testFilesDir = new TestFilesDir(TestContext, TestFilesZip, null, TestFilesPersistent); var inFiles = INDIVIDUAL_OUTPUT.Select(testFilesDir.GetTestPath); string outFile = testFilesDir.GetTestPath("Spectronaut.csv"); RunConversion(inFiles, outFile); }
public void TestBlibDriftTimes() { var testFilesDir = new TestFilesDir(TestContext, @"Test\Results\BlibDriftTimeTest.zip"); // Open document with some peptides but no results var docPath = testFilesDir.GetTestPath("BlibDriftTimeTest.sky"); SrmDocument docOriginal = ResultsUtil.DeserializeDocument(docPath); var docContainer = new ResultsTestDocumentContainer(docOriginal, docPath); var doc = docContainer.Document; // Use the bare drift times in the spectral library var librarySpec = new BiblioSpecLiteSpec("drift test", testFilesDir.GetTestPath("BlibDriftTimeTest.blib")); doc = doc.ChangeSettings( doc.Settings.ChangePeptideLibraries(lib => lib.ChangeLibrarySpecs(new[] { librarySpec })). ChangePeptidePrediction(p => p.ChangeLibraryDriftTimesResolvingPower(20)). ChangePeptidePrediction(p => p.ChangeUseLibraryDriftTimes(true)) ); // Import an mz5 file that needs drift info that's in the original data set, // but preserved in the .blib file associated with a different raw source // Without the bugfix this won't get any drift time filtering. const string replicateName = "ID12692_01_UCA168_3727_040714"; var chromSets = new[] { new ChromatogramSet(replicateName, new[] { new MsDataFilePath(testFilesDir.GetTestPath("ID12692_01_UCA168_3727_040714.mz5")), }), }; var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets)); Assert.IsTrue(docContainer.SetDocument(docResults, docOriginal, true)); docContainer.AssertComplete(); var document = docContainer.Document; float tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance; double maxHeight = 0; var results = document.Settings.MeasuredResults; Assert.AreEqual(2, document.PeptidePrecursorPairs.Count()); var pair = document.PeptidePrecursorPairs.ToArray()[1]; ChromatogramGroupInfo[] chromGroupInfo; Assert.IsTrue(results.TryLoadChromatogram(0, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroupInfo)); Assert.AreEqual(1, chromGroupInfo.Length); var chromGroup = chromGroupInfo[0]; Assert.AreEqual(2 , chromGroup.NumPeaks); // This will be higher if we don't filter on DT foreach (var tranInfo in chromGroup.TransitionPointSets) { maxHeight = Math.Max(maxHeight, tranInfo.MaxIntensity); } Assert.AreEqual(278 , maxHeight, 1); // Without DT filtering, this will be much greater - about 996 docContainer.Release(); }
public void DoAgilentMseChromatogramTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules) { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); TestSmallMolecules = false; // We have an explicit test for that here string docPath; SrmDocument document = InitAgilentMseDocument(testFilesDir, out docPath); if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none) { var refine = new RefinementSettings(); document = refine.ConvertToSmallMolecules(document, asSmallMolecules); } var docContainer = new ResultsTestDocumentContainer(document, docPath); var doc = docContainer.Document; var listChromatograms = new List<ChromatogramSet>(); var path = MsDataFileUri.Parse(@"AgilentMse\BSA-AI-0-10-25-41_first_100_scans.mzML"); listChromatograms.Add(AssertResult.FindChromatogramSet(doc, path) ?? new ChromatogramSet(path.GetFileName().Replace('.', '_'), new[] { path })); var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); document = docContainer.Document; float tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance; var results = document.Settings.MeasuredResults; foreach (var pair in document.MoleculePrecursorPairs) { ChromatogramGroupInfo[] chromGroupInfo; Assert.IsTrue(results.TryLoadChromatogram(0, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroupInfo)); Assert.AreEqual(1, chromGroupInfo.Length); } // now drill down for specific values int nPeptides = 0; foreach (var nodePep in document.Molecules.Where(nodePep => nodePep.Results[0] != null)) { // expecting just one peptide result in this small data set if (nodePep.Results[0].Sum(chromInfo => chromInfo.PeakCountRatio > 0 ? 1 : 0) > 0) { Assert.AreEqual(0.2462, (double)nodePep.GetMeasuredRetentionTime(0), .0001, "averaged retention time differs in node "+nodePep.RawTextId); Assert.AreEqual(0.3333, (double)nodePep.GetPeakCountRatio(0), 0.0001); nPeptides++; } } Assert.AreEqual(1, nPeptides); // Release file handles docContainer.Release(); testFilesDir.Dispose(); }
public void RefineConvertToSmallMoleculesTest() { // Exercise the code that helps match heavy labeled ion formulas with unlabled Assert.AreEqual("C5H12NO2S", BioMassCalc.MONOISOTOPIC.StripLabelsFromFormula("C5H9H'3NO2S")); Assert.IsNull(BioMassCalc.MONOISOTOPIC.StripLabelsFromFormula("")); Assert.IsNull(BioMassCalc.MONOISOTOPIC.StripLabelsFromFormula(null)); TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"TestA\Refine.zip"); var document = InitRefineDocument(testFilesDir); var refineSettings = new RefinementSettings(); var converted = refineSettings.ConvertToSmallMolecules(document); AssertEx.ConvertedSmallMoleculeDocumentIsSimilar(document, converted); }
public void TestExplicitRT() { TestSmallMolecules = false; // Don't need the magic test node var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); // Verify our handling of two Q1>Q3 transitions with no RT overlap - formerly we just ignored one or the other though both are needed // As in https://skyline.gs.washington.edu/labkey/announcements/home/support/thread.view?entityId=924e3c51-7c00-1033-9ff1-da202582a252&_anchor=24723 doTest(testFilesDir, "lysine.sky", 13.8, new[] { "ESvKprosp_20151120_035", "ESvKprosp_20151120_036" }, .5); // Verify our use of explict RT in peak picking where the correct peak isn't the largest // As in https://skyline.gs.washington.edu/labkey/announcements/home/support/thread.view?entityId=273ccc30-8258-1033-9ff1-da202582a252&_anchor=24774 doTest(testFilesDir, "test_b.sky", 9.1, new[] { "120315_120", "120315_121", "120315_125", "120315_126" }, null); }
private static void doTest(TestFilesDir testFilesDir, string skyFile, double expectedRT, string[] filenames, double? expectedRatio) { string docPath; var document = InitExplicitRTDocument(testFilesDir, skyFile, out docPath); var docContainer = new ResultsTestDocumentContainer(document, docPath); var doc = docContainer.Document; var listChromatograms = new List<ChromatogramSet>(); foreach (var filename in filenames) { var path = MsDataFileUri.Parse(filename + ExtensionTestContext.ExtWatersRaw); listChromatograms.Add(AssertResult.FindChromatogramSet(doc, path) ?? new ChromatogramSet(path.GetFileName().Replace('.', '_'), new[] { path })); } var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); document = docContainer.Document; float tolerance = (float) document.Settings.TransitionSettings.Instrument.MzMatchTolerance; foreach (var pair in document.MoleculePrecursorPairs) { ChromatogramGroupInfo[] chromGroupInfo; Assert.IsTrue(document.Settings.MeasuredResults.TryLoadChromatogram(0, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroupInfo)); Assert.IsTrue(document.Settings.MeasuredResults.TryLoadChromatogram(1, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroupInfo)); } var nResults = 0; foreach (var nodePep in document.Molecules) { foreach (var results in nodePep.Results) { foreach (var result in results) { Assert.AreEqual(expectedRT, result.RetentionTime ?? 0, .1); // We should pick peaks based on explicit RT if (expectedRatio.HasValue) // If we didn't, ratios won't be right { Assert.IsNotNull(result.LabelRatios[0].Ratio); Assert.AreEqual(expectedRatio.Value, result.LabelRatios[0].Ratio.Ratio, .1); } nResults++; } } } Assert.AreEqual(filenames.Length*document.MoleculeGroupCount, nResults); // Release file handles docContainer.Release(); }
public void GenerateDecoysTest() { TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"TestA\SimpleDecoys.zip"); string docPath = testFilesDir.GetTestPath("SimpleDecoys.sky"); SrmDocument simpleDecoysDoc = ResultsUtil.DeserializeDocument(docPath); AssertEx.IsDocumentState(simpleDecoysDoc, 0, 1, 18, 18, 56); // First check right number of decoy peptide groups and transtions are generated var refineSettings = new RefinementSettings(); int numDecoys = simpleDecoysDoc.PeptideCount; var decoysDoc = refineSettings.GenerateDecoys(simpleDecoysDoc, numDecoys, DecoyGeneration.ADD_RANDOM); ValidateDecoys(simpleDecoysDoc, decoysDoc, false); // Second call to generate decoys to make sure that it removes the original Decoys group and generates a completely new one. var newDecoysDoc = refineSettings.GenerateDecoys(decoysDoc, numDecoys, DecoyGeneration.ADD_RANDOM); Assert.AreNotEqual(decoysDoc.PeptideGroups.First(nodePeptideGroup => nodePeptideGroup.IsDecoy), newDecoysDoc.PeptideGroups.First(nodePeptideGroup => nodePeptideGroup.IsDecoy)); // MS1 document with precursors and variable modifications, shuffled docPath = testFilesDir.GetTestPath("Ms1FilterTutorial.sky"); SrmDocument variableDecoysDoc = ResultsUtil.DeserializeDocument(docPath); AssertEx.IsDocumentState(variableDecoysDoc, 0, 11, 50, 51, 153); numDecoys = variableDecoysDoc.PeptideCount; var decoysVariableShuffle = refineSettings.GenerateDecoys(variableDecoysDoc, numDecoys, DecoyGeneration.SHUFFLE_SEQUENCE); ValidateDecoys(variableDecoysDoc, decoysVariableShuffle, true); // Document with explicit modifications, reversed SrmDocument docStudy7 = ResultsUtil.DeserializeDocument("Study7.sky", GetType()); AssertEx.IsDocumentState(docStudy7, 0, 7, 11, 22, 66); numDecoys = docStudy7.PeptideCount; var decoysExplicitReverse = refineSettings.GenerateDecoys(docStudy7, numDecoys, DecoyGeneration.REVERSE_SEQUENCE); ValidateDecoys(docStudy7, decoysExplicitReverse, true); // Random mass shifts with precursors (used to throw an exception due to bad range check that assumed product ions only) while (true) { // As this is random we may need to make a few attempts before we get the values we need SrmDocument doc = ResultsUtil.DeserializeDocument(testFilesDir.GetTestPath("precursor_decoy_test.sky")); AssertEx.IsDocumentState(doc, null, 1, 1, 2, 6); numDecoys = 2; var decoysRandom = refineSettings.GenerateDecoys(doc, numDecoys, DecoyGeneration.ADD_RANDOM); // Verify that we successfully set a precursor transition decoy mass outside the allowed range of product transitions if (decoysRandom.PeptideTransitions.Any(x => x.IsDecoy && (x.Transition.DecoyMassShift > Transition.MAX_PRODUCT_DECOY_MASS_SHIFT || x.Transition.DecoyMassShift < Transition.MIN_PRODUCT_DECOY_MASS_SHIFT))) break; } }
private void RunMultiplePeptidesSameMz(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules) { if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none) TestDirectoryName = asSmallMolecules.ToString(); TestSmallMolecules = false; // Don't need the magic test node, we have an explicit test var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath; SrmDocument document = InitMultiplePeptidesSameMzDocument(testFilesDir, out docPath); document = (new RefinementSettings()).ConvertToSmallMolecules(document, asSmallMolecules); var docContainer = new ResultsTestDocumentContainer(document, docPath); var doc = docContainer.Document; var listChromatograms = new List<ChromatogramSet>(); var path = MsDataFileUri.Parse(@"AMultiplePeptidesSameMz\ljz_20131201k_Newvariant_standards_braf.mzML"); listChromatograms.Add(AssertResult.FindChromatogramSet(doc, path) ?? new ChromatogramSet(path.GetFileName().Replace('.', '_'), new[] { path })); var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); document = docContainer.Document; float tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance; var results = document.Settings.MeasuredResults; foreach (var pair in document.MoleculePrecursorPairs) { ChromatogramGroupInfo[] chromGroupInfo; Assert.IsTrue(results.TryLoadChromatogram(0, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroupInfo)); Assert.AreEqual(1, chromGroupInfo.Length); // without the fix, only the first pair will have a chromatogram } // now drill down for specific values int nPeptides = 0; foreach (var nodePep in document.Molecules.Where(nodePep => nodePep.Results[0] != null)) { // expecting three peptide result in this small data set if (nodePep.Results[0].Sum(chromInfo => chromInfo.PeakCountRatio > 0 ? 1 : 0) > 0) { Assert.AreEqual(34.2441024780273,(double)nodePep.GetMeasuredRetentionTime(0), .0001); nPeptides++; } } Assert.AreEqual(3, nPeptides); // without the fix this will give just one result // Release file handles docContainer.Release(); testFilesDir.Dispose(); }
public void FileTypeTest() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string extWiff = ExtensionTestContext.ExtAbWiff; string suffix = ExtensionTestContext.CanImportAbWiff ? "" : "-test"; // Do file type checks using (var msData = new MsDataFileImpl(testFilesDir.GetTestPath("051309_digestion" + suffix + extWiff))) { Assert.IsTrue(msData.IsABFile); } using (var msData = new MsDataFileImpl(testFilesDir.GetTestPath("051309_digestion-s3.mzXML"))) { Assert.IsTrue(msData.IsABFile); Assert.IsTrue(msData.IsMzWiffXml); } }
public void TestCurrentXmlFormat() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); var doc08Path = testFilesDir.GetTestPath("Study7_for_xml_validation.sky"); var docCurrentPath = testFilesDir.GetTestPath("Study7_for_xml_validation_current.sky"); // Test schema validation. var assembly = Assembly.GetAssembly(typeof(AssertEx)); var stream = assembly.GetManifestResourceStream( typeof(AssertEx).Namespace + String.Format(CultureInfo.InvariantCulture, ".Schemas.Skyline_{0}.xsd", SrmDocument.FORMAT_VERSION)); // Not L10N TestSchemaValidation(stream, doc08Path, docCurrentPath); // Check explicit and implicit modifications in the current format. TestPeptideModifications(docCurrentPath); // Import a results file and check instrument information written out to the xml document. var resultsPath = testFilesDir.GetTestPath("CE_Vantage_15mTorr_0001_REP1_01.mzML"); TestInstrumentInfo(resultsPath, docCurrentPath); }
public void TestInstrumentInfo() { const string testZipPath = @"TestA\PwizFileInfoTest.zip"; var testFilesDir = new TestFilesDir(TestContext, testZipPath); // Waters file (.raw directory) and mz5 equivalent foreach ( var ext in new[] {ExtensionTestContext.ExtWatersRaw, ExtensionTestContext.ExtMz5}) { VerifyInstrumentInfo(testFilesDir.GetTestPath("160109_Mix1_calcurve_075" + ext), "Waters instrument model", "", "", ""); } // ABI .wiff file if (ExtensionTestContext.CanImportAbWiff) { VerifyInstrumentInfo(testFilesDir.GetTestPath("051309_digestion.wiff"), "4000 QTRAP", "electrospray ionization", "quadrupole/quadrupole/axial ejection linear ion trap", "electron multiplier"); } // MzWiff generated mzXML files VerifyInstrumentInfo(testFilesDir.GetTestPath("051309_digestion-s3.mzXML"), "4000 Q Trap", "electrospray ionization", "TOFMS", ""); // Agilent file (.d directory) VerifyInstrumentInfo(testFilesDir.GetTestPath("081809_100fmol-MichromMix-05" + ExtensionTestContext.ExtAgilentRaw), "Agilent instrument model", "nanoelectrospray", "quadrupole/quadrupole/quadrupole", "electron multiplier"); // Thermo .raw|mzML file foreach ( var ext in new[] {ExtensionTestContext.ExtThermoRaw, ExtensionTestContext.ExtMzml}) { VerifyInstrumentInfo(testFilesDir.GetTestPath("CE_Vantage_15mTorr_0001_REP1_01" + ext), "TSQ Vantage", "nanoelectrospray", "quadrupole/quadrupole/quadrupole", "electron multiplier"); } }
public void ChromatogramExportTest() { var testFilesDir = new TestFilesDir(TestContext, TEST_ZIP_PATH); string chromExportDoc = testFilesDir.GetTestPath("ChromToExport.sky"); string fileExpected1 = testFilesDir.GetTestPathLocale(EXPORT_1); string fileActual1 = GetActualName(fileExpected1); string fileExpected2 = testFilesDir.GetTestPathLocale(EXPORT_2); string fileActual2 = GetActualName(fileExpected2); string fileExpectedAll = testFilesDir.GetTestPathLocale(EXPORT_ALL); string fileActualAll = GetActualName(fileExpectedAll); SrmDocument doc = ResultsUtil.DeserializeDocument(chromExportDoc); // Load an empty doc, so that we can make a change and // cause the .skyd to be loaded var docContainer = new ResultsTestDocumentContainer(null, chromExportDoc); docContainer.SetDocument(doc, null, true); docContainer.AssertComplete(); SrmDocument docResults = docContainer.Document; if (IsSaveAll) { // For regenerating all of the required expected files, if things change SaveChrom(docResults, testFilesDir.GetTestPath(EXPORT_1), FILE_NAMES_1.ToList(), CultureInfo.GetCultureInfo("en-US"), EXTRACTOR_1, SOURCES_1); SaveChrom(docResults, testFilesDir.GetTestPath(EXPORT_2), FILE_NAMES_2.ToList(), CultureInfo.GetCultureInfo("en-US"), EXTRACTOR_2, SOURCES_2); SaveChrom(docResults, testFilesDir.GetTestPath(EXPORT_ALL), FILE_NAMES_ALL.ToList(), CultureInfo.GetCultureInfo("en-US"), EXTRACTOR_ALL, SOURCES_ALL); SaveChrom(docResults, testFilesDir.GetTestPathIntl(EXPORT_1), FILE_NAMES_1.ToList(), CultureInfo.GetCultureInfo("fr-FR"), EXTRACTOR_1, SOURCES_1); SaveChrom(docResults, testFilesDir.GetTestPathIntl(EXPORT_2), FILE_NAMES_2.ToList(), CultureInfo.GetCultureInfo("fr-FR"), EXTRACTOR_2, SOURCES_2); SaveChrom(docResults, testFilesDir.GetTestPathIntl(EXPORT_ALL), FILE_NAMES_ALL.ToList(), CultureInfo.GetCultureInfo("fr-FR"), EXTRACTOR_ALL, SOURCES_ALL); } SaveChrom(docResults, fileActual1, FILE_NAMES_1.ToList(), LocalizationHelper.CurrentCulture, EXTRACTOR_1, SOURCES_1); SaveChrom(docResults, fileActual2, FILE_NAMES_2.ToList(), LocalizationHelper.CurrentCulture, EXTRACTOR_2, SOURCES_2); SaveChrom(docResults, fileActualAll, FILE_NAMES_ALL.ToList(), LocalizationHelper.CurrentCulture, EXTRACTOR_ALL, SOURCES_ALL); AssertEx.FileEquals(fileExpected1, fileActual1); AssertEx.FileEquals(fileExpected2, fileActual2); AssertEx.FileEquals(fileExpectedAll, fileActualAll); // Close the .skyd file docContainer.Release(); }
private void DoTestImportSim(bool asSmallMolecules) { TestSmallMolecules = false; // Don't need that magic extra node var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath(DOCUMENT_NAME); string cachePath = ChromatogramCache.FinalPathForName(docPath, null); FileEx.SafeDelete(cachePath); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); var pepdoc = doc; if (asSmallMolecules) { var refine = new RefinementSettings(); doc = refine.ConvertToSmallMolecules(pepdoc); } var docContainer = new ResultsTestDocumentContainer(doc, docPath); // Import the mzML file and verify Mz range Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME), 510, 512); Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME2), 555, 557); }
/// <summary> /// Tests our ability to discover drift times by inspecting loaded results /// </summary> private void TestMeasuredDriftTimes() { var testFilesDir = new TestFilesDir(TestContext, @"Test\Results\BlibDriftTimeTest.zip"); // Re-used from BlibDriftTimeTest // Open document with some peptides but no results var documentFile = TestFilesDir.GetTestPath(@"..\BlibDriftTimeTest\BlibDriftTimeTest.sky"); WaitForCondition(() => File.Exists(documentFile)); RunUI(() => SkylineWindow.OpenFile(documentFile)); WaitForDocumentLoaded(); var doc = SkylineWindow.Document; // Import an mz5 file that contains drift info ImportResultsFile(testFilesDir.GetTestPath(@"..\BlibDriftTimeTest\ID12692_01_UCA168_3727_040714.mz5")); // Verify ability to extract predictions from raw data var peptideSettingsDlg = ShowDialog<PeptideSettingsUI>( () => SkylineWindow.ShowPeptideSettingsUI(PeptideSettingsUI.TABS.Prediction)); // Simulate user picking Add... from the Drift Time Predictor combo control var driftTimePredictorDlg = ShowDialog<EditDriftTimePredictorDlg>(peptideSettingsDlg.AddDriftTimePredictor); const string predictorName = "TestMeasuredDriftTimes"; const double resolvingPower = 123.4; RunUI(() => { driftTimePredictorDlg.SetResolvingPower(resolvingPower); driftTimePredictorDlg.SetPredictorName(predictorName); driftTimePredictorDlg.GetDriftTimesFromResults(); driftTimePredictorDlg.OkDialog(); }); WaitForClosedForm(driftTimePredictorDlg); var pepSetDlg = peptideSettingsDlg; RunUI(() => { pepSetDlg.OkDialog(); }); WaitForClosedForm(peptideSettingsDlg); doc = WaitForDocumentChange(doc); var result = doc.Settings.PeptideSettings.Prediction.DriftTimePredictor.MeasuredDriftTimePeptides; Assert.AreEqual(2, result.Count); var key3 = new LibKey("GLAGVENVTELKK", 3); var key2 = new LibKey("GLAGVENVTELKK", 2); const double expectedDT3= 4.0709; const double expectedOffset3 = 0.8969; Assert.AreEqual(expectedDT3, result[key3].DriftTimeMsec(false).Value, .001); Assert.AreEqual(expectedOffset3, result[key3].HighEnergyDriftTimeOffsetMsec, .001); // High energy offset const double expectedDT2 = 5.5889; const double expectedOffset2 = -1.1039; Assert.AreEqual(expectedDT2, result[key2].DriftTimeMsec(false).Value, .001); Assert.AreEqual(expectedOffset2, result[key2].HighEnergyDriftTimeOffsetMsec, .001); // High energy offset WaitForDocumentLoaded(); // Verify exception handling by deleting the msdata file File.Delete(testFilesDir.GetTestPath(@"..\BlibDriftTimeTest\ID12692_01_UCA168_3727_040714.mz5")); peptideSettingsDlg = ShowDialog<PeptideSettingsUI>( () => SkylineWindow.ShowPeptideSettingsUI(PeptideSettingsUI.TABS.Prediction)); var driftTimePredictorDoomedDlg = ShowDialog<EditDriftTimePredictorDlg>(peptideSettingsDlg.AddDriftTimePredictor); RunUI(() => { driftTimePredictorDoomedDlg.SetResolvingPower(resolvingPower); driftTimePredictorDoomedDlg.SetPredictorName(predictorName+"_doomed"); }); RunDlg<MessageDlg>(driftTimePredictorDoomedDlg.GetDriftTimesFromResults, messageDlg => { AssertEx.AreComparableStrings( Resources.DriftTimeFinder_HandleLoadScanException_Problem_using_results_to_populate_drift_time_library__, messageDlg.Message); messageDlg.OkDialog(); }); RunUI(() => driftTimePredictorDoomedDlg.CancelDialog()); WaitForClosedForm(driftTimePredictorDoomedDlg); RunUI(() => { peptideSettingsDlg.OkDialog(); }); WaitForClosedForm(peptideSettingsDlg); }
protected override void DoTest() { using (var testFilesDir = new TestFilesDir(TestContext, TestFilesZip)) { const double HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC = -.1; // do a few unit tests on the UI error handlers TestGetIonMobilityDBErrorHandling(testFilesDir); TestImportIonMobilityFromSpectralLibraryErrorHandling(); TestEditIonMobilityLibraryDlgErrorHandling(); TestEditDriftTimePredictorDlgErrorHandling(); // Now exercise the UI var goodPeptide = new ValidatingIonMobilityPeptide("SISIVGSYVGNR", 133.3210342, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC); Assert.IsNull(goodPeptide.Validate()); var badPeptides = new[] { new ValidatingIonMobilityPeptide("@#$!", 133.3210342, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("SISIVGSYVGNR", 0, 0), new ValidatingIonMobilityPeptide("SISIVGSYVGNR", -133.3210342, -HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), }; foreach (var badPeptide in badPeptides) { Assert.IsNotNull(badPeptide.Validate()); } var ionMobilityPeptides = new[] { new ValidatingIonMobilityPeptide("SISIVGSYVGNR",133.3210342, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), // These are made-up values new ValidatingIonMobilityPeptide("SISIVGSYVGNR",133.3210342, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("CCSDVFNQVVK",131.2405487, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("CCSDVFNQVVK",131.2405487, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("ANELLINVK",119.2825783, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("ANELLINVK",119.2825783, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("EALDFFAR",110.6867676, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("EALDFFAR",110.6867676, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("GVIFYESHGK",123.7844632, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("GVIFYESHGK",123.7844632, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("EKDIVGAVLK",124.3414249, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("EKDIVGAVLK",124.3414249, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("VVGLSTLPEIYEK",149.857687, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("VVGLSTLPEIYEK",149.857687, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("VVGLSTLPEIYEK",149.857687, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("ANGTTVLVGMPAGAK",144.7461979, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("ANGTTVLVGMPAGAK",144.7461979, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("IGDYAGIK", 102.2694763, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("IGDYAGIK", 102.2694763, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("GDYAGIK", 91.09155861, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("GDYAGIK", 91.09155861, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("IFYESHGK",111.2756406, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), new ValidatingIonMobilityPeptide("EALDFFAR",110.6867676, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), }; List<ValidatingIonMobilityPeptide> minimalSet; var message = EditIonMobilityLibraryDlg.ValidateUniqueChargedPeptides(ionMobilityPeptides, out minimalSet); // Check for conflicts, strip out dupes Assert.IsNull(message, "known good data set failed import"); Assert.AreEqual(11, minimalSet.Count, "known good data imported but with wrong result count"); var save = ionMobilityPeptides[0].CollisionalCrossSection; ionMobilityPeptides[0].CollisionalCrossSection += 1.0; // Same sequence and charge, different cross section message = EditIonMobilityLibraryDlg.ValidateUniqueChargedPeptides(ionMobilityPeptides, out minimalSet); // Check for conflicts, strip out dupes Assert.IsNotNull(message, message); Assert.IsNull(minimalSet, "bad inputs to drift time library paste should be rejected wholesale"); ionMobilityPeptides[0].CollisionalCrossSection = save; // restore // Present the Prediction tab of the peptide settings dialog var peptideSettingsDlg1 = ShowDialog<PeptideSettingsUI>( () => SkylineWindow.ShowPeptideSettingsUI(PeptideSettingsUI.TABS.Prediction)); // Simulate picking "Add..." from the Ion Mobility Libraries button context menu var ionMobilityLibDlg1 = ShowDialog<EditIonMobilityLibraryDlg>(peptideSettingsDlg1.AddIonMobilityLibrary); // Simulate user pasting in collisional cross section data to create a new drift time library const string testlibName = "testlib"; string databasePath = testFilesDir.GetTestPath(testlibName + IonMobilityDb.EXT); RunUI(() => { string libraryText = BuildPasteLibraryText(ionMobilityPeptides, seq => seq.Substring(0, seq.Length - 1)); ionMobilityLibDlg1.LibraryName = testlibName; ionMobilityLibDlg1.CreateDatabase(databasePath); SetClipboardText(libraryText); ionMobilityLibDlg1.DoPasteLibrary(); ionMobilityLibDlg1.OkDialog(); }); WaitForClosedForm(ionMobilityLibDlg1); RunUI(peptideSettingsDlg1.OkDialog); WaitForClosedForm(peptideSettingsDlg1); // Use that drift time database in a differently named library const string testlibName2 = "testlib2"; var peptideSettingsDlg2 = ShowDialog<PeptideSettingsUI>( () => SkylineWindow.ShowPeptideSettingsUI(PeptideSettingsUI.TABS.Prediction)); // Simulate user picking Add... from the Drift Time Predictor combo control var driftTimePredictorDlg = ShowDialog<EditDriftTimePredictorDlg>(peptideSettingsDlg2.AddDriftTimePredictor); // ... and reopening an existing drift time database var ionMobility = ShowDialog<EditIonMobilityLibraryDlg>(driftTimePredictorDlg.AddIonMobilityLibrary); RunUI(() => { ionMobility.LibraryName = testlibName2; ionMobility.OpenDatabase(databasePath); ionMobility.OkDialog(); }); WaitForClosedForm(ionMobility); // Set other parameters - name, resolving power, per-charge slope+intercept const string predictorName = "test"; const double resolvingPower = 123.4; RunUI(() => { driftTimePredictorDlg.SetResolvingPower(resolvingPower); driftTimePredictorDlg.SetPredictorName(predictorName); SetClipboardText("1\t2\t3\n2\t4\t5"); // Silly values: z=1 s=2 i=3, z=2 s=4 i=5 driftTimePredictorDlg.PasteRegressionValues(); }); var olddoc = SkylineWindow.Document; RunUI(() => { // Go back to the first library we created driftTimePredictorDlg.ChooseIonMobilityLibrary(testlibName); driftTimePredictorDlg.OkDialog(); var docUI = SkylineWindow.DocumentUI; if (docUI != null) SetUiDocument(docUI.ChangeSettings(docUI.Settings.ChangePeptideSettings( docUI.Settings.PeptideSettings.ChangePrediction( docUI.Settings.PeptideSettings.Prediction.ChangeDriftTimePredictor(driftTimePredictorDlg.Predictor))))); }); WaitForClosedForm(driftTimePredictorDlg); RunUI(peptideSettingsDlg2.OkDialog); /* * Check that the database was created successfully * Check that it has the correct number peptides */ IonMobilityDb db = IonMobilityDb.GetIonMobilityDb(databasePath, null); Assert.AreEqual(11, db.GetPeptides().Count()); WaitForDocumentChange(olddoc); // Check serialization and background loader WaitForDocumentLoaded(); RunUI(() => { SkylineWindow.SaveDocument(TestContext.GetTestPath("test.sky")); SkylineWindow.NewDocument(); SkylineWindow.OpenFile(TestContext.GetTestPath("test.sky")); }); var doc = WaitForDocumentLoaded(); // Verify that the schema has been updated to include these new settings AssertEx.ValidatesAgainstSchema(doc); // Do some DT calculations double windowDT; DriftTimeInfo centerDriftTime = doc.Settings.PeptideSettings.Prediction.GetDriftTimeHelper( new LibKey("ANELLINV", 2), null, out windowDT); Assert.AreEqual((4 * (119.2825783)) + 5, centerDriftTime.DriftTimeMsec(false)); Assert.AreEqual(2 * ((4 * (119.2825783)) + 5)/resolvingPower, windowDT); Assert.AreEqual((4 * (119.2825783)) + 5 + HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC, centerDriftTime.DriftTimeMsec(true)); // // Test importing collisional cross sections from a spectral lib that has drift times but no high energy offset info // var peptideSettingsUI = ShowDialog<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI); const string libname = "libIMS"; var blibPath = TestContext.GetTestPath("IonMobilityTest\\mse-mobility.filtered-scaled.blib"); var editListUI = ShowDialog<EditListDlg<SettingsListBase<LibrarySpec>, LibrarySpec>>(peptideSettingsUI.EditLibraryList); RunDlg<EditLibraryDlg>(editListUI.AddItem, editLibraryDlg => { editLibraryDlg.LibrarySpec = new BiblioSpecLibSpec(libname, blibPath); editLibraryDlg.OkDialog(); }); OkDialog(editListUI, editListUI.OkDialog); RunUI(() => peptideSettingsUI.PickedLibraries = new[] { libname }); // Check error cases for resolving power (caused unexpected excption) RunUI(() => { peptideSettingsUI.IsUseSpectralLibraryDriftTimes = true; peptideSettingsUI.SpectralLibraryDriftTimeResolvingPower = null; }); RunDlg<MessageDlg>(peptideSettingsUI.OkDialog, dlg => { AssertEx.AreComparableStrings(Resources.MessageBoxHelper_ValidateDecimalTextBox__0__must_contain_a_decimal_value, dlg.Message); dlg.OkDialog(); }); RunUI(() => peptideSettingsUI.SpectralLibraryDriftTimeResolvingPower = 0); RunDlg<MessageDlg>(peptideSettingsUI.OkDialog, dlg => { Assert.AreEqual(Resources.EditDriftTimePredictorDlg_ValidateResolvingPower_Resolving_power_must_be_greater_than_0_, dlg.Message); dlg.OkDialog(); }); RunUI(() => peptideSettingsUI.IsUseSpectralLibraryDriftTimes = false); OkDialog(peptideSettingsUI, peptideSettingsUI.OkDialog); WaitForDocumentLoaded(); // Let that library load // In this lib: ANGTTVLVGMPAGAK at z=2, with drift time 4.99820623749102 // and, a single CCS value, for ANELLINVK, which is 3.8612432898618 // Present the Prediction tab of the peptide settings dialog var peptideSettingsDlg3 = ShowDialog<PeptideSettingsUI>( () => SkylineWindow.ShowPeptideSettingsUI(PeptideSettingsUI.TABS.Prediction)); // Simulate picking "Add..." from the Drift Time Predictor combo control var driftTimePredictorDlg3 = ShowDialog<EditDriftTimePredictorDlg>(peptideSettingsDlg3.AddDriftTimePredictor); const double deadeelsDT = 3.456; const double deadeelsDTHighEnergyOffset = -0.1; var threeCols = "DEADEELS\t5\t" + deadeelsDT.ToString(CultureInfo.CurrentCulture); var fourCols = "DEADEELS\t5\t" + deadeelsDT.ToString(CultureInfo.CurrentCulture) + "\t" + deadeelsDTHighEnergyOffset.ToString(CultureInfo.CurrentCulture); RunUI(() => { driftTimePredictorDlg3.SetResolvingPower(resolvingPower); driftTimePredictorDlg3.SetPredictorName("test3"); SetClipboardText("1\t2\t3\n2\t4\t5"); // Silly values: z=1 s=2 i=3, z=2 s=4 i=5 driftTimePredictorDlg3.PasteRegressionValues(); // Simulate user pasting in some measured drift time info without high energy offset, even though its enabled - should not throw driftTimePredictorDlg3.SetOffsetHighEnergySpectraCheckbox(true); SetClipboardText(threeCols); driftTimePredictorDlg3.PasteMeasuredDriftTimes(); // Simulate user pasting in some measured drift time info with high energy offset SetClipboardText(fourCols); driftTimePredictorDlg3.PasteMeasuredDriftTimes(); // Now turn off the high energy column and paste in four columns - should fail driftTimePredictorDlg3.SetOffsetHighEnergySpectraCheckbox(false); SetClipboardText(fourCols); }); // An error will appear because the column count is wrong ShowDialog<MessageDlg>(driftTimePredictorDlg3.PasteMeasuredDriftTimes); var errorDlg = WaitForOpenForm<MessageDlg>(); Assert.AreEqual(string.Format(Resources.SettingsUIUtil_DoPasteText_Incorrect_number_of_columns__0__found_on_line__1__, 4, 1), errorDlg.Message); errorDlg.OkDialog(); RunUI(() => { // And now paste in three columns, should be OK SetClipboardText(threeCols); driftTimePredictorDlg3.PasteMeasuredDriftTimes(); // Finally turn the high energy column back on, and put in a value driftTimePredictorDlg3.SetOffsetHighEnergySpectraCheckbox(true); SetClipboardText(fourCols); driftTimePredictorDlg3.PasteMeasuredDriftTimes(); }); // Simulate picking "Add..." from the Ion Mobility Library combo control var ionMobilityLibDlg3 = ShowDialog<EditIonMobilityLibraryDlg>(driftTimePredictorDlg3.AddIonMobilityLibrary); const string testlibName3 = "testlib3"; string databasePath3 = testFilesDir.GetTestPath(testlibName3 + IonMobilityDb.EXT); RunUI(() => { ionMobilityLibDlg3.LibraryName = testlibName3; ionMobilityLibDlg3.CreateDatabase(databasePath3); }); // Simulate pressing "Import" button from the Edit Ion Mobility Library dialog var importSpectralLibDlg = ShowDialog<ImportIonMobilityFromSpectralLibraryDlg>(ionMobilityLibDlg3.ImportFromSpectralLibrary); RunUI(() => { // Set up to fail - don't provide z=2 info importSpectralLibDlg.Source = SpectralLibrarySource.settings; // Simulate user selecting 1st radio button SetClipboardText("1\t1\t0"); // This will fail - no z=2 information importSpectralLibDlg.PasteRegressionValues(); }); importSpectralLibDlg.BeginInvoke(new Action(importSpectralLibDlg.OkDialog)); // User clicks OK - we expect an error dialog to follow WaitForOpenForm<MessageDlg>().OkDialog(); // Dismiss the error message, we'll be dropped back into the dialog RunUI(() => { importSpectralLibDlg.Source = SpectralLibrarySource.file; // Simulate user selecting 2nd radio button importSpectralLibDlg.FilePath = blibPath; // Simulate user entering filename SetClipboardText("1\t1\t0\n2\t2\t2"); // Note non-unity slope and charge for z=2, for test purposes importSpectralLibDlg.PasteRegressionValues(); importSpectralLibDlg.OkDialog(); }); WaitForClosedForm(importSpectralLibDlg); WaitForCondition(() => ionMobilityLibDlg3.LibraryPeptideCount > 8); // Let that library load RunUI(ionMobilityLibDlg3.OkDialog); WaitForClosedForm(ionMobilityLibDlg3); RunUI(driftTimePredictorDlg3.OkDialog); WaitForClosedForm(driftTimePredictorDlg3); RunUI(peptideSettingsDlg3.OkDialog); WaitForClosedForm(peptideSettingsDlg3); doc = WaitForDocumentChangeLoaded(doc); // Let that library load // Do some DT calculations with this new library centerDriftTime = doc.Settings.PeptideSettings.Prediction.GetDriftTimeHelper( new LibKey("ANELLINVK", 2), null, out windowDT); double ccs = 3.8612432898618; // should have imported CCS without any transformation Assert.AreEqual((4 * (ccs)) + 5, centerDriftTime.DriftTimeMsec(false) ?? ccs, .000001); Assert.AreEqual(2 * ((4 * (ccs)) + 5) / resolvingPower, windowDT, .000001); centerDriftTime = doc.Settings.PeptideSettings.Prediction.GetDriftTimeHelper( new LibKey("ANGTTVLVGMPAGAK", 2), null, out windowDT); ccs = (4.99820623749102 - 2)/2; // should have imported CCS as a converted drift time Assert.AreEqual((4 * (ccs)) + 5, centerDriftTime.DriftTimeMsec(false) ?? ccs, .000001); Assert.AreEqual(2 * ((4 * (ccs)) + 5) / resolvingPower, windowDT, .000001); // Do some DT calculations with the measured drift time centerDriftTime = doc.Settings.PeptideSettings.Prediction.GetDriftTimeHelper( new LibKey("DEADEELS", 3), null, out windowDT); // Should fail Assert.AreEqual(windowDT, 0); Assert.IsFalse(centerDriftTime.DriftTimeMsec(false).HasValue); centerDriftTime = doc.Settings.PeptideSettings.Prediction.GetDriftTimeHelper( new LibKey("DEADEELS", 5), null, out windowDT); Assert.AreEqual(deadeelsDT, centerDriftTime.DriftTimeMsec(false) ?? -1, .000001); Assert.AreEqual(deadeelsDT+deadeelsDTHighEnergyOffset, centerDriftTime.DriftTimeMsec(true) ?? -1, .000001); Assert.AreEqual(2 * (deadeelsDT / resolvingPower), windowDT, .0001); // Directly measured, should match // Now check handling of scenario where user pastes in high energy offsets then unchecks the "Use High Energy Offsets" box var peptideSettingsDlg4 = ShowDialog<PeptideSettingsUI>( () => SkylineWindow.ShowPeptideSettingsUI(PeptideSettingsUI.TABS.Prediction)); // Simulate picking "Edit Current..." from the Drift Time Predictor combo control var driftTimePredictorDlg4 = ShowDialog<EditDriftTimePredictorDlg>(peptideSettingsDlg4.EditDriftTimePredictor); RunUI(() => { Assert.IsTrue(driftTimePredictorDlg4.GetOffsetHighEnergySpectraCheckbox()); // Should start out enabled if we have offsets driftTimePredictorDlg4.SetOffsetHighEnergySpectraCheckbox(false); // Turn off the high energy offset column driftTimePredictorDlg4.SetPredictorName("test4"); }); RunUI(driftTimePredictorDlg4.OkDialog); WaitForClosedForm(driftTimePredictorDlg4); RunUI(peptideSettingsDlg4.OkDialog); WaitForClosedForm(peptideSettingsDlg4); doc = WaitForDocumentChangeLoaded(doc); centerDriftTime = doc.Settings.PeptideSettings.Prediction.GetDriftTimeHelper( new LibKey("DEADEELS", 5), null, out windowDT); Assert.AreEqual(deadeelsDT, centerDriftTime.DriftTimeMsec(false) ?? -1, .000001); Assert.AreEqual(deadeelsDT, centerDriftTime.DriftTimeMsec(true) ?? -1, .000001); // High energy value should now be same as low energy value Assert.AreEqual(2 * (deadeelsDT / resolvingPower), windowDT, .0001); // Directly measured, should match // Now make sure that high energy checkbox initial state is as we expect var peptideSettingsDlg5 = ShowDialog<PeptideSettingsUI>( () => SkylineWindow.ShowPeptideSettingsUI(PeptideSettingsUI.TABS.Prediction)); // Simulate picking "Edit Current..." from the Drift Time Predictor combo control var driftTimePredictorDlg5 = ShowDialog<EditDriftTimePredictorDlg>(peptideSettingsDlg5.EditDriftTimePredictor); RunUI(() => Assert.IsFalse(driftTimePredictorDlg5.GetOffsetHighEnergySpectraCheckbox())); RunUI(driftTimePredictorDlg5.CancelDialog); WaitForClosedForm(driftTimePredictorDlg5); RunUI(peptideSettingsDlg5.OkDialog); WaitForClosedForm(peptideSettingsDlg5); } TestMeasuredDriftTimes(); }
/// <summary> /// Test various error conditions in IonMobilityDb.cs /// </summary> public void TestGetIonMobilityDBErrorHandling(TestFilesDir testFilesDir) { AssertEx.ThrowsException<DatabaseOpeningException>(() => IonMobilityDb.GetIonMobilityDb(null, null), Resources.IonMobilityDb_GetIonMobilityDb_Please_provide_a_path_to_an_existing_ion_mobility_library_); const string badfilename = "nonexistent_file.imdb"; AssertEx.ThrowsException<DatabaseOpeningException>( () => IonMobilityDb.GetIonMobilityDb(badfilename, null), String.Format( Resources.IonMobilityDb_GetIonMobilityDb_The_ion_mobility_library_file__0__could_not_be_found__Perhaps_you_did_not_have_sufficient_privileges_to_create_it_, badfilename)); string bogusfile = testFilesDir.GetTestPath("bogus.imdb"); using (FileStream fs = File.Create(bogusfile)) { Byte[] info = new UTF8Encoding(true).GetBytes("This is a bogus file."); fs.Write(info, 0, info.Length); } AssertEx.ThrowsException<DatabaseOpeningException>( () => IonMobilityDb.GetIonMobilityDb(bogusfile, null), String.Format( Resources.IonMobilityDb_GetIonMobilityDb_The_file__0__is_not_a_valid_ion_mobility_library_file_, bogusfile)); }
public void ConsoleImportPeptideSearchTest() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); var docPath = testFilesDir.GetTestPath("blank.sky"); var outPath = testFilesDir.GetTestPath("import-search.sky"); var searchFilePath = testFilesDir.GetTestPath("CAexample.pep.xml"); var fastaPath = testFilesDir.GetTestPath("bov-5-prot.fasta"); // with mods and invalid cutoff score const string badCutoff = "1.1"; var output = RunCommand("--in=" + docPath, "--out=" + outPath, "--import-search-file=" + searchFilePath, "--import-search-cutoff-score=" + badCutoff, "--import-search-add-mods", "--import-fasta=" + fastaPath); AssertEx.Contains(output, string.Format( Resources.CommandArgs_ParseArgsInternal_Warning__The_cutoff_score__0__is_invalid__It_must_be_a_value_between_0_and_1_, badCutoff)); AssertEx.Contains(output, TextUtil.LineSeparate(Resources.CommandLine_ImportSearch_Creating_spectral_library_from_files_, Path.GetFileName(searchFilePath))); AssertEx.Contains(output, string.Format(Resources.CommandLine_ImportSearch_Adding__0__modifications_, 2)); AssertEx.Contains(output, string.Format(Resources.CommandLine_ImportFasta_Importing_FASTA_file__0____, Path.GetFileName(fastaPath))); var doc = ResultsUtil.DeserializeDocument(outPath); Assert.IsTrue(doc.Settings.HasResults); Assert.AreEqual(1, doc.Settings.MeasuredResults.Chromatograms.Count); Assert.IsTrue(doc.Settings.MeasuredResults.ContainsChromatogram("CAexample")); Assert.AreEqual(5, doc.PeptideGroupCount); Assert.AreEqual(26, doc.PeptideCount); Assert.AreEqual(26, doc.PeptideTransitionGroupCount); Assert.AreEqual(78, doc.PeptideTransitionCount); // without mods var outPath2 = testFilesDir.GetTestPath("import-search2.sky"); output = RunCommand("--in=" + docPath, "--out=" + outPath2, "--import-search-file=" + searchFilePath, "--import-fasta=" + fastaPath); AssertEx.Contains(output, TextUtil.LineSeparate(Resources.CommandLine_ImportSearch_Creating_spectral_library_from_files_, Path.GetFileName(searchFilePath))); AssertEx.Contains(output, string.Format(Resources.CommandLine_ImportFasta_Importing_FASTA_file__0____, Path.GetFileName(fastaPath))); doc = ResultsUtil.DeserializeDocument(outPath2); Assert.IsTrue(doc.Settings.HasResults); Assert.AreEqual(1, doc.Settings.MeasuredResults.Chromatograms.Count); Assert.IsTrue(doc.Settings.MeasuredResults.ContainsChromatogram("CAexample")); Assert.AreEqual(5, doc.PeptideGroupCount); Assert.AreEqual(23, doc.PeptideCount); Assert.AreEqual(23, doc.PeptideTransitionGroupCount); Assert.AreEqual(69, doc.PeptideTransitionCount); // test setting cutoff and accepting mods when not importing a search output = RunCommand( "--import-search-cutoff-score=" + 0.99, "--import-search-add-mods"); AssertEx.Contains(output, CommandArgs.WarnArgRequirementText(CommandArgs.ARG_IMPORT_PEPTIDE_SEARCH_FILE, CommandArgs.ARG_IMPORT_PEPTIDE_SEARCH_CUTOFF)); AssertEx.Contains(output, CommandArgs.WarnArgRequirementText(CommandArgs.ARG_IMPORT_PEPTIDE_SEARCH_FILE, CommandArgs.ARG_IMPORT_PEPTIDE_SEARCH_MODS)); }
protected override void DoTest() { const int numStandardPeps = 11; const int numLibraryPeps = 18; const string irtCalc = "iRT-C18"; const string ssrCalc = "SSRCalc 3.0 (300A)"; var testFilesDir = new TestFilesDir(TestContext, TestFilesZip); string databasePath = testFilesDir.GetTestPath("irt-c18.irtdb"); string documentPath = testFilesDir.GetTestPath("iRT Test.sky"); RunUI(() => SkylineWindow.OpenFile(documentPath)); var peptideSettingsDlg1 = ShowDialog<PeptideSettingsUI>( () => SkylineWindow.ShowPeptideSettingsUI(PeptideSettingsUI.TABS.Prediction)); var editRT1 = ShowDialog<EditRTDlg>(peptideSettingsDlg1.AddRTRegression); var irtDlg1 = ShowDialog<EditIrtCalcDlg>(editRT1.AddCalculator); RunUI(() => { irtDlg1.CalcName = irtCalc; irtDlg1.CreateDatabase(databasePath); }); var calibratePeptides = new List<MeasuredPeptide>(); /* * Check several error handling cases * Check the peptide choosing algorithm for sanity (correct # peptides) * Check that the info dialog comes up when too many are requested * Check the peptide linear transformation for sanity * Check that the peptides get passed back to EditIrtCalcDlg */ var calibrateDlg = ShowDialog<CalibrateIrtDlg>(irtDlg1.Calibrate); //Check the peptide choosing algorithm int peptideCount = SkylineWindow.Document.PeptideCount; //29 peptides in the document //Use the dialog box UI var countDlg = ShowDialog<AddIrtStandardsDlg>(calibrateDlg.UseResults); RunUI(() => countDlg.StandardCount = CalibrateIrtDlg.MIN_STANDARD_PEPTIDES - 1); RunDlg<MessageDlg>(countDlg.OkDialog, messageDlg => messageDlg.OkDialog()); RunUI(() => { countDlg.StandardCount = peptideCount; countDlg.OkDialog(); }); WaitForClosedForm(countDlg); Assert.AreEqual(peptideCount, calibrateDlg.StandardPeptideCount); //Bypass the UI foreach (int i in new[] { peptideCount, peptideCount/2, CalibrateIrtDlg.MIN_STANDARD_PEPTIDES*2, CalibrateIrtDlg.MIN_STANDARD_PEPTIDES }) { int j = i; RunUI(() => { calibratePeptides = calibrateDlg.Recalculate(SkylineWindow.Document, j); Assert.AreEqual(calibratePeptides.Count, j); Assert.IsNull(FindOpenForm<MessageDlg>()); }); } RunUI(() => { calibrateDlg.Recalculate(SkylineWindow.Document, 11); //After closing this dialog, there should be 3 iRT values below 0 //and 3 above 100 calibrateDlg.SetFixedPoints(3, 7); calibrateDlg.OkDialog(); }); WaitForClosedForm(calibrateDlg); //Now check that the peptides were passed to the EditIrtCalcDlg RunUI(() => { Assert.AreEqual(numStandardPeps, irtDlg1.StandardPeptideCount); //And that there are 3 below 0 and 3 above 100 Assert.AreEqual(3, irtDlg1.StandardPeptides.Count(pep => pep.Irt < 0)); Assert.AreEqual(3, irtDlg1.StandardPeptides.Count(pep => pep.Irt > 100)); irtDlg1.ClearStandardPeptides(); }); /* * Test pasting into EditIrtCalcDlg * Test that the dialog requires the whole standard to be in the document * Test that add results gets everything in the document besides the standard * Test that there were no errors along the way */ //Now paste in iRT with each peptide truncated by one amino acid var standard = new[] { new MeasuredPeptide("LGGNEQVTR", -24.92), new MeasuredPeptide("GAGSSEPVTGLDAK", 0.00), new MeasuredPeptide("VEATFGVDESNAK", 12.39), new MeasuredPeptide("YILAGVENSK", 19.79), new MeasuredPeptide("TPVISGGPYEYR", 28.71), new MeasuredPeptide("TPVITGAPYEYR", 33.38), new MeasuredPeptide("DGLDAASYYAPVR", 42.26), new MeasuredPeptide("ADVTPADFSEWSK", 54.62), new MeasuredPeptide("GTFIIDPGGVIR", 70.52), new MeasuredPeptide("GTFIIDPAAVIR", 87.23), new MeasuredPeptide("LFLQFGAQGSPFLK", 100.00), }; RunUI(() => { string standardText = BuildStandardText(standard, seq => seq.Substring(0, seq.Length - 1)); SetClipboardText(standardText); irtDlg1.DoPasteStandard(); }); // Cannot add results because standard peptides are not in the document RunDlg<MessageDlg>(irtDlg1.AddResults, messageDlg => messageDlg.OkDialog()); // Paste Biognosys-provided values RunUI(() => { string standardText = BuildStandardText(standard, seq => seq); SetClipboardText(standardText); irtDlg1.ClearStandardPeptides(); irtDlg1.DoPasteStandard(); //Check count Assert.AreEqual(numStandardPeps, irtDlg1.StandardPeptideCount); }); //Add results RunDlg<AddIrtPeptidesDlg>(irtDlg1.AddResults, addPeptidesDlg => addPeptidesDlg.OkDialog()); RunUI(() => Assert.AreEqual(numLibraryPeps, irtDlg1.LibraryPeptideCount)); // Recalibrate const int shift = 100; const int skew = 10; RunDlg<RecalibrateIrtDlg>(irtDlg1.Calibrate, recalDlg => { recalDlg.MinIrt = standard[1].RetentionTime + shift; recalDlg.MaxIrt = standard[standard.Length - 1].RetentionTime*skew + shift; recalDlg.FixedPoint1 = standard[1].Sequence; recalDlg.FixedPoint2 = standard[standard.Length - 1].Sequence; recalDlg.OkDialog(); }); RunUI(() => { for (int i = 0; i < irtDlg1.StandardPeptideCount; i++) { Assert.AreEqual(standard[i].RetentionTime*skew + shift, irtDlg1.StandardPeptides.Skip(i).First().Irt); } }); RunDlg<RecalibrateIrtDlg>(irtDlg1.Calibrate, recalDlg => { recalDlg.FixedPoint1 = standard[2].Sequence; recalDlg.FixedPoint2 = standard[standard.Length - 2].Sequence; recalDlg.MinIrt = standard[2].RetentionTime; recalDlg.MaxIrt = standard[standard.Length - 2].RetentionTime; recalDlg.OkDialog(); }); // Change peptides var changePeptides = irtDlg1.LibraryPeptides.Where((p, i) => i%2 == 0).ToArray(); var resetPeptides = irtDlg1.StandardPeptides.ToArray(); RunDlg<ChangeIrtPeptidesDlg>(irtDlg1.ChangeStandardPeptides, changeDlg => { changeDlg.Peptides = changePeptides; changeDlg.OkDialog(); }); Assert.IsTrue(ArrayUtil.EqualsDeep(changePeptides.Select(p => p.Sequence).ToArray(), irtDlg1.StandardPeptides.Select(p => p.Sequence).ToArray())); Assert.IsTrue(ArrayUtil.EqualsDeep(changePeptides.Select(p => p.Irt).ToArray(), irtDlg1.StandardPeptides.Select(p => p.Irt).ToArray())); RunDlg<ChangeIrtPeptidesDlg>(irtDlg1.ChangeStandardPeptides, changeDlg => { changeDlg.Peptides = resetPeptides; changeDlg.OkDialog(); }); OkDialog(irtDlg1, irtDlg1.OkDialog); Assert.IsNull(FindOpenForm<MessageDlg>()); /* * Check that the database was created successfully * Check that it has the correct numbers of standard and library peptides */ IrtDb db = IrtDb.GetIrtDb(databasePath, null); Assert.AreEqual(numStandardPeps, db.StandardPeptideCount); Assert.AreEqual(numLibraryPeps, db.LibraryPeptideCount); /* * Make sure that loading the database brings back up the right numbers of peptides */ //Rather than rigging SettingsListComboDriver, just create a new one and load var irtDlg1A = ShowDialog<EditIrtCalcDlg>(editRT1.AddCalculator); RunDlg<MessageDlg>(() => irtDlg1A.OpenDatabase(testFilesDir.GetTestPath("bogus.irtdb")), messageDlg => messageDlg.OkDialog()); //There was a _bug_ where opening a path and then clicking OK would save all the peptides //twice, doubling the size of the database. So check that that is fixed. EditIrtCalcDlgPepCountTest(irtDlg1A, numStandardPeps, numLibraryPeps, databasePath, false); EditIrtCalcDlgPepCountTest(ShowDialog<EditIrtCalcDlg>(editRT1.AddCalculator), numStandardPeps, numLibraryPeps, databasePath, false); EditIrtCalcDlgPepCountTest(ShowDialog<EditIrtCalcDlg>(editRT1.AddCalculator), numStandardPeps, numLibraryPeps, databasePath, true); EditIrtCalcDlgPepCountTest(ShowDialog<EditIrtCalcDlg>(editRT1.AddCalculator), numStandardPeps, numLibraryPeps, databasePath, false); /* * Create a regression based on the new calculator * Create a regression based on SSRCalc * Open the graph * Switch to new calculator, verify r = 1.00 and graph is labeled iRT-C18 * Switch to SSRCalc, verify graph label changes */ RunUI(() => { editRT1.SetRegressionName("iRT Regression"); editRT1.AddResults(); editRT1.ChooseCalculator(irtCalc); editRT1.OkDialog(); }); WaitForClosedForm(editRT1); var editRT1A = ShowDialog<EditRTDlg>(peptideSettingsDlg1.AddRTRegression); RunUI(() => { editRT1A.SetRegressionName("SSRCalc Regression"); editRT1A.AddResults(); editRT1A.ChooseCalculator(ssrCalc); }); RunDlg<RTDetails>(editRT1A.ShowDetails, detailsDlg => detailsDlg.Close()); OkDialog(editRT1A, editRT1A.OkDialog); RunUI(peptideSettingsDlg1.CancelButton.PerformClick); WaitForClosedForm(peptideSettingsDlg1); var docPeptides = new List<MeasuredRetentionTime>(); RunUI(() => { var document = Program.ActiveDocumentUI; foreach (var docPepNode in document.Peptides) { docPeptides.Add(new MeasuredRetentionTime(document.Settings.GetModifiedSequence(docPepNode), docPepNode.AverageMeasuredRetentionTime.HasValue ? docPepNode.AverageMeasuredRetentionTime.Value : 0)); } }); RetentionTimeStatistics stats = null; RegressionLineElement line = null; RunUI(() => { SkylineWindow.ShowRTLinearRegressionGraph(); SkylineWindow.SetupCalculatorChooser(); SkylineWindow.ChooseCalculator(irtCalc); stats = SkylineWindow.RTGraphController.RegressionRefined.CalcStatistics(docPeptides, null); line = SkylineWindow.RTGraphController.RegressionRefined.Conversion; }); Assert.IsNotNull(stats); Assert.IsTrue(stats.R > 0.999); Assert.IsNotNull(line); //These values were taken from the graph, which shows values to 2 decimal places, so the real values must //be +/- 0.01 from these values Assert.IsTrue(Math.Abs(line.Intercept - 14.17) < 0.01); Assert.IsTrue(Math.Abs(line.Slope - 0.15) < 0.01); RunUI(() => { SkylineWindow.ChooseCalculator(ssrCalc); stats = SkylineWindow.RTGraphController.RegressionRefined.CalcStatistics(docPeptides, null); }); Assert.IsNotNull(stats); Assert.IsTrue(Math.Abs(stats.R - 0.97) < 0.01); /* * Delete all peptides except the standard * Create a new calculator with the document standard (instead of pasting) * Create a regression with that calculator * Export a transition list using measured retention times * Export a method using predicted retention times * Test that they are identical */ //Delete from the document all but the last protein, which has all the standard peptides RunUI(() => { SkylineWindow.CollapseProteins(); var seqTree = SkylineWindow.SequenceTree; seqTree.SelectedNode = seqTree.Nodes[0]; seqTree.KeysOverride = Keys.Shift; seqTree.SelectedNode = seqTree.Nodes[17]; SkylineWindow.EditDelete(); }); //Peptide settings dialog -> Add a regression var peptideSettingsDlg2 = ShowDialog<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI); var editRT2 = ShowDialog<EditRTDlg>(peptideSettingsDlg2.AddRTRegression); //Set regression name RunUI(() => editRT2.SetRegressionName("iRT Document Regression")); //Regression dialog -> add a calculator var irtDlg2 = ShowDialog<EditIrtCalcDlg>(editRT2.AddCalculator); //Set calc name, database RunUI(() => { irtDlg2.CalcName = "iRT Document Calculator"; irtDlg2.CreateDatabase(testFilesDir.GetTestPath("irt-doc.irtdb")); }); //Calc dialog -> calibrate standard RunDlg<CalibrateIrtDlg>(irtDlg2.Calibrate, calibrateDlg2 => { //Get 11 peptides from the document (all of them) and go back to calculator dialog calibrateDlg2.Recalculate(SkylineWindow.Document, 11); calibrateDlg2.OkDialog(); }); Assert.AreEqual(11, irtDlg2.StandardPeptideCount); Assert.AreEqual(0, irtDlg2.LibraryPeptideCount); // Close dialog to save calculator OkDialog(irtDlg2, irtDlg2.OkDialog); // Test adding irt calculator { var irtDlgAdd = ShowDialog<EditIrtCalcDlg>(editRT2.EditCurrentCalculator); var addDlg = ShowDialog<AddIrtCalculatorDlg>(irtDlgAdd.AddIrtDatabase); // Check error messages RunUI(() => addDlg.Source = IrtCalculatorSource.file); RunDlg<MessageDlg>(addDlg.OkDialog, messageDlg => { Assert.AreEqual(Resources.AddIrtCalculatorDlg_OkDialog_Please_specify_a_path_to_an_existing_iRT_database, messageDlg.Message); messageDlg.OkDialog(); }); RunUI(() => addDlg.FilePath = "not_irtdb.docx"); RunDlg<MessageDlg>(addDlg.OkDialog, messageDlg => { AssertEx.AreComparableStrings(Resources.AddIrtCalculatorDlg_OkDialog_The_file__0__is_not_an_iRT_database, messageDlg.Message); messageDlg.OkDialog(); }); RunUI(() => addDlg.FilePath = "not_exist.irtdb"); RunDlg<MessageDlg>(addDlg.OkDialog, messageDlg => { AssertEx.AreComparableStrings(TextUtil.LineSeparate( Resources.AddIrtCalculatorDlgOkDialogThe_file__0__does_not_exist, Resources.AddIrtCalculatorDlg_OkDialog_Please_specify_a_path_to_an_existing_iRT_database), messageDlg.Message); messageDlg.OkDialog(); }); RunUI(() => addDlg.CalculatorName = "noexist"); PauseForScreenShot(); RunDlg<MessageDlg>(addDlg.OkDialog, messageDlg => { Assert.AreEqual(Resources.AddIrtCalculatorDlg_OkDialog_Please_choose_the_iRT_calculator_you_would_like_to_add, messageDlg.Message); messageDlg.OkDialog(); }); RunUI(() => addDlg.FilePath = databasePath); RunDlg<AddIrtPeptidesDlg>(addDlg.OkDialog, addPepDlg => addPepDlg.OkDialog()); Assert.AreEqual(18, irtDlgAdd.LibraryPeptideCount); OkDialog(irtDlgAdd, irtDlgAdd.CancelButton.PerformClick); } // Add from existing calculator { var irtDlgAdd = ShowDialog<EditIrtCalcDlg>(editRT2.EditCurrentCalculator); var addDlg = ShowDialog<AddIrtCalculatorDlg>(irtDlgAdd.AddIrtDatabase); RunUI(() => addDlg.CalculatorName = irtCalc); RunDlg<AddIrtPeptidesDlg>(addDlg.OkDialog, addPepDlg => addPepDlg.OkDialog()); Assert.AreEqual(18, irtDlgAdd.LibraryPeptideCount); OkDialog(irtDlgAdd, irtDlgAdd.CancelButton.PerformClick); } OkDialog(editRT2, editRT2.CancelButton.PerformClick); OkDialog(peptideSettingsDlg2, peptideSettingsDlg2.CancelButton.PerformClick); WaitForClosedForm(peptideSettingsDlg2); //Restore the document to contain all 29 peptides RunUI(SkylineWindow.Undo); //Open peptide settings var peptideSettingsDlg3 = ShowDialog<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI); //Add a new regression var editRT3 = ShowDialog<EditRTDlg>(peptideSettingsDlg3.AddRTRegression); RunUI(() => editRT3.SetRegressionName("iRT Document Regression")); //Edit the calculator list var editCalculator = ShowDialog<EditListDlg<SettingsListBase<RetentionScoreCalculatorSpec>, RetentionScoreCalculatorSpec>>( editRT3.EditCalculatorList); RunUI(() => editCalculator.SelectItem("iRT Document Calculator")); //Edit the document-based calculator var irtDlg3 = ShowDialog<EditIrtCalcDlg>(editCalculator.EditItem); //Add the 18 non-standard peptides to the calculator, then OkDialog back to Skyline RunDlg<AddIrtPeptidesDlg>(irtDlg3.AddResults, addPeptidesDlg => addPeptidesDlg.OkDialog()); RunUI(() => { Assert.AreEqual(18, irtDlg3.LibraryPeptideCount); irtDlg3.OkDialog(); }); WaitForClosedForm(irtDlg3); RunUI(editCalculator.OkDialog); WaitForClosedForm(editCalculator); RunUI(() => { editRT3.AddResults(); editRT3.ChooseCalculator("iRT Document Calculator"); editRT3.SetTimeWindow(2.0); editRT3.OkDialog(); }); WaitForClosedForm(editRT3); //Then choose the new, document-based regression and turn off prediction RunUI(() => { peptideSettingsDlg3.ChooseRegression("iRT Document Regression"); peptideSettingsDlg3.IsUseMeasuredRT = true; peptideSettingsDlg3.OkDialog(); }); WaitForClosedForm(peptideSettingsDlg3); Assert.IsNull(FindOpenForm<MessageDlg>()); //Export the measurement-based transition list ExportMethod(testFilesDir.GetTestPath("EmpiricalTL.csv")); //Turn on prediction for scheduling var peptideSettingsDlg4 = ShowDialog<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI); RunUI(() => { peptideSettingsDlg4.IsUseMeasuredRT = false; peptideSettingsDlg4.OkDialog(); }); WaitForClosedForm(peptideSettingsDlg4); //Export the prediction-based transition list ExportMethod(testFilesDir.GetTestPath("PredictionTL.csv")); //Now open both files and compare AssertEx.NoDiff(File.ReadAllText(testFilesDir.GetTestPath("EmpiricalTL.csv")), File.ReadAllText(testFilesDir.GetTestPath("PredictionTL.csv"))); // Close and re-open, and try again RunUI(() => { Assert.IsTrue(SkylineWindow.SaveDocument()); SkylineWindow.NewDocument(); Assert.IsTrue(SkylineWindow.OpenFile(documentPath)); }); WaitForDocumentLoaded(); ExportMethod(testFilesDir.GetTestPath("PredictionTL_reopen.csv")); AssertEx.NoDiff(File.ReadAllText(testFilesDir.GetTestPath("EmpiricalTL.csv")), File.ReadAllText(testFilesDir.GetTestPath("PredictionTL_reopen.csv"))); /* * Rename the database * Switch to the calculator in EditRTDlg and check for an error * Go to edit the calculator and check for an error * Try to export a transition list and check for an error * Switch to the calculator in the graph and check for an error */ var stream = File.Create(testFilesDir.GetTestPath("irt-c18-copy.irtdb")); stream.Close(); File.Replace(databasePath, testFilesDir.GetTestPath("irt-c18-copy.irtdb"), testFilesDir.GetTestPath("backup.irtdb")); // The database renaming doesn't break usage anymore, since // the iRT databases are loaded into memory during initialization. // So, create a new calculator with a bogus path. const string irtCalcMissing = "iRT-C18-missing"; Settings.Default.RTScoreCalculatorList.SetValue(new RCalcIrt(irtCalcMissing, testFilesDir.GetTestPath("irt-c18-missing.irtdb"))); var peptideSettingsDlg5 = ShowDialog<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI); var editRT5 = ShowDialog<EditRTDlg>(peptideSettingsDlg5.AddRTRegression); //Add results and switch to a calculator whose database is not connected: error RunDlg<MessageDlg>(() => { editRT5.AddResults(); editRT5.ChooseCalculator(irtCalcMissing); }, errorMessage => errorMessage.OkDialog()); //Go to add a new calculator var irtDlg5 = ShowDialog<EditIrtCalcDlg>(editRT5.AddCalculator); //Try to open a file that does not exist: error RunDlg<MessageDlg>(() => irtDlg5.OpenDatabase(databasePath), messageDlg => messageDlg.OkDialog()); RunUI(() => irtDlg5.CancelButton.PerformClick()); WaitForClosedForm(irtDlg5); //In order to export a transition list, we have to set the RT regression to have the iRT Calc. //This means that the iRT calc must have its database connected - else the dialog will not let //the user choose it. So here we will restore the file so we can choose the calculator. //Then once that dialog is closed and the regression is saved, switch the file back again. stream = File.Create(databasePath); stream.Close(); File.Replace(testFilesDir.GetTestPath("irt-c18-copy.irtdb"), databasePath, testFilesDir.GetTestPath("backup.irtdb")); RunUI(() => { editRT5.SetRegressionName("iRT Test Regression"); editRT5.AddResults(); editRT5.ChooseCalculator(irtCalc); editRT5.OkDialog(); }); WaitForClosedForm(editRT5); RunUI(() => { peptideSettingsDlg5.ChooseRegression("iRT Test Regression"); peptideSettingsDlg5.IsUseMeasuredRT = false; //Use prediction peptideSettingsDlg5.OkDialog(); }); WaitForClosedForm(peptideSettingsDlg5); RunUI(() => SkylineWindow.SaveDocument()); //Switch the file back to the copy, destroying the original stream = File.Create(testFilesDir.GetTestPath("irt-c18-copy.irtdb")); stream.Close(); File.Replace(databasePath, testFilesDir.GetTestPath("irt-c18-copy.irtdb"), testFilesDir.GetTestPath("backup.irtdb")); var exportTransList = ShowDialog<ExportMethodDlg>(SkylineWindow.ShowExportTransitionListDlg); // Used to cause a message box, but should work now, because iRT databases get loaded once RunUI(() => exportTransList.SetMethodType(ExportMethodType.Scheduled)); RunUI(() => exportTransList.CancelButton.PerformClick()); WaitForClosedForm(exportTransList); // Used to cause a message box, but should work now, because iRT databases get loaded once RunUI(() => SkylineWindow.ChooseCalculator(irtCalc)); /* * Now clean up by deleting all these calculators. If we don't, then the next functional test * will fail because it will try to use a calculator from settings which will not have its * database. */ RunDlg<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI, peptideSettingsDlg6 => { peptideSettingsDlg6.ChooseRegression(Resources.SettingsList_ELEMENT_NONE_None); peptideSettingsDlg6.OkDialog(); }); // Finally, close and re-open the document to see MissingFileDlg int pepCount = SkylineWindow.Document.PeptideCount; RunUI(() => SkylineWindow.NewDocument(true)); Assert.AreEqual(0, SkylineWindow.Document.PeptideCount); RunDlg<MissingFileDlg>(() => SkylineWindow.OpenFile(documentPath), dlg => dlg.OkDialog()); Assert.AreEqual(pepCount, SkylineWindow.Document.PeptideCount); RunUI(() => SkylineWindow.NewDocument(true)); RunDlg<MissingFileDlg>(() => SkylineWindow.OpenFile(documentPath), dlg => dlg.CancelDialog()); Assert.AreEqual(0, SkylineWindow.Document.PeptideCount); // Make sure no message boxes are left open Assert.IsNull(FindOpenForm<MessageDlg>()); }