コード例 #1
0
        protected override void DoTest()
        {
            RunUI(() => SkylineWindow.OpenFile(TestFilesDir.GetTestPath("CE_Vantage_15mTorr_scheduled_mini_withMod.sky")));
            WaitForGraphs();

            RunUI(() =>
            {
                SequenceTree sequenceTree = SkylineWindow.SequenceTree;

                // Test single node copy.
                sequenceTree.ExpandAll();
                sequenceTree.KeysOverride = Keys.None;
                sequenceTree.SelectedNode = sequenceTree.Nodes[0];
                SkylineWindow.Copy();
                CheckCopiedNodes(0, 1);

                // Test multiple selection copy.
                sequenceTree.KeysOverride = Keys.Shift;
                sequenceTree.SelectedNode = sequenceTree.Nodes[1];
                SkylineWindow.Copy();

                // Test multiple selection disjoint, reverse order copy.
                CheckCopiedNodes(0, 1);
                Assert.AreSame(sequenceTree, SkylineWindow.SequenceTree);
                sequenceTree.KeysOverride = Keys.None;
                sequenceTree.SelectedNode = sequenceTree.Nodes[1].Nodes[0];
                sequenceTree.KeysOverride = Keys.Control;
                sequenceTree.SelectedNode = sequenceTree.Nodes[0].Nodes[0];
                SkylineWindow.Copy();
                // After copying in reverse order, reselect the nodes in sorted order so we don't have to
                // sort them in the test code.
                sequenceTree.KeysOverride = Keys.None;
                sequenceTree.SelectedNode = sequenceTree.Nodes[0];
                sequenceTree.SelectedNode = sequenceTree.Nodes[0].Nodes[0];
                sequenceTree.KeysOverride = Keys.Control;
                sequenceTree.SelectedNode = sequenceTree.Nodes[1].Nodes[0];
                Assert.AreSame(sequenceTree, SkylineWindow.SequenceTree);
                CheckCopiedNodes(1, 2);

                // Test no space between parent and descendents if immediate child is not selected.
                sequenceTree.KeysOverride = Keys.None;
                sequenceTree.SelectedNode = sequenceTree.Nodes[0];
                sequenceTree.KeysOverride = Keys.Control;
                sequenceTree.SelectedNode = sequenceTree.Nodes[0].Nodes[0].Nodes[0].Nodes[0];
                sequenceTree.SelectedNode = sequenceTree.Nodes[0].Nodes[0].Nodes[0].Nodes[2];
                SkylineWindow.Copy();
                CheckCopiedNodes(0, 1);

                // Test paste menu item enabled, copy menu item disabled when dummy node is selected.
                sequenceTree.KeysOverride = Keys.None;
                sequenceTree.SelectedNode =
                    sequenceTree.Nodes[SkylineWindow.SequenceTree.Nodes.Count - 1];
                Assert.IsFalse(SkylineWindow.CopyMenuItemEnabled(), "Copy menu should not be enabled");
                Assert.IsTrue(SkylineWindow.PasteMenuItemEnabled());

                // Test FASTA sequence copy HTML formatting
                sequenceTree.SelectedNode = sequenceTree.Nodes[0];
                SkylineWindow.Copy();
                string clipboardHtml = GetClipboardHtml();
                Assert.AreEqual(4, Regex.Matches(clipboardHtml, "<font style=\"font-weight: bold").Count);
                Assert.AreEqual(4, Regex.Matches(clipboardHtml, "</font>").Count);
                Assert.AreEqual(1, Regex.Matches(clipboardHtml, "color: blue").Count);

                sequenceTree.SelectedNode = sequenceTree.Nodes[1];
                SkylineWindow.Copy();
                clipboardHtml = GetClipboardHtml();
                Assert.AreEqual(19, Regex.Matches(clipboardHtml, "<font style=\"font-weight: bold").Count);
                Assert.AreEqual(19, Regex.Matches(clipboardHtml, "</font>").Count);
                Assert.AreEqual(2, Regex.Matches(clipboardHtml, "color: blue").Count);

                sequenceTree.SelectedNode = sequenceTree.Nodes[2];
                SkylineWindow.Copy();
                clipboardHtml = GetClipboardHtml();
                Assert.AreEqual(18, Regex.Matches(clipboardHtml, "<font style=\"font-weight: bold").Count);
                Assert.AreEqual(18, Regex.Matches(clipboardHtml, "</font>").Count);
                Assert.AreEqual(2, Regex.Matches(clipboardHtml, "color: blue").Count);

                // Test clipboard HTML contains formatting for modified peptides.
                sequenceTree.SelectedNode = sequenceTree.Nodes[3].Nodes[0];
                SkylineWindow.Copy();
                clipboardHtml = GetClipboardHtml();
                Assert.IsTrue(clipboardHtml.Contains("font") && clipboardHtml.Contains("color"));
            });

            // Paste a protein list
            var document = WaitForProteinMetadataBackgroundLoaderCompletedUI();

            RunUI(() =>
            {
                SetClipboardText(PROTEINLIST_CLIPBOARD_TEXT);
                SkylineWindow.Paste();
            });
            var docPaste = WaitForDocumentChange(document);

            Assert.AreEqual(document.PeptideGroupCount + 3, docPaste.PeptideGroupCount);
            Assert.AreEqual("P23978", docPaste.PeptideGroups.Last().ProteinMetadata.Accession);  // Did builtin IPI conversion work?

            // Paste an invalid protein list
            RunDlg <MessageDlg>(() =>
            {
                SetClipboardText(PROTEINLIST_CLIPBOARD_TEXT.Replace("MDAL", "***"));
                SkylineWindow.Paste();
            },
                                msgDlg => msgDlg.OkDialog());
            Assert.AreSame(docPaste, WaitForProteinMetadataBackgroundLoaderCompletedUI());

            // Test border case where protein/peptide/transition list contains a blank line
            // Should give generic error, not crash
            RunDlg <MessageDlg>(() =>
            {
                SetClipboardText(PROTEIN_LIST_BAD_FORMAT);
                SkylineWindow.Paste();
            },
                                msgDlg =>
            {
                Assert.AreEqual(msgDlg.Message, Resources.CopyPasteTest_DoTest_Could_not_read_the_pasted_transition_list___Transition_list_must_be_in_separated_columns_and_cannot_contain_blank_lines_);
                msgDlg.OkDialog();
            });

            // Paste peptides
            const int precursorCharge = 2;
            List <Tuple <string, int> > peptidePaste = new List <Tuple <string, int> >
            {
                new Tuple <string, int>("FVEGLPINDFSR", 3),
                new Tuple <string, int>("FVEGLPINDFSR", 2),
                new Tuple <string, int>("FVEGLPINDFSR", 0),
                new Tuple <string, int>("DLNELQALIEAHFENR", 0),
                new Tuple <string, int>(string.Format("C[+{0:F01}]QPLELAGLGFAELQDLC[+{1:F01}]R", 57.0, 57.0), 3),
                new Tuple <string, int>("PEPTIDER", 5),
                new Tuple <string, int>("PEPTIDER", 15)
            };
            var peptidePasteSb = new StringBuilder();

            foreach (var pep in peptidePaste)
            {
                peptidePasteSb.AppendLine(pep.Item1 + Transition.GetChargeIndicator(pep.Item2));
            }

            RunUI(() =>
            {
                SkylineWindow.NewDocument(true);
                document = SkylineWindow.Document;
                document = document.ChangeSettings(document.Settings.ChangeTransitionFilter(f => f.ChangePrecursorCharges(new[] { precursorCharge })));
                SetClipboardText(peptidePasteSb.ToString());
                SkylineWindow.Paste();
            });
            document = WaitForDocumentChange(document);
            Assert.AreEqual(peptidePaste.Count, document.PeptideTransitionGroupCount);
            for (int i = 0; i < document.PeptideTransitionGroupCount; i++)
            {
                TransitionGroupDocNode transition = document.PeptideTransitionGroups.ElementAt(i);
                string seq    = transition.TransitionGroup.Peptide.Sequence;
                int    charge = transition.PrecursorCharge;
                Assert.AreEqual(FastaSequence.StripModifications(peptidePaste[i].Item1), seq);
                var pastedCharge = peptidePaste[i].Item2;
                Assert.AreEqual(pastedCharge != 0 ? pastedCharge : precursorCharge, charge);
            }

            // Undo paste
            RunUI(() => SkylineWindow.Undo());
            document = WaitForDocumentChange(document);
            // Change precursor charges
            int[] precursorCharges = { 2, 3, 4 };
            RunUI(() => SkylineWindow.ModifyDocument("Change precursor charges", doc => doc.ChangeSettings((document.Settings.ChangeTransitionFilter(f => f.ChangePrecursorCharges(precursorCharges))))));
            document = WaitForDocumentChange(document);
            // Re-paste in peptides
            RunUI(() => SkylineWindow.Paste());
            document = WaitForDocumentChange(document);
            int curTransitionGroup = 0;

            foreach (var peptide in peptidePaste)
            {
                if (peptide.Item2 > 0)
                {
                    // Pasted peptides with a charge indicator should have a single precursor with the specified charge state
                    TransitionGroupDocNode group = document.PeptideTransitionGroups.ElementAt(curTransitionGroup++);
                    string seq    = group.TransitionGroup.Peptide.Sequence;
                    int    charge = group.PrecursorCharge;
                    Assert.AreEqual(FastaSequence.StripModifications(peptide.Item1), seq);
                    var pastedCharge = peptide.Item2;
                    Assert.AreEqual(pastedCharge, charge);
                }
                else
                {
                    // Pasted peptides with no charge indicator should have a precursor for every charge state in transition filter settings
                    for (int j = 0; j < precursorCharges.Count(); j++)
                    {
                        TransitionGroupDocNode group = document.PeptideTransitionGroups.ElementAt(curTransitionGroup++);
                        string seq    = group.TransitionGroup.Peptide.Sequence;
                        int    charge = group.PrecursorCharge;
                        Assert.AreEqual(FastaSequence.StripModifications(peptide.Item1), seq);
                        Assert.AreEqual(precursorCharges[j], charge);
                    }
                }
            }
            Assert.AreEqual(curTransitionGroup, document.PeptideTransitionGroupCount);
        }