Ejemplo n.º 1
0
 private static void PrepareLibraryDlg(ViewLibraryDlg libraryDlg, Action prepareAction = null)
 {
     if (prepareAction != null)
     {
         SkylineWindow.BeginInvoke(prepareAction);
     }
     if (!TryWaitForCondition(2000, () => libraryDlg.IsUpdateComplete))
     {
         libraryDlg.IsUpdateCanceled = true;
         Assert.Fail("Unexpected long wait filling peptide list form");
     }
 }
Ejemplo n.º 2
0
        private void RelaunchLibExplorer(bool showModsDlg, string libName)
        {
            if (_viewLibUI != null)
            {
                RunUI(() => _viewLibUI.CancelDialog());
                WaitForClosedForm(_viewLibUI);
            }
            _viewLibUI = ShowDialog <ViewLibraryDlg>(() => SkylineWindow.OpenLibraryExplorer(libName));
            if (showModsDlg)
            {
                var modDlg = WaitForOpenForm <MultiButtonMsgDlg>();
                if (modDlg != null)
                {
                    RunUI(modDlg.Btn1Click);
                }
                WaitForClosedForm(modDlg);
            }
            RunUI(() =>
            {
                // Find the libary combobox control
                _libComboBox = (ComboBox)_viewLibUI.Controls.Find("comboLibrary", true)[0];
                Assert.IsNotNull(_libComboBox);
                // Find the peptides list control
                _pepList = (ListBox)_viewLibUI.Controls.Find("listPeptide", true)[0];
                Assert.IsNotNull(_pepList);
            });
            WaitForConditionUI(() => _pepList.SelectedIndex != -1);
            WaitForConditionUI(() => _viewLibUI.HasMatches || FindOpenForm <MultiButtonMsgDlg>() != null);
            Assert.IsNull(FindOpenForm <MultiButtonMsgDlg>());
            var docLibraries = SkylineWindow.Document.Settings.PeptideSettings.Libraries;

            if (docLibraries.GetLibrary(libName) == null)
            {
                RunDlg <MultiButtonMsgDlg>(() => _viewLibUI.CheckLibraryInSettings(), msgDlg => msgDlg.Btn0Click());
            }
        }
