Ejemplo n.º 1
0
        public static string ProteinModalDisplayText(ProteinMetadata metadata, ProteinDisplayMode displayProteinsMode)
        {
            switch (displayProteinsMode)
            {
            case ProteinDisplayMode.ByAccession:
            case ProteinDisplayMode.ByPreferredName:
            case ProteinDisplayMode.ByGene:
                break;

            default:
                return(metadata.Name);
            }

            // If the desired field is not populated because it's not yet searched, say so
            if (metadata.NeedsSearch())
            {
                return(Resources.ProteinMetadataManager_LookupProteinMetadata_resolving_protein_details);
            }

            // If the desired field is not populated, return something like "<name: YAL01234>"
            var failsafe = String.Format(Resources.PeptideGroupTreeNode_ProteinModalDisplayText__name___0__, metadata.Name);

            switch (displayProteinsMode)
            {
            case ProteinDisplayMode.ByAccession:
                return(metadata.Accession ?? failsafe);

            case ProteinDisplayMode.ByPreferredName:
                return(metadata.PreferredName ?? failsafe);

            case ProteinDisplayMode.ByGene:
                return(metadata.Gene ?? failsafe);
            }
            return(failsafe);
        }
Ejemplo n.º 2
0
        private static string GetDisplayText(ProteinDisplayMode arg, ProteinMetadata proteinMetadata)
        {
            string val;

            switch (arg)
            {
            case ProteinDisplayMode.ByAccession:
                val = proteinMetadata.Accession;
                break;

            case ProteinDisplayMode.ByGene:
                val = proteinMetadata.Gene;
                break;

            case ProteinDisplayMode.ByPreferredName:
                val = proteinMetadata.PreferredName;
                break;

            default:
                val = proteinMetadata.Name;
                break;
            }
            Assert.IsFalse(String.IsNullOrEmpty(val));
            if (arg != ProteinDisplayMode.ByName)
            {
                Assert.AreNotEqual(val, proteinMetadata.Name);
            }
            return(val);
        }
Ejemplo n.º 3
0
        // CONSIDER bspratt - wouldn't a button for restoring the original name be useful too?

        private void UseAccessionOrPreferredNameorGene(ProteinDisplayMode mode)
        {
            var dictNodeToNewName = new Dictionary <string, string>();

            foreach (var nodePepGroup in _document.MoleculeGroups)
            {
                string newname;
                if (!dictNodeToNewName.TryGetValue(nodePepGroup.Name, out newname))
                {
                    string text = null;
                    switch (mode)
                    {
                    case ProteinDisplayMode.ByAccession:
                        text = nodePepGroup.ProteinMetadata.Accession;
                        break;

                    case ProteinDisplayMode.ByPreferredName:
                        text = nodePepGroup.ProteinMetadata.PreferredName;
                        break;

                    case ProteinDisplayMode.ByGene:
                        text = nodePepGroup.ProteinMetadata.Gene;
                        break;
                    }
                    text = text ?? nodePepGroup.Name;
                    dictNodeToNewName.Add(nodePepGroup.Name, text);
                }
            }


            _gridViewDriver.Populate(_document.MoleculeGroups
                                     .Where(nodePepGroup => dictNodeToNewName.ContainsKey(nodePepGroup.Name))
                                     .Select(nodePepGroup => new RenameProteins
            {
                CurrentName = nodePepGroup.Name,
                NewName     = dictNodeToNewName[nodePepGroup.Name]
            }));
            if (NameCount == 0)
            {
                MessageDlg.Show(this, string.Format(Resources.RenameProteinsDlg_UseAccessionOrPreferredNameorGene_No_protein_metadata_available));
            }
        }
 private static string GetDisplayText(ProteinDisplayMode arg, ProteinMetadata proteinMetadata)
 {
     string val;
     switch (arg)
     {
         case ProteinDisplayMode.ByAccession:
             val = proteinMetadata.Accession;
             break;
         case ProteinDisplayMode.ByGene:
             val = proteinMetadata.Gene;
             break;
         case ProteinDisplayMode.ByPreferredName:
             val = proteinMetadata.PreferredName;
             break;
         default:
             val = proteinMetadata.Name;
             break;
     }
     Assert.IsFalse(String.IsNullOrEmpty(val));
     if (arg != ProteinDisplayMode.ByName)
         Assert.AreNotEqual(val, proteinMetadata.Name);
     return val;
 }
