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 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 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 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(); }
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); }
private void ExportWithExplicitCollisionEnergyValues(string pathList) { var original = SkylineWindow.Document; var refine = new RefinementSettings(); var document = refine.ConvertToSmallMolecules(original); for (var loop = 0; loop < 2; loop++) { SkylineWindow.SetDocument(document, SkylineWindow.Document); var exportMethodDlg = ShowDialog<ExportMethodDlg>(() => SkylineWindow.ShowExportMethodDialog(ExportFileType.List)); RunUI(() => { exportMethodDlg.InstrumentType = ExportInstrumentType.THERMO_QUANTIVA; exportMethodDlg.OptimizeType = ExportOptimize.CE; exportMethodDlg.MethodType = ExportMethodType.Standard; }); RunUI(() => exportMethodDlg.OkDialog(pathList)); WaitForClosedForm(exportMethodDlg); var actual = File.ReadAllLines(pathList); if (loop == 1) { // Explicit CE values Assert.AreEqual(document.MoleculeTransitionCount+1, actual.Length); // Should be just one line per transition, and a header break; } else { Assert.AreEqual(document.MoleculeTransitionCount*11 + 1, actual.Length); // Multiple steps, and a header } // Change the current document to use explicit CE values, verify that this changes the output var ce = 1; for (bool changing = true; changing; ) { changing = false; foreach (var peptideGroupDocNode in document.MoleculeGroups) { var pepGroupPath = new IdentityPath(IdentityPath.ROOT, peptideGroupDocNode.Id); foreach (var nodePep in peptideGroupDocNode.Molecules) { var pepPath = new IdentityPath(pepGroupPath, nodePep.Id); foreach (var nodeTransitionGroup in nodePep.TransitionGroups) { if (!nodeTransitionGroup.ExplicitValues.CollisionEnergy.HasValue) { var tgPath = new IdentityPath(pepPath, nodeTransitionGroup.Id); document = (SrmDocument)document.ReplaceChild(tgPath.Parent, nodeTransitionGroup.ChangeExplicitValues(nodeTransitionGroup.ExplicitValues.ChangeCollisionEnergy(ce++))); changing = true; break; } } } if (changing) break; } } } SkylineWindow.SetDocument(original, SkylineWindow.Document); }
private void CheckRoundTrip() { // Verify that document roundtrips properly as small molecule var refine = new RefinementSettings(); var doc = refine.ConvertToSmallMolecules(SkylineWindow.Document, ignoreDecoys: true); AssertEx.RoundTrip(doc); // Verify that document roundtrips properly AssertEx.RoundTrip(SkylineWindow.Document); }
private static SrmDocument InitWatersImsMseDocument(TestFilesDir testFilesDir, string skyFile, RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules, out string docPath) { docPath = testFilesDir.GetTestPath(skyFile); var consoleBuffer = new StringBuilder(); var consoleOutput = new CommandStatusWriter(new StringWriter(consoleBuffer)); var cmdline = new CommandLine(consoleOutput); Assert.IsTrue(cmdline.OpenSkyFile(docPath)); // Handles any path shifts in database files, like our .imdb file SrmDocument doc = cmdline.Document; var refine = new RefinementSettings(); doc = refine.ConvertToSmallMolecules(doc, asSmallMolecules); return doc; }
public void DoAsymmetricIsolationTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules) { TestSmallMolecules = false; // We test small molecules explicitly in this test LocalizationHelper.InitThread(); // TODO: All unit tests should be correctly initialized var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath("Asym_DIA.sky"); string cachePath = ChromatogramCache.FinalPathForName(docPath, null); FileEx.SafeDelete(cachePath); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); var refine = new RefinementSettings(); doc = refine.ConvertToSmallMolecules(doc, asSmallMolecules); const int expectedMoleculeCount = 1; // At first small molecules did not support multiple charge states, and this was 2 for that test mode AssertEx.IsDocumentState(doc, null, 1, expectedMoleculeCount, 2, 4); var fullScanInitial = doc.Settings.TransitionSettings.FullScan; Assert.IsTrue(fullScanInitial.IsEnabledMsMs); Assert.AreEqual(FullScanAcquisitionMethod.DIA, fullScanInitial.AcquisitionMethod); Assert.AreEqual(25, fullScanInitial.PrecursorFilter); AssertEx.Serializable(doc); var docContainer = new ResultsTestDocumentContainer(doc, docPath); // Import the first RAW file (or mzML for international) string rawPath = testFilesDir.GetTestPath("Asym_DIA_data.mzML"); var measuredResults = new MeasuredResults(new[] { new ChromatogramSet("Single", new[] { rawPath }) }); TransitionGroupDocNode nodeGroup; double ratio; { // Import with symmetric isolation window SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2); nodeGroup = docResults.MoleculeTransitionGroups.First(); ratio = nodeGroup.Results[0][0].Ratio ?? 0; // The expected ratio is 1.0, but the symmetric isolation window should produce poor results if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only) // Can't use labels without a formula Assert.AreEqual(0.25, ratio, 0.05); // Revert to original document, and get rid of results cache Assert.IsTrue(docContainer.SetDocument(doc, docResults, false)); FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd")); } { // Import with asymmetric isolation window SrmDocument docAsym = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan => fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test asym", 5, 20)))); AssertEx.Serializable(docAsym); Assert.IsTrue(docContainer.SetDocument(docAsym, doc, false)); SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2); nodeGroup = docResults.MoleculeTransitionGroups.First(); ratio = nodeGroup.Results[0][0].Ratio ?? 0; // Asymmetric should be a lot closer to 1.0 if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only) // Can't use labels without a formula Assert.AreEqual(1.05, ratio, 0.05); // Revert to original document, and get rid of results cache Assert.IsTrue(docContainer.SetDocument(doc, docResults, false)); FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd")); } { // Import with prespecified isolation windows var windowList = new List<IsolationWindow> { new IsolationWindow(999.2702214, 1024.270221), new IsolationWindow(1024.27267, 1049.27267) }; SrmDocument docPrespecified = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan => fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test prespecified", windowList)))); AssertEx.Serializable(docPrespecified); Assert.IsTrue(docContainer.SetDocument(docPrespecified, doc, false)); SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2); nodeGroup = docResults.MoleculeTransitionGroups.First(); ratio = nodeGroup.Results[0][0].Ratio ?? 0; // Asymmetric should be a lot closer to 1.0 if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only) // Can't use labels without a formula Assert.AreEqual(1.05, ratio, 0.05); // Revert to original document, and get rid of results cache Assert.IsTrue(docContainer.SetDocument(doc, docResults, false)); FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd")); } { // Import with prespecified targets var windowList = new List<IsolationWindow> { new IsolationWindow(999.2702214, 1024.270221, 1004.27), new IsolationWindow(1024.27267, 1049.27267, 1029.27) }; SrmDocument docPrespecified = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan => fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test target", windowList)))); AssertEx.Serializable(docPrespecified); Assert.IsTrue(docContainer.SetDocument(docPrespecified, doc, false)); SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2); nodeGroup = docResults.MoleculeTransitionGroups.First(); ratio = nodeGroup.Results[0][0].Ratio ?? 0; // Asymmetric should be a lot closer to 1.0 if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only) // Can't use labels without a formula Assert.AreEqual(1.05, ratio, 0.05); // Revert to original document, and get rid of results cache Assert.IsTrue(docContainer.SetDocument(doc, docResults, false)); FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd")); } { // Import with ambiguous prespecified targets var windowList = new List<IsolationWindow> { new IsolationWindow(999.2702214, 1024.270221, 1004.27), new IsolationWindow(1000.0, 1049.27267, 1004.28) }; SrmDocument docAmbiguous = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan => fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test ambiguous", windowList)))); AssertEx.Serializable(docAmbiguous); Assert.IsTrue(docContainer.SetDocument(docAmbiguous, doc, false)); try { docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2); Assert.Fail("Expected ambiguous isolation targets."); } catch (Exception x) { AssertEx.AreComparableStrings(Resources.SpectrumFilter_FindFilterPairs_Two_isolation_windows_contain_targets_which_match_the_isolation_target__0__, x.Message, 1); } // Revert to original document, and get rid of results cache Assert.IsTrue(docContainer.SetDocument(doc, docContainer.Document, false)); FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd")); } { // Import with one isolation window, so one result is discarded. var windowList = new List<IsolationWindow> { new IsolationWindow(999.2702214, 1024.270221), }; SrmDocument docOneWindow = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan => fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test one window", windowList)))); AssertEx.Serializable(docOneWindow); Assert.IsTrue(docContainer.SetDocument(docOneWindow, doc, false)); SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, 1, 1, 0, 2, 0); nodeGroup = docResults.MoleculeTransitionGroups.First(); Assert.IsNull(nodeGroup.Results[0][0].Ratio); // Revert to original document, and get rid of results cache Assert.IsTrue(docContainer.SetDocument(doc, docResults, false)); FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd")); } testFilesDir.Dispose(); }
protected override void DoTest() { // Lest we get "To export a scheduled method, you must first choose a retention time predictor in Peptide Settings / Prediction, or import results for all peptides in the document." TestSmallMolecules = false; // Skyline Collision Energy Optimization RunUI(() => SkylineWindow.OpenFile(GetTestPath("CE_Vantage_15mTorr.sky"))); // Not L10N if (AsSmallMolecules) { var doc = WaitForDocumentLoaded(); var refine = new RefinementSettings(); SkylineWindow.SetDocument(refine.ConvertToSmallMolecules(doc), doc); } // Deriving a New Linear Equation, p. 2 var transitionSettingsUI = ShowDialog<TransitionSettingsUI>(SkylineWindow.ShowTransitionSettingsUI); var editList = ShowDialog<EditListDlg<SettingsListBase<CollisionEnergyRegression>, CollisionEnergyRegression>> (transitionSettingsUI.EditCEList); RunUI(() => editList.SelectItem("Thermo")); // Not L10N EditCEDlg editItem = ShowDialog<EditCEDlg>(editList.EditItem); PauseForScreenShot<EditCEDlg>("Edit Collision Energy Equation form", 3); ChargeRegressionLine regressionLine2 = new ChargeRegressionLine(2, 0.034, 3.314); ChargeRegressionLine regressionLine3 = new ChargeRegressionLine(3, 0.044, 3.314); CheckRegressionLines(new[] {regressionLine2, regressionLine3}, editItem.Regression.Conversions); RunUI(() => { editItem.DialogResult = DialogResult.OK; editList.DialogResult = DialogResult.Cancel; transitionSettingsUI.DialogResult = DialogResult.Cancel; }); WaitForClosedForm(transitionSettingsUI); // Measuring Retention Times for Method Scheduling, p. 3 { var exportMethodDlg = ShowDialog<ExportMethodDlg>(() => SkylineWindow.ShowExportMethodDialog(ExportFileType.List)); RunUI(() => { exportMethodDlg.InstrumentType = ExportInstrumentType.THERMO; exportMethodDlg.ExportStrategy = ExportStrategy.Single; exportMethodDlg.OptimizeType = ExportOptimize.NONE; exportMethodDlg.MethodType = ExportMethodType.Standard; }); PauseForScreenShot<ExportMethodDlg.TransitionListView>("Export Transition List form", 4); RunUI(() => exportMethodDlg.OkDialog(GetTestPath("CE_Vantage_15mTorr_unscheduled.csv"))); // Not L10N WaitForClosedForm(exportMethodDlg); } string filePathTemplate = GetTestPath("CE_Vantage_15mTorr_unscheduled.csv"); // Not L10N CheckTransitionList(filePathTemplate, 1, 6); const string unscheduledName = "Unscheduled"; // Not L10N RunDlg<ImportResultsDlg>(SkylineWindow.ImportResults, importResultsDlg => { importResultsDlg.RadioAddNewChecked = true; var path = new[] {new KeyValuePair<string, MsDataFileUri[]>(unscheduledName, // This is not actually a valid file path (missing OptimizeCE) // but Skyline should correctly find the file in the same folder // as the document. new[] { MsDataFileUri.Parse(GetTestPath("CE_Vantage_15mTorr_unscheduled" + ExtThermoRaw))})}; // Not L10N importResultsDlg.NamedPathSets = path; importResultsDlg.OkDialog(); }); WaitForCondition(5*60*1000, () => SkylineWindow.Document.Settings.MeasuredResults.IsLoaded); // 5 minutes AssertEx.IsDocumentState(SkylineWindow.Document, null, 7, 27, 30, 120); var docUnsched = SkylineWindow.Document; AssertResult.IsDocumentResultsState(SkylineWindow.Document, unscheduledName, docUnsched.MoleculeCount, docUnsched.MoleculeTransitionGroupCount, 0, docUnsched.MoleculeTransitionCount - 1, 0); RunUI(() => { SkylineWindow.ExpandProteins(); SkylineWindow.ExpandPeptides(); }); PauseForScreenShot("Main Skyline window", 5); // Creating Optimization Methods, p. 5 { var exportMethodDlg = ShowDialog<ExportMethodDlg>(() => SkylineWindow.ShowExportMethodDialog(ExportFileType.List)); RunUI(() => { exportMethodDlg.InstrumentType = ExportInstrumentType.THERMO; exportMethodDlg.ExportStrategy = ExportStrategy.Buckets; exportMethodDlg.MaxTransitions = 110; exportMethodDlg.IgnoreProteins = true; exportMethodDlg.OptimizeType = ExportOptimize.CE; exportMethodDlg.MethodType = ExportMethodType.Scheduled; }); PauseForScreenShot<ExportMethodDlg.TransitionListView>("Export Transition List form", 6); RunUI(() => exportMethodDlg.OkDialog(GetTestPath("CE_Vantage_15mTorr.csv"))); // Not L10N WaitForClosedForm(exportMethodDlg); } string filePathTemplate1 = GetTestPath("CE_Vantage_15mTorr_000{0}.csv"); // Not L10N CheckTransitionList(filePathTemplate1, 5, 9); var filePath = GetTestPath("CE_Vantage_15mTorr_0001.csv"); // Not L10N CheckCEValues(filePath, 11); // Analyze Optimization Data, p. 7 RunDlg<ImportResultsDlg>(SkylineWindow.ImportResults, importResultsDlg => { importResultsDlg.RadioAddNewChecked = true; importResultsDlg.OptimizationName = ExportOptimize.CE; importResultsDlg.NamedPathSets = DataSourceUtil.GetDataSourcesInSubdirs(TestFilesDirs[0].FullPath).ToArray(); importResultsDlg.NamedPathSets[0] = new KeyValuePair<string, MsDataFileUri[]>("Optimize CE", importResultsDlg.NamedPathSets[0].Value.Take(5).ToArray()); // Not L10N importResultsDlg.OkDialog(); }); RunUI(() => { SkylineWindow.ShowSingleTransition(); SkylineWindow.AutoZoomBestPeak(); SkylineWindow.ShowPeakAreaReplicateComparison(); }); if (AsSmallMolecules) { return; // Too peptide-centric from here to end of test } FindNode("IHGFDLAAINLQR"); RestoreViewOnScreen(8); WaitForCondition(15*60*1000, () => SkylineWindow.Document.Settings.MeasuredResults.IsLoaded); // 10 minutes PauseForScreenShot("Main Skyline window", 8); // p. 8 // Not L10N RemovePeptide("EGIHAQQK"); FindNode("IDALNENK"); RunUI(() => SkylineWindow.NormalizeAreaGraphTo(AreaNormalizeToView.area_percent_view)); PauseForScreenShot("Main Skyline window", 9); RunUI(SkylineWindow.EditDelete); RemovePeptide("LICDNTHITK"); // Creating a New Equation for CE, p. 9 var transitionSettingsUI1 = ShowDialog<TransitionSettingsUI>(SkylineWindow.ShowTransitionSettingsUI); var editCEDlg1 = ShowDialog<EditListDlg<SettingsListBase<CollisionEnergyRegression>, CollisionEnergyRegression>>(transitionSettingsUI1.EditCEList); var addItem = ShowDialog<EditCEDlg>(editCEDlg1.AddItem); RunUI(() => { addItem.RegressionName = "Thermo Vantage Tutorial"; // Not L10N addItem.UseCurrentData(); }); var graphRegression = ShowDialog<GraphRegression>(addItem.ShowGraph); PauseForScreenShot<GraphRegression>("Collision Energy Regression graphs", 10); var graphDatas = graphRegression.RegressionGraphDatas.ToArray(); Assert.AreEqual(2, graphDatas.Length); ChargeRegressionLine regressionLine21 = new ChargeRegressionLine(2, 0.0305, 2.5061); ChargeRegressionLine regressionLine31 = new ChargeRegressionLine(3, 0.0397, 1.4217); var expectedRegressions = new[] {regressionLine21, regressionLine31}; CheckRegressionLines(expectedRegressions, new[] { new ChargeRegressionLine(2, Math.Round(graphDatas[0].RegressionLine.Slope, 4), Math.Round(graphDatas[0].RegressionLine.Intercept, 4)), new ChargeRegressionLine(3, Math.Round(graphDatas[1].RegressionLine.Slope, 4), Math.Round(graphDatas[1].RegressionLine.Intercept, 4)), }); RunUI(graphRegression.CloseDialog); WaitForClosedForm(graphRegression); RunUI(addItem.OkDialog); WaitForClosedForm(addItem); RunUI(editCEDlg1.OkDialog); WaitForClosedForm(editCEDlg1); RunUI(transitionSettingsUI1.OkDialog); WaitForClosedForm(transitionSettingsUI1); // Optimizing Each Transition, p. 10 RunDlg<TransitionSettingsUI>(SkylineWindow.ShowTransitionSettingsUI, transitionSettingsUI2 => { transitionSettingsUI2.UseOptimized = true; transitionSettingsUI2.OptimizeType = OptimizedMethodType.Transition.GetLocalizedString(); transitionSettingsUI2.OkDialog(); }); RunDlg<ExportMethodDlg>(() => SkylineWindow.ShowExportMethodDialog(ExportFileType.List), exportMethodDlg => { exportMethodDlg.ExportStrategy = ExportStrategy.Single; exportMethodDlg.OkDialog(GetTestPath("CE_Vantage_15mTorr_optimized.csv")); // Not L10N }); var filePathTemplate2 = GetTestPath("CE_Vantage_15mTorr_optimized.csv"); // Not L10N CheckTransitionList(filePathTemplate2, 1, 9); RunUI(() => SkylineWindow.SaveDocument()); WaitForConditionUI(() => !SkylineWindow.Dirty); }
public void DoFullScanSettingsTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules, out List<SrmDocument> docCheckPoints) { TestSmallMolecules = false; // Don't need that magic extra node, we have an explicit test docCheckPoints = new List<SrmDocument>(); var doc = ResultsUtil.DeserializeDocument("MultiLabel.sky", GetType()); var refine = new RefinementSettings(); doc = refine.ConvertToSmallMolecules(doc, asSmallMolecules); Assert.IsFalse(doc.MoleculeTransitionGroups.Any(nodeGroup => nodeGroup.IsotopeDist != null)); AssertEx.Serializable(doc, AssertEx.Cloned); double c13Delta = BioMassCalc.MONOISOTOPIC.GetMass(BioMassCalc.C13) - BioMassCalc.MONOISOTOPIC.GetMass(BioMassCalc.C); double n15Delta = BioMassCalc.MONOISOTOPIC.GetMass(BioMassCalc.N15) - BioMassCalc.MONOISOTOPIC.GetMass(BioMassCalc.N); // Verify isotope distributions calculated when MS1 filtering enabled var enrichments = IsotopeEnrichments.DEFAULT; var docIsotopes = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 3, enrichments))); docCheckPoints.Add(docIsotopes); Assert.AreEqual(FullScanMassAnalyzerType.tof, docIsotopes.Settings.TransitionSettings.FullScan.PrecursorMassAnalyzer); Assert.IsFalse(docIsotopes.MoleculeTransitionGroups.Any(nodeGroup => nodeGroup.IsotopeDist == null)); foreach (var nodeGroup in docIsotopes.MoleculeTransitionGroups) { Assert.AreEqual(3, nodeGroup.Children.Count); var isotopePeaks = nodeGroup.IsotopeDist; Assert.IsNotNull(isotopePeaks); Assert.IsTrue(nodeGroup.HasIsotopeDist); // The peaks should always includ at least M-1 Assert.IsTrue(isotopePeaks.MassIndexToPeakIndex(0) > 0); // Within 2.5% of 100% of the entire isotope distribution Assert.AreEqual(1.0, isotopePeaks.ExpectedProportions.Sum(), 0.025); // Precursor mass and m/z values are expected to match exactly (well, within XML roundtrip accuracy anyway) Assert.AreEqual(nodeGroup.PrecursorMz, nodeGroup.IsotopeDist.GetMZI(0), SequenceMassCalc.MassTolerance); Assert.AreEqual(nodeGroup.PrecursorMz, nodeGroup.TransitionGroup.IsCustomIon ? BioMassCalc.CalculateIonMz(nodeGroup.IsotopeDist.GetMassI(0), nodeGroup.TransitionGroup.PrecursorCharge) : SequenceMassCalc.GetMZ(nodeGroup.IsotopeDist.GetMassI(0), nodeGroup.TransitionGroup.PrecursorCharge), SequenceMassCalc.MassTolerance); // Check isotope distribution masses for (int i = 1; i < isotopePeaks.CountPeaks; i++) { int massIndex = isotopePeaks.PeakIndexToMassIndex(i); Assert.IsTrue(isotopePeaks.GetMZI(massIndex - 1) < isotopePeaks.GetMZI(massIndex)); double massDelta = GetMassDelta(isotopePeaks, massIndex); if (nodeGroup.TransitionGroup.LabelType.IsLight) { // All positive should be close to 13C - C, and 0 should be the same as the next delta double expectedDelta = (massIndex > 0 ? c13Delta : GetMassDelta(isotopePeaks, massIndex + 1)); Assert.AreEqual(expectedDelta, massDelta, 0.001); } else if (nodeGroup.TransitionGroup.LabelType.Name.Contains("15N")) { // All positive should be close to 13C, and all negative 15N double expectedDelta = (massIndex > 0 ? c13Delta : n15Delta); Assert.AreEqual(expectedDelta, massDelta, 0.0015); } else if (massIndex == 0) { double expectedDelta = (isotopePeaks.GetProportionI(massIndex - 1) == 0 ? GetMassDelta(isotopePeaks, massIndex + 1) : 1.0017); Assert.AreEqual(expectedDelta, massDelta, 0.001); } else { Assert.AreEqual(c13Delta, massDelta, 0.001); } } } AssertEx.Serializable(docIsotopes, AssertEx.Cloned); // Narrow the resolution, and verify that predicted proportion of the isotope // distribution captured is reduced for all precursors var docIsotopesFt = docIsotopes.ChangeSettings(docIsotopes.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorResolution(FullScanMassAnalyzerType.ft_icr, 500 * 1000, 400))); docCheckPoints.Add(docIsotopesFt); var tranGroupsOld = docIsotopes.MoleculeTransitionGroups.ToArray(); var tranGroupsNew = docIsotopesFt.MoleculeTransitionGroups.ToArray(); Assert.AreEqual(tranGroupsOld.Length, tranGroupsNew.Length); for (int i = 0; i < tranGroupsOld.Length; i++) { Assert.AreNotSame(tranGroupsOld[i], tranGroupsNew[i]); Assert.AreNotSame(tranGroupsOld[i].IsotopeDist, tranGroupsNew[i].IsotopeDist); Assert.IsTrue(tranGroupsOld[i].IsotopeDist.ExpectedProportions.Sum() > tranGroupsNew[i].IsotopeDist.ExpectedProportions.Sum()); } // Use Min % of base peak and verify variation in transitions used const float minPercent1 = 10; var docIsotopesP1 = docIsotopes.ChangeSettings(docIsotopes.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Percent, minPercent1, enrichments))); docCheckPoints.Add(docIsotopesP1); tranGroupsNew = docIsotopesP1.MoleculeTransitionGroups.ToArray(); int maxTran = 0; for (int i = 0; i < tranGroupsOld.Length; i++) { // Isotope distributions should not have changed var isotopePeaks = tranGroupsNew[i].IsotopeDist; Assert.AreSame(tranGroupsOld[i].IsotopeDist, isotopePeaks); // Expected transitions should be present maxTran = Math.Max(maxTran, tranGroupsNew[i].Children.Count); foreach (TransitionDocNode nodeTran in tranGroupsNew[i].Children) { int massIndex = nodeTran.Transition.MassIndex; Assert.IsTrue(minPercent1 <= isotopePeaks.GetProportionI(massIndex)*100.0/isotopePeaks.BaseMassPercent); } } Assert.AreEqual(5, maxTran); AssertEx.Serializable(docIsotopesP1, AssertEx.Cloned); // Express any failure in terms of XML diffs // Use 10%, and check that 15N modifications all have M-1 const float minPercent2 = 5; var docIsotopesP2 = docIsotopesP1.ChangeSettings(docIsotopesP1.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Percent, minPercent2, enrichments))); docCheckPoints.Add(docIsotopesP2); foreach (var nodeGroup in docIsotopesP2.MoleculeTransitionGroups) { var firstChild = (TransitionDocNode) nodeGroup.Children[0]; if (nodeGroup.TransitionGroup.LabelType.Name.EndsWith("15N")) Assert.AreEqual(-1, firstChild.Transition.MassIndex); else Assert.AreNotEqual(-1, firstChild.Transition.MassIndex); } AssertEx.Serializable(docIsotopesP2, AssertEx.Cloned); // Use lower enrichment of 13C, and verify that this add M-1 for 13C labeled precursors var enrichmentsLow13C = enrichments.ChangeEnrichment(new IsotopeEnrichmentItem(BioMassCalc.C13, 0.9)); var docIsotopesLow13C = docIsotopesP1.ChangeSettings(docIsotopesP1.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Percent, minPercent2, enrichmentsLow13C))); tranGroupsNew = docIsotopesLow13C.MoleculeTransitionGroups.ToArray(); for (int i = 0; i < tranGroupsOld.Length; i++) { var nodeGroup = tranGroupsNew[i]; if (!Equals(nodeGroup.TransitionGroup.LabelType.Name, "heavy")) Assert.AreSame(tranGroupsOld[i].IsotopeDist, nodeGroup.IsotopeDist); else { var firstChild = (TransitionDocNode)nodeGroup.Children[0]; Assert.IsTrue(firstChild.Transition.MassIndex < 0); } } AssertEx.Serializable(docIsotopesLow13C, AssertEx.Cloned); // Express any failure as XML diffs // Use 0%, and check that everything has M-1 and lower var enrichmentsLow = enrichmentsLow13C.ChangeEnrichment(new IsotopeEnrichmentItem(BioMassCalc.N15, 0.97)); var docIsotopesLowP0 = docIsotopesP1.ChangeSettings(docIsotopesP1.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Percent, 0, enrichmentsLow))); docCheckPoints.Add(docIsotopesLowP0); foreach (var nodeGroup in docIsotopesLowP0.MoleculeTransitionGroups) { Assert.AreEqual(nodeGroup.IsotopeDist.CountPeaks, nodeGroup.Children.Count); var firstChild = (TransitionDocNode)nodeGroup.Children[0]; if (nodeGroup.TransitionGroup.LabelType.IsLight) Assert.AreEqual(-1, firstChild.Transition.MassIndex); else Assert.IsTrue(-1 > firstChild.Transition.MassIndex); } AssertEx.Serializable(docIsotopesLowP0, AssertEx.Cloned); // Test a document with variable and heavy modifications, which caused problems for // the original implementation var docVariable = ResultsUtil.DeserializeDocument("HeavyVariable.sky", GetType()); Assert.IsFalse(docVariable.MoleculeTransitionGroups.Any(nodeGroup => nodeGroup.IsotopeDist == null)); foreach (var nodeGroup in docVariable.MoleculeTransitionGroups) { var isotopePeaks = nodeGroup.IsotopeDist; Assert.IsNotNull(isotopePeaks); // The peaks should always includ at least M-1 Assert.IsTrue(isotopePeaks.MassIndexToPeakIndex(0) > 0); // Precursor mass and m/z values are expected to match exactly (well, within XML roundtrip tolerance anyway) Assert.AreEqual(nodeGroup.PrecursorMz, nodeGroup.IsotopeDist.GetMZI(0), SequenceMassCalc.MassTolerance); // Check isotope distribution masses for (int i = 1; i < isotopePeaks.CountPeaks; i++) { int massIndex = isotopePeaks.PeakIndexToMassIndex(i); Assert.IsTrue(isotopePeaks.GetMZI(massIndex - 1) < isotopePeaks.GetMZI(massIndex)); double massDelta = GetMassDelta(isotopePeaks, massIndex); bool containsSulfur = nodeGroup.TransitionGroup.Peptide.IsCustomIon ? (nodeGroup.CustomIon.Formula.IndexOfAny("S".ToCharArray()) != -1) : (nodeGroup.TransitionGroup.Peptide.Sequence.IndexOfAny("CM".ToCharArray()) != -1); if (massIndex == 0) { double expectedDelta = (isotopePeaks.GetProportionI(massIndex - 1) == 0 ? GetMassDelta(isotopePeaks, massIndex + 1) : 1.0017); Assert.AreEqual(expectedDelta, massDelta, 0.001); } else if (!containsSulfur || massIndex == 1) { Assert.AreEqual(c13Delta, massDelta, 0.001); } else { Assert.AreEqual(1.00075, massDelta, 0.001); } } } docCheckPoints.Add(docVariable); }
private static SrmDocument InitFullScanDocument(string docPath, int prot, ref int pep, ref int prec, ref int tran, RefinementSettings.ConvertToSmallMoleculesMode smallMoleculeTestMode) { SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); int? expectedRevisionNumber = 0; if (smallMoleculeTestMode != RefinementSettings.ConvertToSmallMoleculesMode.none) { var refine = new RefinementSettings(); var oldDoc = doc; AssertEx.Serializable(oldDoc); doc = refine.ConvertToSmallMolecules(doc, smallMoleculeTestMode); AssertEx.ConvertedSmallMoleculeDocumentIsSimilar(oldDoc, doc); AssertEx.Serializable(doc); expectedRevisionNumber = null; } AssertEx.IsDocumentState(doc, expectedRevisionNumber, prot, pep, prec, tran); return doc; }
public void ConvertDocumentToSmallMolecules(RefinementSettings.ConvertToSmallMoleculesMode mode = RefinementSettings.ConvertToSmallMoleculesMode.formulas, bool invertCharges = false, bool ignoreDecoys = false) { WaitForDocumentLoaded(); RunUI(() => SkylineWindow.ModifyDocument("Convert to small molecules", document => { var refine = new RefinementSettings(); return refine.ConvertToSmallMolecules(document, mode, invertCharges, ignoreDecoys); })); }
public void DoThermoRatioTest(RefinementSettings.ConvertToSmallMoleculesMode smallMoleculesTestMode) { TestSmallMolecules = false; // We do this explicitly var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath; SrmDocument doc = InitThermoDocument(testFilesDir, out docPath); SrmSettings settings = doc.Settings.ChangePeptideModifications(mods => mods.ChangeInternalStandardTypes(new[]{IsotopeLabelType.light})); doc = doc.ChangeSettings(settings); if (smallMoleculesTestMode != RefinementSettings.ConvertToSmallMoleculesMode.none) { var docOrig = doc; var refine = new RefinementSettings(); doc = refine.ConvertToSmallMolecules(doc, smallMoleculesTestMode); // This is our first example of a converted label doc - check roundtripping AssertEx.ConvertedSmallMoleculeDocumentIsSimilar(docOrig, doc); AssertEx.Serializable(doc); } var docContainer = new ResultsTestDocumentContainer(doc, docPath); string extRaw = ExtensionTestContext.ExtThermoRaw; var listChromatograms = new List<ChromatogramSet> { new ChromatogramSet("rep03", new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath( "Site20_STUDY9P_PHASEII_QC_03" + extRaw)) }), new ChromatogramSet("rep05", new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath( "Site20_STUDY9P_PHASEII_QC_05" + extRaw)) }) }; var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); docResults = docContainer.Document; // Make sure all groups have at least 5 transitions (of 6) with ratios int ratioGroupMissingCount = 0; foreach (var nodeGroup in docResults.MoleculeTransitionGroups) { if (nodeGroup.TransitionGroup.LabelType.IsLight) { foreach (var result in nodeGroup.Results) Assert.IsFalse(result[0].Ratio.HasValue, "Light group found with a ratio"); foreach (TransitionDocNode nodeTran in nodeGroup.Children) { foreach (var resultTran in nodeTran.Results) Assert.IsFalse(resultTran[0].Ratio.HasValue, "Light transition found with a ratio"); } } else { bool missingRatio = false; foreach (ChromInfoList<TransitionGroupChromInfo> chromInfoList in nodeGroup.Results) { var ratioHeavy = chromInfoList[0].Ratio; if (!ratioHeavy.HasValue) missingRatio = true; } int ratioCount1 = 0; int ratioCount2 = 0; foreach (TransitionDocNode nodeTranHeavy in nodeGroup.Children) { float? ratioHeavy = nodeTranHeavy.Results[0][0].Ratio; if (ratioHeavy.HasValue) { Assert.IsFalse(float.IsNaN(ratioHeavy.Value) || float.IsInfinity(ratioHeavy.Value)); ratioCount1++; } ratioHeavy = nodeTranHeavy.Results[1][0].Ratio; if (ratioHeavy.HasValue) { Assert.IsFalse(float.IsNaN(ratioHeavy.Value) || float.IsInfinity(ratioHeavy.Value)); ratioCount2++; } } Assert.AreEqual(3, ratioCount1); if (ratioCount2 < 2) ratioGroupMissingCount++; else Assert.IsFalse(missingRatio, "Precursor missing ratio when transitions have ratios"); } } // 3 groups with less than 2 transition ratios Assert.AreEqual(3, ratioGroupMissingCount); // Remove the first light transition, checking that this removes the ratio // from the corresponding heavy transition, but not the entire group, until // after all light transitions have been removed. IdentityPath pathFirstPep = docResults.GetPathTo((int) SrmDocument.Level.Molecules, 0); var nodePep = (PeptideDocNode) docResults.FindNode(pathFirstPep); Assert.AreEqual(2, nodePep.Children.Count); var nodeGroupLight = (TransitionGroupDocNode) nodePep.Children[0]; IdentityPath pathGroupLight = new IdentityPath(pathFirstPep, nodeGroupLight.TransitionGroup); Assert.IsNull(nodeGroupLight.Results[0][0].Ratio, "Light group has ratio"); var nodeGroupHeavy = (TransitionGroupDocNode) nodePep.Children[1]; IdentityPath pathGroupHeavy = new IdentityPath(pathFirstPep, nodeGroupHeavy.TransitionGroup); float? ratioStart = nodeGroupHeavy.Results[0][0].Ratio; Assert.IsTrue(ratioStart.HasValue, "No starting heavy group ratio"); var expectedValues = new[] { 1.403414, 1.38697791, 1.34598482 }; for (int i = 0; i < 3; i++) { var pathLight = docResults.GetPathTo((int) SrmDocument.Level.Transitions, 0); var pathHeavy = docResults.GetPathTo((int) SrmDocument.Level.Transitions, 3); TransitionDocNode nodeTran = (TransitionDocNode) docResults.FindNode(pathHeavy); float? ratioTran = nodeTran.Results[0][0].Ratio; Assert.IsTrue(ratioTran.HasValue, "Expected transition ratio not found"); Assert.AreEqual(ratioTran.Value, expectedValues[i], 1.0e-5); docResults = (SrmDocument) docResults.RemoveChild(pathLight.Parent, docResults.FindNode(pathLight)); nodeTran = (TransitionDocNode) docResults.FindNode(pathHeavy); Assert.IsFalse(nodeTran.Results[0][0].Ratio.HasValue, "Unexpected transiton ratio found"); Assert.AreEqual(pathGroupHeavy, pathHeavy.Parent, "Transition found outside expected group"); // nodePep = (PeptideDocNode) docResults.FindNode(pathFirstPep); nodeGroupHeavy = (TransitionGroupDocNode) docResults.FindNode(pathGroupHeavy); // Assert.AreEqual(nodePep.Results[0][0].RatioToStandard, nodeGroupHeavy.Results[0][0].Ratio, // "Peptide and group ratios not equal"); if (i < 2) { float? ratioGroup = nodeGroupHeavy.Results[0][0].Ratio; Assert.IsTrue(ratioGroup.HasValue, "Group ratio removed with transition ratios"); Assert.AreEqual(ratioStart.Value, ratioGroup.Value, 0.1, "Unexpected group ratio change by more than 0.1"); } else { Assert.IsFalse(nodeGroupHeavy.Results[0][0].Ratio.HasValue, "Group ratio still present with no transition ratios"); } } bool asSmallMolecules = (smallMoleculesTestMode != RefinementSettings.ConvertToSmallMoleculesMode.none); if (!asSmallMolecules) // GetTransitions() doesn't work the same way for small molecules - it only lists existing ones { bool firstAdd = true; var nodeGroupLightOrig = (TransitionGroupDocNode) doc.FindNode(pathGroupLight); DocNode[] lightChildrenOrig = nodeGroupLightOrig.Children.ToArray(); foreach (var nodeTran in nodeGroupLightOrig.GetTransitions(docResults.Settings, null, nodeGroupLightOrig.PrecursorMz, null, null, null, false)) { var transition = nodeTran.Transition; if (!firstAdd && lightChildrenOrig.IndexOf(node => Equals(node.Id, transition)) == -1) continue; // Add the first transition, and then the original transitions docResults = (SrmDocument) docResults.Add(pathGroupLight, nodeTran); nodeGroupHeavy = (TransitionGroupDocNode) docResults.FindNode(pathGroupHeavy); if (firstAdd) Assert.IsNull(nodeGroupHeavy.Results[0][0].Ratio, "Unexpected heavy ratio found"); else Assert.IsNotNull(nodeGroupHeavy.Results[0][0].Ratio, "Heavy ratio null after adding light children"); firstAdd = false; } Assert.AreEqual(ratioStart, nodeGroupHeavy.Results[0][0].Ratio); } // Release file handles docContainer.Release(); testFilesDir.Dispose(); }