Ejemplo n.º 3
0
        protected override void DoTest()
        {
            // Exploring a Library,  p. 1
            PeptideSettingsUI peptideSettingsUI = ShowDialog <PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);
            var editListUI =
                ShowDialog <EditListDlg <SettingsListBase <LibrarySpec>, LibrarySpec> >(peptideSettingsUI.EditLibraryList);

            RunDlg <EditLibraryDlg>(editListUI.AddItem, editLibraryDlg =>
            {
                editLibraryDlg.LibrarySpec =
                    new BiblioSpecLibSpec("Experiment 15N", GetTestPath(@"labeled_15N.blib"));
                editLibraryDlg.OkDialog();
            });
            OkDialog(editListUI, editListUI.OkDialog);
            RunUI(() =>
            {
                peptideSettingsUI.SelectedTab     = PeptideSettingsUI.TABS.Library;
                peptideSettingsUI.PickedLibraries = new[] { "Experiment 15N" };
            });
            PauseForScreenShot <PeptideSettingsUI.LibraryTab>("Peptide Settings - Library tab", 3);

            // Modifications Tab in peptideSttingsUI to check "Carbamidomethyl Cysteine"
            const string carbamidoName = StaticModList.DEFAULT_NAME;

            RunUI(() =>
            {
                peptideSettingsUI.SelectedTab      = PeptideSettingsUI.TABS.Modifications;
                peptideSettingsUI.PickedStaticMods = new[] { carbamidoName };
            });
            PauseForScreenShot <PeptideSettingsUI.ModificationsTab>("Peptide Settings - Modifications tab", 4);

            OkDialog(peptideSettingsUI, peptideSettingsUI.OkDialog);

            Assert.IsTrue(WaitForCondition(() =>
                                           SkylineWindow.Document.Settings.PeptideSettings.Libraries.IsLoaded &&
                                           SkylineWindow.Document.Settings.PeptideSettings.Libraries.Libraries.Count > 0));

            // Go to view menu and click Spectral Libraries
            ViewLibraryDlg viewLibraryDlg = ShowDialog <ViewLibraryDlg>(SkylineWindow.ViewSpectralLibraries);
            var            matchedPepsDlg = WaitForOpenForm <AddModificationsDlg>();

            RunUI(matchedPepsDlg.CancelDialog);
            PauseForScreenShot <ViewLibraryDlg>("Library Explorer", 5);

            // Types text in Peptide textbox in the Spectral Library Explorer Window
            RunUI(() =>
            {
                viewLibraryDlg.FilterString = "Q"; // Not L10N
                Assert.AreEqual(7, viewLibraryDlg.PeptideDisplayCount);
            });
            PauseForScreenShot("Library Explorere filtered for peptides beginning with Q", 6);

            RunUI(() =>
            {
                viewLibraryDlg.FilterString = "I"; // Not L10N
                viewLibraryDlg.SetObservedMzValues(true);
                Assert.AreEqual(1, viewLibraryDlg.PeptideDisplayCount);
            });

            // Click B and 2 buttons on the right side of Spectral Library Explorer Window to show b-ions
            RunUI(() =>
            {
                Assert.AreEqual(11, viewLibraryDlg.GraphItem.IonLabels.Count());
                viewLibraryDlg.GraphSettings.ShowBIons   = true;
                viewLibraryDlg.GraphSettings.ShowCharge2 = true;
                Assert.AreEqual(35, viewLibraryDlg.GraphItem.IonLabels.Count());
            });
            PauseForScreenShot <ViewLibraryDlg>("Library Explorer showing ISERT peptide with b and charge 2 ions", 7);

            // Right click on spectrum chart and select Observed m/z Values
            RunUI(() =>
            {
                if (!Settings.Default.ShowObservedMz)
                {
                    if (!Settings.Default.ShowIonMz)
                    {
                        var labelsBefore = viewLibraryDlg.GraphItem.IonLabels.ToArray();
                        Assert.IsFalse(labelsBefore.Contains(label => label.Contains("\n"))); // Not L10N
                    }
                    viewLibraryDlg.SetObservedMzValues(true);
                }
                var labelsAfter = viewLibraryDlg.GraphItem.IonLabels;
                Assert.IsTrue(labelsAfter.Contains(label => label.Contains("\n"))); // Not L10N
            });

            // Clearing Peptide Textbox...
            RunUI(() =>
            {
                viewLibraryDlg.FilterString = string.Empty;
                Assert.AreEqual(43, viewLibraryDlg.PeptideDisplayCount);
            });

            // Matching Modifications p. 7

            // Settings > Peptides Settings
            var          peptideSettingsUI1 = ShowDialog <PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);
            const string glnPyroGluName     = "Gln->pyro-Glu (N-term Q)"; // Not L10N
            var          glnPyroGlu         = UniMod.GetModification(glnPyroGluName, out _);

            glnPyroGlu = glnPyroGlu.ChangeVariable(true);
            AddStaticMod(glnPyroGlu, peptideSettingsUI1, "Edit Structural Modification form", 8);

            RunUI(() => peptideSettingsUI1.PickedStaticMods = new[] { carbamidoName, glnPyroGluName });
            const string label15NName = "Label:15N"; // Not L10N
            var          mod15N       = UniMod.GetModification(label15NName, out _);

            AddHeavyMod(mod15N, peptideSettingsUI1, "Edit Structural Modification form", 9);
            RunUI(() => peptideSettingsUI1.PickedHeavyMods = new[] { label15NName });
            PauseForScreenShot <PeptideSettingsUI.ModificationsTab>("Peptide Settings - Modificatoins tab", 10);

            OkDialog(peptideSettingsUI1, peptideSettingsUI1.OkDialog);

            Assert.IsTrue(WaitForCondition(() =>
                                           SkylineWindow.Document.Settings.PeptideSettings.Modifications.StaticModifications.Count > 0 &&
                                           SkylineWindow.Document.Settings.PeptideSettings.Modifications.AllHeavyModifications.Any()));
            PauseForScreenShot("Peptide list clipped from Library Explorer", 11);

            if (IsCoverShotMode)
            {
                RestoreCoverViewOnScreen(false);
                RunUI(() =>
                {
                    viewLibraryDlg.SetBounds(SkylineWindow.Left, SkylineWindow.Top, SkylineWindow.Width, SkylineWindow.Height);
                });
                TakeCoverShot();

                OkDialog(viewLibraryDlg, viewLibraryDlg.CancelDialog);
                return;
            }
            // Adding Library Peptides to the Document p. 11

            // Adding AEVNGLAAQGKYEGSGEDGGAAAQSLYIANHAY
            var          docInitial       = WaitForProteinMetadataBackgroundLoaderCompletedUI();
            const string peptideSequence1 = "AEVNGLAAQGKYEGSGEDGGAAAQSLYIANHAY"; // Not L10N

            RunUI(() =>
            {
                viewLibraryDlg.FilterString = peptideSequence1;
                Assert.AreEqual(1, viewLibraryDlg.PeptideDisplayCount);
            });
            {
                var msgDlg = ShowDialog <FilterMatchedPeptidesDlg>(viewLibraryDlg.AddPeptide);
                PauseForScreenShot <FilterMatchedPeptidesDlg>("Filter peptides form", 11);

                OkDialog(msgDlg, msgDlg.OkDialog);
            }

            var docAdd1 = WaitForDocumentChange(docInitial);

            Assert.AreEqual(1, docAdd1.PeptideCount);
            Assert.AreEqual(peptideSequence1, docAdd1.Peptides.ToArray()[0].Peptide.Sequence);


            // Adding DNAGAATEEFIK++ (no ok dialog)
            const string peptideSequence2 = "DNAGAATEEFIK"; // Not L10N

            RunUI(() =>
            {
                viewLibraryDlg.FilterString = peptideSequence2 + "++"; // Not L10N
                Assert.AreEqual(2, viewLibraryDlg.PeptideDisplayCount);
            });
            RunUI(viewLibraryDlg.AddPeptide);

            var docAdd2 = WaitForDocumentChange(docAdd1);

            Assert.AreEqual(2, docAdd2.PeptideCount);
            Assert.AreEqual(peptideSequence2, docAdd2.Peptides.ToArray()[1].Peptide.Sequence);

            // Edit > ExpandAll > Peptides
            RunUI(() =>
            {
                SkylineWindow.ExpandPeptides();
                SkylineWindow.Size = new Size(918, 553);
            });
            RestoreViewOnScreen(12);
            PauseForScreenShot("Main window", 12);

            // Adding DNAGAATEEFIKR++ (has ok)
            const string peptideSequence3 = "DNAGAATEEFIKR"; // Not L10N

            RunUI(() =>
            {
                viewLibraryDlg.FilterString = peptideSequence3 + "++"; // Not L10N
                Assert.AreEqual(2, viewLibraryDlg.PeptideDisplayCount);
            });

            RunDlg <FilterMatchedPeptidesDlg>(viewLibraryDlg.AddPeptide, msgDlg => msgDlg.OkDialog());
            var docAdd3 = WaitForDocumentChange(docAdd2);

            Assert.AreEqual(3, docAdd3.PeptideCount);
            Assert.AreEqual(2, docAdd3.Peptides.ToArray()[2].Children.Count);
            Assert.AreEqual(peptideSequence3, docAdd3.Peptides.ToArray()[2].Peptide.Sequence);

            // Adding DNAGAATEEFIKR+++ (has ok)
            RunUI(() =>
            {
                viewLibraryDlg.FilterString = peptideSequence3 + "+++"; // Not L10N
                Assert.AreEqual(1, viewLibraryDlg.PeptideDisplayCount);
            });
            WaitForGraphs();

            RunDlg <FilterMatchedPeptidesDlg>(viewLibraryDlg.AddPeptide, msgDlg => msgDlg.OkDialog());
            var docAdd4 = WaitForDocumentChange(docAdd3);

            // peptideSequence4 is considered a sub of peptideSequence3
            Assert.AreEqual(3, docAdd4.PeptideCount);
            Assert.AreEqual(4, docAdd4.Peptides.ToArray()[2].Children.Count);

            // Close the Library Explorer dialog
            OkDialog(viewLibraryDlg, viewLibraryDlg.CancelDialog);

            // Save current document as 15N_library_peptides.sky
            RunUI(() => SkylineWindow.SaveDocument(GetTestPath(@"15N_library_peptides.sky")));
            RunUI(() => SkylineWindow.NewDocument());

            // Neutral Losses p. 13
            PeptideSettingsUI settingsUI = ShowDialog <PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);

            RunUI(() =>
            {
                settingsUI.SelectedTab      = PeptideSettingsUI.TABS.Modifications;
                settingsUI.PickedStaticMods = new[] { carbamidoName };           // Not L10N
                settingsUI.PickedHeavyMods  = new string[0];
                settingsUI.PickedLibraries  = new string[0];
            });
            PauseForScreenShot <PeptideSettingsUI.ModificationsTab>("Peptide Settings - Modifications tab", 14);

            var editListUI1 =
                ShowDialog <EditListDlg <SettingsListBase <LibrarySpec>, LibrarySpec> >(settingsUI.EditLibraryList);
            const string humanPhosphoLibName = "Human Phospho"; // Not L10N

            RunDlg <EditLibraryDlg>(editListUI1.AddItem, editLibraryDlg =>
            {
                editLibraryDlg.LibrarySpec =
                    new BiblioSpecLibSpec(humanPhosphoLibName, GetTestPath(@"phospho.blib"));
                editLibraryDlg.OkDialog();
            });
            OkDialog(editListUI1, editListUI1.OkDialog);
            RunUI(() =>
            {
                settingsUI.SelectedTab     = PeptideSettingsUI.TABS.Library;
                settingsUI.PickedLibraries = new[] { humanPhosphoLibName };
            });
            PauseForScreenShot <PeptideSettingsUI.LibraryTab>("Peptide Settings - Library tab", 15);

            {
                var msgDlg = ShowDialog <MultiButtonMsgDlg>(() => settingsUI.ShowViewLibraryDlg());
                PauseForScreenShot <MultiButtonMsgDlg>("Save changes", 15);

                OkDialog(msgDlg, msgDlg.Btn0Click);
            }

            Assert.IsTrue(WaitForCondition(() =>
                                           SkylineWindow.Document.Settings.PeptideSettings.Modifications.StaticModifications.Count == 1 &&
                                           !SkylineWindow.Document.Settings.PeptideSettings.Modifications.AllHeavyModifications.Any() &&
                                           SkylineWindow.Document.Settings.PeptideSettings.Libraries.IsLoaded &&
                                           SkylineWindow.Document.Settings.PeptideSettings.Libraries.Libraries.Count > 0));

            // Ignore modification matching form
            var matchedPepModsDlg = WaitForOpenForm <AddModificationsDlg>();

            RunUI(matchedPepModsDlg.CancelDialog);

            var       viewLibraryDlg1 = WaitForOpenForm <ViewLibraryDlg>();
            const int countLabels1    = 15;
            const int countLabels2    = 18;

            RunUI(() =>
            {
                viewLibraryDlg1.FilterString = "AISS"; // Not L10N
                Assert.AreEqual(2, viewLibraryDlg1.PeptideDisplayCount);
                Assert.AreEqual(countLabels1, viewLibraryDlg1.GraphItem.IonLabels.Count());
            });
            PauseForScreenShot <GraphSpectrum>("Spectrum graph metafile", 16);   // p. 16, figure 1a
            RunUI(() =>
            {
                viewLibraryDlg1.SelectedIndex = 1;
                Assert.AreEqual(countLabels2, viewLibraryDlg1.GraphItem.IonLabels.Count());
            });
            PauseForScreenShot <GraphSpectrum>("Spectrum graph metafile", 16);   // p. 16, figure 1b

            docInitial = SkylineWindow.Document;

            var          peptideSettingsUI2 = ShowDialog <PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);
            const string phosphoModName     = "Phospho (ST)";                                                                      // Not L10N
            var          phosphoSt          = new StaticMod(phosphoModName, "S, T", null, true, "HPO3", LabelAtoms.None,           // Not L10N
                                                            RelativeRT.Unknown, null, null, new[] { new FragmentLoss("H3PO4"), }); // Not L10N

            AddStaticMod(phosphoSt, peptideSettingsUI2, "Edit Structural Modifcation form", 17);

            // Check Phospho (ST) and Carbamidomethyl Cysteine
            RunUI(() => peptideSettingsUI2.PickedStaticMods = new[] { phosphoModName, carbamidoName }); // Not L10N
            OkDialog(peptideSettingsUI2, peptideSettingsUI2.OkDialog);

            var docPhospho = WaitForDocumentChange(docInitial);

            Assert.IsTrue(docPhospho.Settings.PeptideSettings.Modifications.StaticModifications.Count == 2);

            string    lossText         = Math.Round(-phosphoSt.Losses[0].MonoisotopicMass, 1).ToString(LocalizationHelper.CurrentCulture);
            const int countLossLabels1 = 12;
            const int countLossLabels2 = 15;
            const int countPrecursors1 = 1;
            const int countPrecursors2 = 2;

            RunUI(() =>
            {
                // New ions should be labeled, because of the added modification with loss
                viewLibraryDlg1.SelectedIndex = 0;
                Assert.AreEqual(countLabels1 + countLossLabels1, viewLibraryDlg1.GraphItem.IonLabels.Count());

                viewLibraryDlg1.GraphSettings.ShowPrecursorIon = true;

                // Make sure the precursor -98 ion was added
                var labelsPhospho = viewLibraryDlg1.GraphItem.IonLabels.ToList();
                Assert.AreEqual(countLossLabels1 + 1, labelsPhospho.Count(label => label.Contains(lossText)));
                Assert.IsTrue(labelsPhospho.Contains(label => label.Contains(string.Format("{0} {1}", IonType.precursor.GetLocalizedString(), lossText))));
                Assert.AreEqual(countLabels1 + countLossLabels1 + countPrecursors1, labelsPhospho.Count);
            });
            PauseForScreenShot <GraphSpectrum>("Spectrum graph metafile", 18);   // p. 18, figure 1a.

            RunUI(() =>
            {
                viewLibraryDlg1.SelectedIndex = 1;
                var labelsPhospho             = viewLibraryDlg1.GraphItem.IonLabels.ToList();
                Assert.AreEqual(countLossLabels2 + 1, labelsPhospho.Count(label => label.Contains(lossText)));
                Assert.IsTrue(labelsPhospho.Contains(label => label.Contains(string.Format("{0} {1}", IonType.precursor.GetLocalizedString(), lossText))));
                Assert.AreEqual(countLabels2 + countLossLabels2 + countPrecursors2, labelsPhospho.Count);
            });
            PauseForScreenShot <GraphSpectrum>("Spectrum graph metafile", 18);   // p. 18, figure 1b.

            // Matching Library Peptides to Proteins p. 18
            var peptideSettingsUI3         = ShowDialog <PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);
            var buildBackgroundProteomeDlg =
                ShowDialog <BuildBackgroundProteomeDlg>(peptideSettingsUI3.ShowBuildBackgroundProteomeDlg);

            RunUI(() =>
            {
                buildBackgroundProteomeDlg.BackgroundProteomePath = GetTestPath(@"human.protdb");
                buildBackgroundProteomeDlg.BackgroundProteomeName = "Human (mini)";
            });
            PauseForScreenShot <BuildBackgroundProteomeDlg>("Edit Background Proteome", 19);   // p. 19

            OkDialog(buildBackgroundProteomeDlg, buildBackgroundProteomeDlg.OkDialog);

            // Select Max Missed Cleavages to be 2
            RunUI(() =>
            {
                peptideSettingsUI3.MissedCleavages = 2;
            });
            OkDialog(peptideSettingsUI3, peptideSettingsUI3.OkDialog);

            WaitForBackgroundProteomeLoaderCompleted(); // wait for protDB to populate protein metadata

            RunUI(() =>
            {
                viewLibraryDlg1.FilterString = string.Empty;
                Assert.AreEqual(100, viewLibraryDlg1.PeptideDisplayCount);
            });

            // Check Associate Proteins check box on Spectral Library Explorer form
            RunUI(() =>
            {
                viewLibraryDlg1.AssociateMatchingProteins = true;
            });

            docInitial = WaitForProteinMetadataBackgroundLoaderCompletedUI();

            var confirmUpgrade = ShowDialog <AlertDlg>(viewLibraryDlg1.AddAllPeptides);
            // Add everything in the library to the document.
            var filterMatchedPeptidesDlg =
                ShowDialog <FilterMatchedPeptidesDlg>(confirmUpgrade.ClickYes);

            RunUI(() =>
            {
                filterMatchedPeptidesDlg.DuplicateProteinsFilter =
                    BackgroundProteome.DuplicateProteinsFilter.FirstOccurence;
                filterMatchedPeptidesDlg.AddUnmatched = true;
                filterMatchedPeptidesDlg.AddFiltered  = true;

                // Checks that Peptides were added with the correct buttons selected...
                Assert.AreEqual(163, filterMatchedPeptidesDlg.DuplicateMatchesCount);
                Assert.AreEqual(2, filterMatchedPeptidesDlg.UnmatchedCount);
            });
            PauseForScreenShot <FilterMatchedPeptidesDlg>("Filter Peptides", 20);   // p. 20, figure 1

            {
                var msgDlg = ShowDialog <MultiButtonMsgDlg>(filterMatchedPeptidesDlg.OkDialog);
                PauseForScreenShot("Message form", 20);   // p. 20, figure 2

                OkDialog(msgDlg, msgDlg.Btn1Click);
            }
            OkDialog(viewLibraryDlg1, viewLibraryDlg1.CancelDialog);

            var docProteins = WaitForDocumentChange(docInitial);

            AssertEx.IsDocumentState(docProteins, null, 250, 346, 347, 1041);

            RestoreViewOnScreen(21);
            PauseForScreenShot("Main window", 21);

            OkDialog(viewLibraryDlg, viewLibraryDlg.Close);
        }