Ejemplo n.º 5
0
        public static string ProteinModalDisplayText(ProteinMetadata metadata, ProteinDisplayMode displayProteinsMode)
        {
            switch (displayProteinsMode)
            {
                case ProteinDisplayMode.ByAccession:
                case ProteinDisplayMode.ByPreferredName:
                case ProteinDisplayMode.ByGene:
                    break;
                default:
                    return metadata.Name;
            }

            // If the desired field is not populated because it's not yet searched, say so
            if (metadata.NeedsSearch())
                return Resources.ProteinMetadataManager_LookupProteinMetadata_resolving_protein_details;

            // If the desired field is not populated, return something like "<name: YAL01234>"
            var failsafe = String.Format(Resources.PeptideGroupTreeNode_ProteinModalDisplayText__name___0__, metadata.Name);
            switch (displayProteinsMode)
            {
                case ProteinDisplayMode.ByAccession:
                    return metadata.Accession ?? failsafe;
                case ProteinDisplayMode.ByPreferredName:
                    return metadata.PreferredName ?? failsafe;
                case ProteinDisplayMode.ByGene:
                    return metadata.Gene ?? failsafe;
            }
            return failsafe;
        }
Ejemplo n.º 6
0
        protected override void DoTest()
        {
            // Formerly this little .sky file would not update its (unsearchable) protein metdata on load
            RunUI(() => SkylineWindow.OpenFile(TestFilesDir.GetTestPath("Mutant Peptides  with Braf AG A00Y - Cut Down.sky")));
            var doc      = WaitForDocumentLoaded();
            var nodeProt = doc.MoleculeGroups.First();
            var metadata = nodeProt.ProteinMetadata;

            Assert.IsFalse(metadata.NeedsSearch());

            RunUI(() => SkylineWindow.OpenFile(TestFilesDir.GetTestPath("ProteinMetadataFunctionalTests.sky")));

            doc      = WaitForDocumentLoaded();
            nodeProt = doc.MoleculeGroups.First();
            metadata = nodeProt.ProteinMetadata;

            // Examine the various View | Targets | By* modes
            foreach (ProteinDisplayMode mode in Enum.GetValues(typeof(ProteinDisplayMode)))
            {
                ProteinDisplayMode arg = mode;
                RunUI(() => SkylineWindow.UpdateTargetsDisplayMode(arg)); // This should alter the text displayed by the node in the sequence tree view
                WaitForConditionUI(() =>
                {
                    var displayText = SkylineWindow.SequenceTree.GetSequenceNodes().First().Text;
                    if (arg != ProteinDisplayMode.ByName &&
                        Equals(displayText, GetDisplayText(ProteinDisplayMode.ByName, metadata)))
                    {
                        return(false);
                    }
                    return(Equals(displayText, GetDisplayText(arg, metadata)));
                });
            }

            // Examine the various Edit | Refine | Sort Proteins | By* modes
            Assert.AreEqual("YIL075C", nodeProt.Name); // unsorted
            foreach (ProteinDisplayMode mode in Enum.GetValues(typeof(ProteinDisplayMode)))
            {
                string expectedTopName = null;
                switch (mode)
                {
                case ProteinDisplayMode.ByName:
                    expectedTopName = "YAL003W";
                    RunUI(() => SkylineWindow.sortProteinsByNameToolStripMenuItem_Click(null, null));
                    break;

                case ProteinDisplayMode.ByAccession:
                    expectedTopName = TestSmallMolecules ? "ZZZTESTINGNONPROTEOMICMOLECULEGROUP" : "YFL038C";
                    RunUI(() => SkylineWindow.sortProteinsByAccessionToolStripMenuItem_Click(null, null));
                    break;

                case ProteinDisplayMode.ByPreferredName:
                    RunUI(() => SkylineWindow.sortProteinsByPreferredNameToolStripMenuItem_Click(null, null));
                    expectedTopName = TestSmallMolecules ? "ZZZTESTINGNONPROTEOMICMOLECULEGROUP" : "YAL016W";
                    break;

                case ProteinDisplayMode.ByGene:
                    RunUI(() => SkylineWindow.sortProteinsByGeneToolStripMenuItem_Click(null, null));
                    expectedTopName = TestSmallMolecules ? "ZZZTESTINGNONPROTEOMICMOLECULEGROUP" : "YGL234W";
                    break;
                }
                var actualTopName = WaitForDocumentLoaded().MoleculeGroups.First().Name.ToUpperInvariant();
                Assert.AreEqual(expectedTopName, actualTopName);
            }

            // Now paste in our fake fasta test data, and handle it with our fake webaccess handler
            var protdbLoader = SkylineWindow.BackgroundProteomeManager;

            protdbLoader.FastaImporter = new WebEnabledFastaImporter(new CommonTest.FastaImporterTest.PlaybackProvider());
            var treeLoader = SkylineWindow.ProteinMetadataManager;

            treeLoader.FastaImporter = new WebEnabledFastaImporter(new CommonTest.FastaImporterTest.PlaybackProvider());

            const int maxEntries = 5;
            var       fastaText  = CommonTest.FastaImporterTest.GetFastaTestText(maxEntries); // Just get the first few

            SetClipboardTextUI(fastaText);
            var pasteDlg = ShowDialog <PasteDlg>(SkylineWindow.ShowPasteFastaDlg); // Show the paste dialog

            RunDlg <EmptyProteinsDlg>(() =>                                        // Anticpate the EmptyProteinsDialog as a side effect
            {
                pasteDlg.PasteFasta();                                             // Doing this in pastDlg...
                pasteDlg.OkDialog();
            },
                                      dlg =>
            {
                Assert.AreEqual(maxEntries, dlg.EmptyProteins);
                dlg.KeepEmptyProteins();
                dlg.OkDialog();     // ... will cause EmptyProteinsDlg to pop up, so OK it.
            });

            // Check that IPI:IPI00197700.1 got an accession number P04638
            WaitForCondition(() => SkylineWindow.Document.MoleculeGroups.Any(pg => Equals("IPI:IPI00197700.1", pg.Name)));
            doc      = WaitForDocumentLoaded();
            nodeProt = doc.MoleculeGroups.First(pg => Equals("IPI:IPI00197700.1", pg.Name));
            Assert.AreEqual("P04638", nodeProt.ProteinMetadata.Accession);

            // Now make our fake fasta into a protdb file, and check statement completion against that
            const string basename   = "fake.fasta";
            var          protdbPath = TestFilesDir.GetTestPath(basename + ProteomeDb.EXT_PROTDB);
            var          fastapath  = TestFilesDir.GetTestPath(basename);

            using (StreamWriter outfile = new StreamWriter(fastapath))
            {
                outfile.Write(CommonTest.FastaImporterTest.GetFastaTestText()); // write them all
            }
            BackgroundProteomeTest.CreateBackgroundProteome(protdbPath, basename, fastapath);
            doc = WaitForDocumentChange(doc);

            // Test for getting accession info from protdb
            RunUI(() =>
            {
                SequenceTree sequenceTree = SkylineWindow.SequenceTree;
                SkylineWindow.SequenceTree.SelectedNode = SkylineWindow.SequenceTree.Nodes[SkylineWindow.SequenceTree.Nodes.Count - 1]; // Select the creation node
                sequenceTree.BeginEdit(false);
                // ReSharper disable LocalizableElement
                sequenceTree.StatementCompletionEditBox.TextBox.Text = "NP_313205";
                // ReSharper restore LocalizableElement
                sequenceTree.CommitEditBox(false);
            });
            doc      = WaitForDocumentChange(doc);
            nodeProt = doc.MoleculeGroups.First(pg => Equals("NP_313205", pg.Name));
            Assert.AreEqual("P0A7T9", nodeProt.ProteinMetadata.Accession);

            var snapshot = SkylineWindow.Document;

            // Test for getting protein from protdb by preferredName
            const string uniRef100A5Di11 = "UniRef100_A5DI11";
            const string a5Di11          = "A5DI11";

            RunUI(() =>
            {
                SequenceTree sequenceTree = SkylineWindow.SequenceTree;
                SkylineWindow.SequenceTree.SelectedNode = SkylineWindow.SequenceTree.Nodes[SkylineWindow.SequenceTree.Nodes.Count - 1]; // Select the creation node
                sequenceTree.BeginEdit(false);
                // ReSharper disable LocalizableElement
                sequenceTree.StatementCompletionEditBox.TextBox.Text = "EF2_PICGU"; // PreferredName for UniRef100_A5DI11
                // ReSharper restore LocalizableElement
                sequenceTree.CommitEditBox(false);
            });
            WaitForCondition(() => SkylineWindow.Document.MoleculeGroups.Any(pg => Equals(uniRef100A5Di11, pg.Name)));
            doc      = WaitForDocumentChange(doc);
            nodeProt = doc.MoleculeGroups.First(pg => Equals(uniRef100A5Di11, pg.Name));
            Assert.AreEqual(a5Di11, nodeProt.ProteinMetadata.Accession);

            // Paste in some junk and make sure we handle the View Targets By* gracefully
            const string badname = "badname";

            RunUI(() =>
            {
                SequenceTree sequenceTree = SkylineWindow.SequenceTree;
                SkylineWindow.SequenceTree.SelectedNode = SkylineWindow.SequenceTree.Nodes[SkylineWindow.SequenceTree.Nodes.Count - 1]; // Select the creation node
                sequenceTree.BeginEdit(false);
                sequenceTree.StatementCompletionEditBox.TextBox.Text = badname;
                sequenceTree.CommitEditBox(false);
            });
            doc = WaitForDocumentChange(doc);
            var nodeText = SkylineWindow.SequenceTree.GetSequenceNodes().Last(n => !SrmDocument.IsSpecialNonProteomicTestDocNode(n.DocNode)).Text;
            var failsafe = String.Format(Resources.PeptideGroupTreeNode_ProteinModalDisplayText__name___0__, badname);  // As in PeptideGroupTreeNode.cs

            Assert.AreEqual(failsafe, nodeText);


            // Revert those changes, so we can insert another way
            Assert.IsTrue(SkylineWindow.SetDocument(snapshot, doc));
            WaitForCondition(() => !SkylineWindow.Document.MoleculeGroups.Any(pg => Equals(uniRef100A5Di11, pg.Name)));
            doc = SkylineWindow.Document;

            // Test for pasting accession number in protein paste dialog, and having it populate with correct name
            SetClipboardTextUI(a5Di11);
            PasteDlg pasteProteinsDlgA = ShowDialog <PasteDlg>(SkylineWindow.ShowPasteProteinsDlg);

            RunUI(() =>
            {
                var selectedNode = SkylineWindow.SequenceTree.Nodes[SkylineWindow.SequenceTree.Nodes.Count - 1];
                SkylineWindow.SequenceTree.SelectedNode = selectedNode;
                pasteProteinsDlgA.SelectedPath          = SkylineWindow.SequenceTree.SelectedPath;
                pasteProteinsDlgA.PasteProteins();
            });
            OkDialog(pasteProteinsDlgA, pasteProteinsDlgA.OkDialog);
            WaitForCondition(() => SkylineWindow.Document.MoleculeGroups.Any(pg => Equals(uniRef100A5Di11, pg.Name)));
            doc      = WaitForDocumentChange(doc);
            nodeProt = doc.MoleculeGroups.First(pg => Equals(uniRef100A5Di11, pg.Name));
            Assert.AreEqual(a5Di11, nodeProt.ProteinMetadata.Accession);

            // See what happens when you paste in a gene name shared by a couple of proteins
            const string dupeGene    = "Apoa2";
            const string ipi00197700 = "IPI:IPI00197700.1";

            SetClipboardTextUI(dupeGene);
            PasteDlg pasteProteinsDlgB = ShowDialog <PasteDlg>(SkylineWindow.ShowPasteProteinsDlg);

            RunUI(() =>
            {
                var selectedNode = SkylineWindow.SequenceTree.Nodes[SkylineWindow.SequenceTree.Nodes.Count - 1];
                SkylineWindow.SequenceTree.SelectedNode = selectedNode;
                pasteProteinsDlgB.SelectedPath          = SkylineWindow.SequenceTree.SelectedPath;
                pasteProteinsDlgB.PasteProteins();
            });
            OkDialog(pasteProteinsDlgB, pasteProteinsDlgB.OkDialog);
            WaitForCondition(() => SkylineWindow.Document.MoleculeGroups.Any(pg => Equals(ipi00197700, pg.Name)));
            doc      = WaitForDocumentChange(doc);
            nodeProt = doc.MoleculeGroups.First(pg => Equals(ipi00197700, pg.Name));
            Assert.AreEqual(dupeGene, nodeProt.ProteinMetadata.Gene);

            // Test for pasting in protein PasteDlg with sequence and metadata - metadata values are same as DocumentGrid column names
            const string pasteProteinName          = "Protein";
            const string pasteProteinDescription   = "Description";
            const string pasteProteinAccession     = "Accession";
            const string pasteProteinPreferredName = "PreferredName";
            const string pasteProteinGene          = "Gene";
            const string pasteProteinSpecies       = "Species";
            var          pasteProteinText          = String.Join("\t", pasteProteinName, pasteProteinDescription,
                                                                 "MFEQFDLDSELLASINK   IGYTKPTSIQELVIPQAMV", pasteProteinAccession, pasteProteinPreferredName, // Note the whitespace embedded in the sequence - UI should deal with that
                                                                 pasteProteinGene, pasteProteinSpecies);

            SetClipboardTextUI(pasteProteinText);
            PasteDlg pasteProteinsDlg = ShowDialog <PasteDlg>(SkylineWindow.ShowPasteProteinsDlg);

            RunUI(() =>
            {
                var selectedNode = SkylineWindow.SequenceTree.Nodes[SkylineWindow.SequenceTree.Nodes.Count - 1];
                SkylineWindow.SequenceTree.SelectedNode = selectedNode;
                pasteProteinsDlg.SelectedPath           = SkylineWindow.SequenceTree.SelectedPath;
                pasteProteinsDlg.PasteProteins();
            });
            OkDialog(pasteProteinsDlg, pasteProteinsDlg.OkDialog);
            WaitForCondition(() => SkylineWindow.Document.MoleculeGroups.Any(pg => Equals(pasteProteinName, pg.Name)));
            doc      = WaitForDocumentChange(doc);
            nodeProt = doc.MoleculeGroups.First(pg => Equals(pasteProteinName, pg.Name));
            Assert.AreEqual(pasteProteinAccession, nodeProt.ProteinMetadata.Accession);

            // Verify DocumentGrid's use of protein metadata - last line should agree with var pasteProteinText
            RunUI(() => SkylineWindow.ShowDocumentGrid(true));
            DocumentGridForm documentGrid = WaitForOpenForm <DocumentGridForm>();

            RunUI(() => documentGrid.ChooseView(Resources.SkylineViewContext_GetDocumentGridRowSources_Proteins));
            WaitForCondition(() => (documentGrid.RowCount > 0));  // Let it initialize
            foreach (var colName in new[]
            {
                pasteProteinAccession,
                pasteProteinPreferredName,
                pasteProteinGene,
                pasteProteinSpecies
            })
            {   // Column content should match column name, for pasteProteinText as input
                string value = null;
                string name  = colName;
                RunUI(() =>
                {
                    var col = documentGrid.FindColumn(PropertyPath.Parse(name));
                    value   =
                        documentGrid.DataGridView.Rows[documentGrid.RowCount - 1].Cells[col.Index].Value.ToString();
                });
                Assert.AreEqual(colName, value);
            }
        }