Ejemplo n.º 4
0
        private void TestModificationMatching()
        {
            var phosphoLossMod = new StaticMod("Phospho Loss", "S, T", null, true, "HPO3",
                                               LabelAtoms.None, RelativeRT.Matching, null, null, new[] { new FragmentLoss("H3PO4"), });

            Settings.Default.StaticModList.Clear();
            Settings.Default.StaticModList.Add(phosphoLossMod.ChangeExplicit(false));

            var phosphoNotVariable = SkylineWindow.Document.Settings.ChangePeptideModifications(
                mods => mods.ChangeStaticModifications(new[] { phosphoLossMod.ChangeExplicit(false) }));

            RunUI(() => SkylineWindow.ModifyDocument("Change static mods",
                                                     doc => doc.ChangeSettings(phosphoNotVariable)));

            RelaunchLibExplorer(false, PHOSPHO_LIB);

            // Test doesn't find variable match if implicit match exists in doc
            WaitForConditionUI(() => !_viewLibUI.HasUnmatchedPeptides);
            using (new CheckDocumentStateWithPossibleProteinMetadataBackgroundUpdate(1, 4, 4, 12))
            {
                RunDlg <MultiButtonMsgDlg>(_viewLibUI.AddAllPeptides, msgDlg => msgDlg.Btn1Click());
            }
            Assert.IsTrue(SkylineWindow.Document.Settings.PeptideSettings.Modifications.StaticModifications
                          .Contains(mod => mod.Equivalent(phosphoLossMod)));
            Assert.IsFalse(SkylineWindow.Document.Settings.PeptideSettings.Modifications.StaticModifications
                           .Contains(mod => mod.Equivalent(phosphoLossMod) && mod.IsVariable));
            RunUI(SkylineWindow.Undo);

            // Test creates variable mod if implicit match exists in globals
            var pepModsNoMods1 =
                SkylineWindow.Document.Settings.ChangePeptideModifications(mods =>
                                                                           mods.ChangeStaticModifications(new StaticMod[0]));

            RunUI(() => SkylineWindow.ModifyDocument("Change static mods", doc =>
                                                     doc.ChangeSettings(pepModsNoMods1)));

            RelaunchLibExplorer(false, PHOSPHO_LIB);

            using (new CheckDocumentStateWithPossibleProteinMetadataBackgroundUpdate(1, 4, 4, 12))
            {
                RunDlg <MultiButtonMsgDlg>(_viewLibUI.AddAllPeptides, msgDlg => msgDlg.Btn1Click());
            }
            Assert.IsTrue(SkylineWindow.Document.Settings.PeptideSettings.Modifications.StaticModifications
                          .Contains(mod => mod.Equivalent(phosphoLossMod) && mod.IsVariable));
            Assert.IsFalse(SkylineWindow.Document.Settings.PeptideSettings.Modifications.StaticModifications
                           .Contains(mod => mod.Equivalent(phosphoLossMod) && !mod.IsVariable));

            // Test implicit mods only created if safe to do so
            RunUI(() => SkylineWindow.Undo());
            RunDlg <MultiButtonMsgDlg>(() => _libComboBox.SelectedIndex = 4, msgDlg => msgDlg.Btn1Click());
            WaitForConditionUI(() => _pepList.SelectedIndex != -1);
            WaitForConditionUI(() => _viewLibUI.HasMatches);
            RunDlg <MultiButtonMsgDlg>(() => _viewLibUI.CheckLibraryInSettings(),
                                       msgDlg => msgDlg.Btn0Click());

            var fmpDlg0 = ShowDialog <FilterMatchedPeptidesDlg>(() => _viewLibUI.AddAllPeptides());

            RunUI(() => fmpDlg0.AddFiltered = true);
            using (new CheckDocumentStateWithPossibleProteinMetadataBackgroundUpdate(1, 82, 96,
                                                                                     TransitionGroup.IsAvoidMismatchedIsotopeTransitions ? 279 : 282))
            {
                RunDlg <MultiButtonMsgDlg>(fmpDlg0.OkDialog, msgDlg => msgDlg.Btn1Click());
            }
            // Implicit mod is created because there are no conflicting peptides in the current document.
            Assert.IsTrue(
                SkylineWindow.Document.Settings.PeptideSettings.Modifications.StaticModifications.Contains(mod =>
                                                                                                           !mod.IsExplicit && !mod.IsVariable));

            var nodeRemoved = "";

            RunUI(() =>
            {
                Settings.Default.EditFindText = "C";
                SkylineWindow.FindNext(false);
                nodeRemoved = ((PeptideTreeNode)SkylineWindow.SelectedNode).DocNode.Peptide.Sequence;
                SkylineWindow.EditDelete();
            });
            Assert.IsFalse(
                SkylineWindow.Document.Settings.PeptideSettings.Modifications.StaticModifications.Contains(mod =>
                                                                                                           mod.IsExplicit));
            var pepModsNoMods2 =
                SkylineWindow.Document.Settings.ChangePeptideModifications(mods =>
                                                                           mods.ChangeStaticModifications(new StaticMod[0]));

            RunUI(() => SkylineWindow.ModifyDocument("Change static mods", doc =>
                                                     doc.ChangeSettings(pepModsNoMods2)));
            RelaunchLibExplorer(false, YEAST);
            RunUI(() =>
            {
                _viewLibUI.ChangeSelectedPeptide(nodeRemoved.Replace("C", "C[+57.0]"));
                _viewLibUI.AddPeptide();
            });

            // Explicit mod is created because an implicit mod conflicts with current document settings.
            Assert.IsFalse(
                SkylineWindow.Document.Settings.PeptideSettings.Modifications.StaticModifications.Contains(mod =>
                                                                                                           !mod.IsExplicit));
            Assert.IsTrue(SkylineWindow.Document.Peptides.Contains(nodePep =>
                                                                   nodePep.Peptide.Sequence == nodeRemoved && nodePep.HasExplicitMods));

            // Implicit modifications only added to document if they apply to the added peptide
            RunUI(() =>
            {
                SkylineWindow.SelectAll();
                SkylineWindow.EditDelete();
            });
            var pepModsNoMods3 =
                SkylineWindow.Document.Settings.ChangePeptideModifications(mods =>
                                                                           mods.ChangeStaticModifications(new StaticMod[0]));

            RunUI(() => SkylineWindow.ModifyDocument("Change static mods", doc =>
                                                     doc.ChangeSettings(pepModsNoMods3)));
            Settings.Default.StaticModList.Clear();
            RelaunchLibExplorer(true, ANL_COMBINED);
            RunUI(() => _viewLibUI.AddPeptide());
            Assert.AreEqual(0, Settings.Default.StaticModList.Count);

            // Variable mods not added if conflict with existing peptides.
            RunUI(() =>
            {
                _pepList.SelectedIndex = 1;
                _viewLibUI.AddPeptide();
            });
            Assert.IsFalse(SkylineWindow.Document.Peptides.Contains(nodePep =>
                                                                    nodePep.HasExplicitMods && nodePep.ExplicitMods.IsVariableStaticMods));

            // Test removing mod from globals affects matches
            var pepModsNoMods4 = SkylineWindow.Document.Settings.ChangePeptideModifications(mods =>
                                                                                            mods.ChangeStaticModifications(Settings.Default.StaticModList.GetDefaults().ToArray()));

            RunUI(() => SkylineWindow.ModifyDocument("Change static mods", doc =>
                                                     doc.ChangeSettings(pepModsNoMods4)));
            Settings.Default.StaticModList.Clear();
            Settings.Default.StaticModList.AddRange(Settings.Default.StaticModList.GetDefaults());
            RelaunchLibExplorer(false, YEAST);
            Assert.IsFalse(_viewLibUI.HasUnmatchedPeptides);

            // Test removing mod from doc does not remove matches
            Settings.Default.StaticModList.Clear();
            var pepModsNone = SkylineWindow.Document.Settings.ChangePeptideModifications(mods =>
                                                                                         mods.ChangeStaticModifications(new StaticMod[0]));

            RunUI(() => SkylineWindow.ModifyDocument("Change static mods", doc =>
                                                     doc.ChangeSettings(pepModsNone)));
            RunUI(SkylineWindow.Activate);
            RunUI(_viewLibUI.Activate);
            WaitForConditionUI(() => _pepList.Items.Count == 96);
            WaitForConditionUI(() => _pepList.SelectedIndex != -1);
            Assert.IsFalse(_viewLibUI.HasUnmatchedPeptides);

            // Relaunch explorer without modification matching
            RunUI(() => _viewLibUI.CancelDialog());
            WaitForClosedForm(_viewLibUI);
            _viewLibUI = ShowDialog <ViewLibraryDlg>(() => SkylineWindow.OpenLibraryExplorer(YEAST));
            var matchedPepModsDlg = WaitForOpenForm <MultiButtonMsgDlg>();

            RunUI(matchedPepModsDlg.BtnCancelClick);
            WaitForConditionUI(() => _pepList.Items.Count == 96);
            WaitForConditionUI(() => _pepList.SelectedIndex != -1);
            Assert.IsTrue(_viewLibUI.HasUnmatchedPeptides);

            // Test adding mod to doc affects matches
            Settings.Default.StaticModList.AddRange(Settings.Default.StaticModList.GetDefaults());
            var pepModsDefault = SkylineWindow.Document.Settings.ChangePeptideModifications(mods =>
                                                                                            mods.ChangeStaticModifications(Settings.Default.StaticModList.Select(mod =>
                                                                                                                                                                 mod.ChangeExplicit(false)).ToArray()));

            RunUI(() => SkylineWindow.ModifyDocument("Change static mods", doc =>
                                                     doc.ChangeSettings(pepModsDefault)));
            RunUI(SkylineWindow.Activate);
            RunUI(_viewLibUI.Activate);
            WaitForConditionUI(() => _pepList.Items.Count == 96);
            WaitForConditionUI(() => _pepList.SelectedIndex != -1);
            Assert.IsFalse(_viewLibUI.HasUnmatchedPeptides);

            RunUI(() => _viewLibUI.CancelDialog());
            WaitForClosedForm(_viewLibUI);
        }
Ejemplo n.º 5
0
        private void TestBasicFunctionality()
        {
            // Launch the Library Explorer dialog
            _viewLibUI = ShowDialog <ViewLibraryDlg>(SkylineWindow.ViewSpectralLibraries);

            // Ensure the appropriate default library is selected
            ComboBox libComboBox = null;
            ListBox  pepList     = null;
            string   libSelected = null;

            RunUI(() =>
            {
                libComboBox = (ComboBox)_viewLibUI.Controls.Find("comboLibrary", true)[0];
                Assert.IsNotNull(libComboBox);
                libSelected = libComboBox.SelectedItem.ToString();

                // Find the peptides list control
                pepList = (ListBox)_viewLibUI.Controls.Find("listPeptide", true)[0];
                Assert.IsNotNull(pepList);
            });
            Assert.AreEqual(_testLibs[0].Name, libSelected);

            // Initially, peptide with index 0 should be selected
            WaitForConditionUI(() => pepList.SelectedIndex != -1);
            var modDlg = WaitForOpenForm <MultiButtonMsgDlg>();

            RunUI(modDlg.Btn1Click);

            ViewLibraryPepInfo previousPeptide = new ViewLibraryPepInfo();
            int peptideIndex = -1;

            RunUI(() =>
            {
                previousPeptide = (ViewLibraryPepInfo)pepList.SelectedItem;
                peptideIndex    = pepList.SelectedIndex;
            });
            Assert.IsNotNull(previousPeptide);
            Assert.AreEqual(0, peptideIndex);
            Assert.AreEqual(3, previousPeptide.Charge, "Expected charge 3 on " + previousPeptide.DisplayString);

            // Now try to select a different peptide and check to see if the
            // selection changes
            const int selectPeptideIndex = 1;

            RunUI(() =>
            {
                pepList.SelectedIndex = selectPeptideIndex;
            });

            ViewLibraryPepInfo selPeptide = new ViewLibraryPepInfo();

            RunUI(() =>
            {
                Assert.AreEqual(selectPeptideIndex, pepList.SelectedIndex); // Did selection change work?

                selPeptide = (ViewLibraryPepInfo)pepList.SelectedItem;
            });
            Assert.IsNotNull(selPeptide);
            if (Equals(previousPeptide, selPeptide))
            {
                Assert.AreNotEqual(previousPeptide.DisplayString, selPeptide.DisplayString);
            }
            Assert.AreEqual(2, selPeptide.Charge, "Expected charge 2 on " + selPeptide.DisplayString);

            // Click the "Next" link
            RunUI(() =>
            {
                var nextLink = (IButtonControl)_viewLibUI.Controls.Find("NextLink", true)[0];
                Assert.IsNotNull(nextLink);

                nextLink.PerformClick();
            });
            RunUI(() =>
            {
                previousPeptide = (ViewLibraryPepInfo)pepList.SelectedItem;
            });

            // Click "Previous" link and ensure the peptide selected changes
            RunUI(() =>
            {
                var previousLink = (IButtonControl)_viewLibUI.Controls.Find("PreviousLink", true)[0];
                Assert.IsNotNull(previousLink);

                previousLink.PerformClick();
            });
            RunUI(() =>
            {
                selPeptide = (ViewLibraryPepInfo)pepList.SelectedItem;
            });
            Assert.AreNotEqual(previousPeptide, selPeptide);


            // Test valid peptide search
            TextBox pepTextBox = null;

            RunUI(() =>
            {
                pepTextBox = (TextBox)_viewLibUI.Controls.Find("textPeptide", true)[0];
                Assert.IsNotNull(pepTextBox);

                pepTextBox.Focus();
                pepTextBox.Text = _testLibs[0].UniquePeptide;
            });
            int pepsCount = 0;

            RunUI(() =>
            {
                selPeptide = (ViewLibraryPepInfo)pepList.SelectedItem;
                pepsCount  = pepList.Items.Count;
            });
            Assert.AreEqual(_testLibs[0].UniquePeptide, selPeptide.DisplayString);
            Assert.AreEqual(1, pepsCount);

            // Test invalid peptide search
            RunUI(() =>
            {
                pepTextBox.Focus();
                pepTextBox.Text = INVALID_SEARCH;
            });
            RunUI(() =>
            {
                pepsCount = pepList.Items.Count;
            });
            Assert.AreEqual(0, pepsCount);

            // Test clearing invalid peptide search
            RunUI(() =>
            {
                pepTextBox.Focus();
                pepTextBox.Text = "";
            });
            selPeptide = new ViewLibraryPepInfo();
            RunUI(() =>
            {
                selPeptide = (ViewLibraryPepInfo)pepList.SelectedItem;
                pepsCount  = pepList.Items.Count;
            });
            Assert.IsNotNull(selPeptide);
            Assert.AreNotEqual(0, pepsCount);

            // Test selecting a different library
            previousPeptide = selPeptide;
            RunDlg <MultiButtonMsgDlg>(() => libComboBox.SelectedIndex = 1, dlg => dlg.Btn1Click());
            RunUI(() =>
            {
                libComboBox.SelectedIndex = 1;
            });
            RunUI(() =>
            {
                libSelected = libComboBox.SelectedItem.ToString();
            });
            Assert.AreEqual(libSelected, _testLibs[1].Name);
            RunUI(() =>
            {
                selPeptide = (ViewLibraryPepInfo)pepList.SelectedItem;
            });
            Assert.IsNotNull(selPeptide);
            Assert.AreNotEqual(previousPeptide, selPeptide);

            // If the library is not in the document settings, offer to add the library to the settings.
            // If the user declines, add the peptides anyways, but strip them so they do not appear to be
            // connected to any library.
            RunDlg <MultiButtonMsgDlg>(_viewLibUI.AddPeptide, msgDlg => msgDlg.Btn1Click());
            Assert.AreEqual(1, SkylineWindow.Document.PeptideCount);
            Assert.IsFalse(SkylineWindow.Document.Peptides.Contains(nodePep => nodePep.HasLibInfo));
            RunUI(() =>
            {
                SkylineWindow.SelectAll();
                SkylineWindow.EditDelete();
            });

            // Test adding peptides offers to add library if not already in settings.
            // Test add single peptide.
            using (new CheckDocumentStateWithPossibleProteinMetadataBackgroundUpdate(1, 1, 1, 3))
            {
                RunDlg <MultiButtonMsgDlg>(_viewLibUI.AddPeptide, msgDlg => msgDlg.Btn0Click());
            }
            RunUI(SkylineWindow.EditDelete);

            // Test unmatched peptides are correct.
            // One unmatched because its precursor m/z is outside the instrument measurement range
            AddAllPeptides(1, 4, 3);

            // Verify that everything matches, given a wide enough mass range
            RunUI(() => SkylineWindow.ModifyDocument("Change m/z range",
                                                     doc => doc.ChangeSettings(doc.Settings.ChangeTransitionInstrument(inst =>
                                                                                                                       inst.ChangeMaxMz(TransitionInstrument.MAX_MEASURABLE_MZ)))));
            WaitForConditionUI(() => !_viewLibUI.HasUnmatchedPeptides);
            RunUI(() => SkylineWindow.ModifyDocument("Change m/z range",
                                                     doc => doc.ChangeSettings(doc.Settings.ChangeTransitionInstrument(inst =>
                                                                                                                       inst.ChangeMaxMz(1500)))));
            WaitForConditionUI(() => _viewLibUI.HasUnmatchedPeptides);

            // Test library peptides are merged without duplicates.
            TestForDuplicatePeptides();

            // Test library peptides only get added to the document once.
            var docOriginal = SkylineWindow.Document;

            RunDlg <MessageDlg>(_viewLibUI.AddPeptide, msgDlg => msgDlg.OkDialog());
            var filterMatchedPeptidesDlg5 = ShowDialog <FilterMatchedPeptidesDlg>(_viewLibUI.AddAllPeptides);

            RunDlg <MessageDlg>(filterMatchedPeptidesDlg5.OkDialog, msgDlg => msgDlg.OkDialog());
            Assert.AreSame(docOriginal, SkylineWindow.Document);

            // Test missing peptides added.
            RunUI(() =>
            {
                var sequenceTree          = SkylineWindow.SequenceTree;
                var nodePeps              = sequenceTree.Nodes[0].Nodes;
                sequenceTree.SelectedNode = nodePeps[0];
                sequenceTree.KeysOverride = Keys.Control;
                for (int i = 2; i < 10; i += 2)
                {
                    sequenceTree.SelectedNode = nodePeps[i];
                }
                sequenceTree.KeysOverride = Keys.None;
                SkylineWindow.EditDelete();
            });
            AddAllPeptides();
            var docAddBack = SkylineWindow.Document;

            // Peptides will be added back in a different order
            AssertEx.IsDocumentState(docAddBack, null,
                                     docOriginal.PeptideGroupCount, docOriginal.PeptideCount,
                                     docOriginal.PeptideTransitionGroupCount, docOriginal.PeptideTransitionCount);
            TestSamePeptides(docOriginal.Peptides);

            // Test missing transition groups added correctly.
            RunUI(() =>
            {
                var sequenceTree          = SkylineWindow.SequenceTree;
                sequenceTree.SelectedNode = sequenceTree.Nodes[0].Nodes[0].Nodes[0];
                sequenceTree.KeysOverride = Keys.Control;
                for (int x = 0; x < 5; x++)
                {
                    var nodePep    = sequenceTree.Nodes[0].Nodes[x];
                    var nodeGroups = nodePep.Nodes;
                    for (int i = 0; i < nodeGroups.Count; i += 2)
                    {
                        sequenceTree.SelectedNode = nodeGroups[i];
                    }
                }
                SkylineWindow.EditDelete();
            });
            AddAllPeptides();
            var docAddBackGroups = SkylineWindow.Document;

            // Check all precursor charges present.
            foreach (PeptideDocNode nodePep in docOriginal.Peptides)
            {
                var key = nodePep.Key;
                foreach (TransitionGroupDocNode nodeGroup in nodePep.Children)
                {
                    var charge = nodeGroup.TransitionGroup.PrecursorCharge;
                    Assert.IsTrue(docAddBackGroups.Peptides.Contains(nodePepDoc => Equals(key, nodePepDoc.Key) &&
                                                                     nodePepDoc.HasChildCharge(charge)));
                }
            }
            // Check no duplicate TransitionGroups added.
            TestForDuplicateTransitionGroups();

            // Test peptides get heavy label modifications.
            List <StaticMod> heavyMods15N =
                new List <StaticMod> {
                new StaticMod("15N", null, null, null, LabelAtoms.N15, null, null)
            };

            RunUI(() =>
            {
                SkylineWindow.SelectAll();
                SkylineWindow.EditDelete();
                var settings = SkylineWindow.Document.Settings.ChangePeptideModifications(mods => new PeptideModifications(mods.StaticModifications,
                                                                                                                           new[] { new TypedModifications(IsotopeLabelType.heavy, heavyMods15N) }));
                SkylineWindow.ModifyDocument("Change heavy modifications", doc => doc.ChangeSettings(settings));
            });
            AddAllPeptides();

            // All peptides should have a heavy label transition group.
            // There should be no peptide whose children do not contain a transition group with heavy label type.
            Assert.IsFalse(SkylineWindow.Document.Peptides.Contains(nodePep =>
                                                                    !nodePep.Children.Contains(nodeGroup =>
                                                                                               ((TransitionGroupDocNode)nodeGroup).TransitionGroup.LabelType.Equals(IsotopeLabelType.heavy))));

            // Test peptide setting changes update the library explorer.
            RunUI(() => SkylineWindow.ModifyDocument("Change static modifications",
                                                     doc => doc.ChangeSettings(SkylineWindow.Document.Settings.ChangePeptideModifications(mods =>
                                                                                                                                          mods.ChangeStaticModifications(new List <StaticMod>())))));
            AddAllPeptides(1, 8, 3);

            // Along with Heavy 15N added earlier in the test, adding this modification means that all library peptides
            // will match to the document settings.
            StaticMod varMetOxidized = new StaticMod("Methionine Oxidized", "M", null, true, "O",
                                                     LabelAtoms.None, RelativeRT.Matching, null, null, null);
            var metOxidizedSettings = SkylineWindow.Document.Settings.ChangePeptideModifications(mods =>
                                                                                                 mods.ChangeStaticModifications(new[] { varMetOxidized }));

            RunUI(() =>
            {
                SkylineWindow.SelectAll();
                SkylineWindow.EditDelete();
                SkylineWindow.ModifyDocument("Change static mods",
                                             doc => doc.ChangeSettings(metOxidizedSettings));
            });

            // Switch to ANL_Combined library
            RunDlg <MultiButtonMsgDlg>(() => { libComboBox.SelectedIndex = 2; }, msgDlg => msgDlg.BtnCancelClick());

            // User prompted to add library since not in current settings.
            RunDlg <MultiButtonMsgDlg>(() => _viewLibUI.CheckLibraryInSettings(), msgDlg => msgDlg.Btn0Click());
            // Add single peptide to the document.
            RunUI(_viewLibUI.AddPeptide);
            WaitForProteinMetadataBackgroundLoaderCompletedUI();
            var nodePepAdded = SkylineWindow.SequenceTree.Nodes[0].Nodes[0];

            // Because document settings match the library, no duplicates should be found.
            AddAllPeptides(0);

            // Even though there are two matches in the library for the the nodePep we just added
            // to the document (one with light modifications and one with heavy), the two spectrum
            // both have the same charge. In this case, both spectrum should be ignored when Add All
            // is called.
            Assert.AreEqual(nodePepAdded, SkylineWindow.SequenceTree.Nodes[0].Nodes[0]);
            Assert.AreEqual(3, SkylineWindow.Document.PeptideCount);

            // Switch to the Phospho Loss Library
            RunDlg <MultiButtonMsgDlg>(() => libComboBox.SelectedIndex = 3, msgDlg => msgDlg.Btn1Click());

            // Add modifications to the document matching the settings of the library.
            var phosphoLossMod = new StaticMod("Phospho Loss", "S, T", null, true, "HPO3",
                                               LabelAtoms.None, RelativeRT.Matching, null, null, new[] { new FragmentLoss("H3PO4"), });
            var phosphoLossSettings =
                SkylineWindow.Document.Settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(new[] { phosphoLossMod }));

            RunUI(() =>
                  SkylineWindow.ModifyDocument("Change static mods", doc => doc.ChangeSettings(phosphoLossSettings)));
            RunDlg <MultiButtonMsgDlg>(() => _viewLibUI.CheckLibraryInSettings(), msgDlg => msgDlg.Btn0Click());

            // Again, we should be able to match all peptides since the document settings match use the peptides found
            // in the library.
            RunDlg <MultiButtonMsgDlg>(_viewLibUI.AddAllPeptides, msgDlg =>
            {
                Assert.AreEqual(0, (int)msgDlg.Tag);
                msgDlg.Btn1Click();
            });
            // Test losses are being displayed in the graph, indicating that the spectrum have been matched correctly.
            WaitForConditionUI(() => _viewLibUI.GraphItem.IonLabels.Contains(str => str.Contains("98")));
            Assert.IsTrue(_viewLibUI.GraphItem.IonLabels.Contains(str => str.Contains("98")));

            // Associate yeast background proteome
            var peptideSettingsUI = ShowDialog <PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);

            RunDlg <BuildBackgroundProteomeDlg>(peptideSettingsUI.ShowBuildBackgroundProteomeDlg,
                                                buildBackgroundProteomeDlg =>
            {
                buildBackgroundProteomeDlg.BackgroundProteomePath = TestFilesDir.GetTestPath("yeast_mini.protdb");
                buildBackgroundProteomeDlg.BackgroundProteomeName = "Yeast";
                buildBackgroundProteomeDlg.OkDialog();
            });
            RunUI(peptideSettingsUI.OkDialog);
            WaitForCondition(() =>
            {
                var peptideSettings    = Program.ActiveDocument.Settings.PeptideSettings;
                var backgroundProteome = peptideSettings.BackgroundProteome;
                return(backgroundProteome.HasDigestion(peptideSettings));
            });
            WaitForDocumentLoaded(); // Give background loader a chance to get the protein metadata too

            RunDlg <TransitionSettingsUI>(SkylineWindow.ShowTransitionSettingsUI, transitionSettingsUI =>
            {
                transitionSettingsUI.PrecursorCharges = "1,2,3";
                transitionSettingsUI.OkDialog();
            });

            // Test add all with the yeast background proteome connected.
            RunUI(() =>
            {
                SkylineWindow.SelectAll();
                SkylineWindow.EditDelete();
                // Switch to yeast library.
                libComboBox.SelectedIndex            = 4;
                _viewLibUI.AssociateMatchingProteins = true;
            });
            var addLibraryDlg = ShowDialog <MultiButtonMsgDlg>(_viewLibUI.AddAllPeptides);
            // Add the library to the document.
            var filterMatchedPeptidesDlg = ShowDialog <FilterMatchedPeptidesDlg>(addLibraryDlg.Btn0Click);

            RunUI(() => filterMatchedPeptidesDlg.AddUnmatched = false);
            using (new CheckDocumentStateWithPossibleProteinMetadataBackgroundUpdate(4, 10, 13, 39))
            {
                RunDlg <MultiButtonMsgDlg>(filterMatchedPeptidesDlg.OkDialog, messageDlg => messageDlg.Btn1Click());
            }
            Assert.IsFalse(SkylineWindow.Document.Peptides.Contains(nodePep => !nodePep.HasLibInfo));

            // Test adding a single peptide that matches two different proteins using keep all.
            RunUI(() =>
            {
                SkylineWindow.Undo();
                _viewLibUI.ChangeSelectedPeptide("ADTGIAVEGATDAAR+");
            });
            using (new CheckDocumentStateWithPossibleProteinMetadataBackgroundUpdate(2, 2, 2, 6))
            {
                RunDlg <FilterMatchedPeptidesDlg>(_viewLibUI.AddPeptide,
                                                  filterMatchedPeptideDlg => filterMatchedPeptideDlg.OkDialog());
            }

            // Test adding a second charge state for that peptide.
            RunUI(() => _viewLibUI.ChangeSelectedPeptide("ADTGIAVEGATDAAR++"));
            using (new CheckDocumentStateWithPossibleProteinMetadataBackgroundUpdate(2, 2, 4, 12))
            {
                RunDlg <FilterMatchedPeptidesDlg>(_viewLibUI.AddPeptide,
                                                  filterMatchedPeptideDlg => filterMatchedPeptideDlg.OkDialog());
            }
            RunDlg <FilterMatchedPeptidesDlg>(_viewLibUI.AddPeptide,
                                              filterMatchedPeptideDlg => filterMatchedPeptideDlg.OkDialog());

            // Test adding a second charge state - No Duplicates.
            RunUI(() => SkylineWindow.Undo());
            var docPrev = WaitForDocumentLoaded();

            RunDlg <FilterMatchedPeptidesDlg>(_viewLibUI.AddPeptide,
                                              filterMatchedPeptideDlg =>
            {
                filterMatchedPeptideDlg.DuplicateProteinsFilter = BackgroundProteome.DuplicateProteinsFilter.NoDuplicates;
                filterMatchedPeptideDlg.OkDialog();
            });
            Assert.AreEqual(docPrev, WaitForDocumentLoaded());

            // Test adding a second charge state - First Only.
            using (new CheckDocumentStateWithPossibleProteinMetadataBackgroundUpdate(2, 2, 3, 9))
            {
                RunDlg <FilterMatchedPeptidesDlg>(_viewLibUI.AddPeptide, filterMatchedPeptideDlg =>
                {
                    filterMatchedPeptideDlg.DuplicateProteinsFilter =
                        BackgroundProteome.DuplicateProteinsFilter.FirstOccurence;
                    filterMatchedPeptideDlg.OkDialog();
                });
            }

            RunUI(() =>
            {
                SkylineWindow.Undo();
                SkylineWindow.Undo();
                // Add doubly charged state, no protein association.
                _viewLibUI.AssociateMatchingProteins = false;
                _viewLibUI.AddPeptide();
                _viewLibUI.AssociateMatchingProteins = true;
            });

            // Add doubly charged state with protein assocation.
            RunDlg <FilterMatchedPeptidesDlg>(_viewLibUI.AddPeptide,
                                              filterMatchedPeptideDlg => filterMatchedPeptideDlg.OkDialog()); // First only
            // Select singly charged state
            RunUI(() => _viewLibUI.ChangeSelectedPeptide("ADTGIAVEGATDAAR+"));
            // Test adding peptide associated with the background proteome does not affect any matching peptides that are
            // in peptide lists.
            using (new CheckDocumentStateWithPossibleProteinMetadataBackgroundUpdate(2, 2, 3, 9))
            {
                RunDlg <FilterMatchedPeptidesDlg>(_viewLibUI.AddPeptide,
                                                  filterMatchedPeptideDlg => filterMatchedPeptideDlg.OkDialog()); // First only
            }
            var peptideGroups = SkylineWindow.Document.PeptideGroups.ToArray();
            int index         = peptideGroups.IndexOf(nodeGroup => nodeGroup.IsPeptideList);

            Assert.IsTrue(peptideGroups[index].Children.Count == 1);

            // Test selecting no duplicates prevents any peptide from appearing twice in the document.
            RunUI(() => SkylineWindow.Undo());
            RunUI(() => SkylineWindow.Undo());
            var filterMatchedPeptidesDlg1 = ShowDialog <FilterMatchedPeptidesDlg>(_viewLibUI.AddAllPeptides);

            RunUI(() => filterMatchedPeptidesDlg1.DuplicateProteinsFilter = BackgroundProteome.DuplicateProteinsFilter.NoDuplicates);
            RunDlg <MultiButtonMsgDlg>(filterMatchedPeptidesDlg1.OkDialog, messageDlg => messageDlg.Btn1Click());
            TestForDuplicatePeptides();

            // Test selecting first occurence prevents any peptide from appearing twice in the document.
            RunUI(() => SkylineWindow.Undo());
            var filterMatchedPeptidesDlg2 = ShowDialog <FilterMatchedPeptidesDlg>(_viewLibUI.AddAllPeptides);

            RunUI(() => filterMatchedPeptidesDlg2.DuplicateProteinsFilter = BackgroundProteome.DuplicateProteinsFilter.FirstOccurence);
            RunDlg <MultiButtonMsgDlg>(filterMatchedPeptidesDlg2.OkDialog, messageDlg => messageDlg.Btn1Click());
            TestForDuplicatePeptides();

            // Test peptides are added to "Library Peptides" peptide list if this peptide group already exists.
            using (new CheckDocumentStateWithPossibleProteinMetadataBackgroundUpdate(1, 2, 3, 9))
            {
                RunUI(() =>
                {
                    SkylineWindow.Undo();
                    _viewLibUI.AssociateMatchingProteins = false;
                    _viewLibUI.AddPeptide();
                    _viewLibUI.ChangeSelectedPeptide("AAAP");
                    _viewLibUI.AddPeptide();
                });
            }

            RunUI(() =>
            {
                SkylineWindow.SelectAll();
                SkylineWindow.EditDelete();
            });

            // Close the Library Explorer dialog
            OkDialog(_viewLibUI, _viewLibUI.CancelDialog);
        }