Exemplo n.º 1
0
        private void RefreshStatus()
        {
            if (File.Exists(textPath.Text))
            {
                btnAddFastaFile.Enabled = true;
                ProteomeDb proteomeDb   = null;
                int        proteinCount = 0;
                try
                {
                    using (var longWaitDlg = new LongWaitDlg
                    {
                        Text = Resources.BuildBackgroundProteomeDlg_RefreshStatus_Loading_Proteome_File,
                        Message =
                            string.Format(
                                Resources.BuildBackgroundProteomeDlg_RefreshStatus_Loading_protein_information_from__0__,
                                textPath.Text)
                    })
                    {
                        longWaitDlg.PerformWork(this, 1000, () =>
                        {
                            proteomeDb = ProteomeDb.OpenProteomeDb(textPath.Text);
                            if (proteomeDb != null)
                            {
                                proteinCount = proteomeDb.GetProteinCount(); // This can be a lengthy operation on a large protdb, do it within the longwait
                            }
                        });
                    }
                    if (proteomeDb == null)
                    {
                        throw new Exception();
                    }

                    tbxStatus.Text =
                        string.Format(
                            Resources.BuildBackgroundProteomeDlg_RefreshStatus_The_proteome_file_contains__0__proteins,
                            proteinCount);
                }
                catch (Exception)
                {
                    tbxStatus.Text          = Resources.BuildBackgroundProteomeDlg_OkDialog_The_proteome_file_is_not_valid;
                    btnAddFastaFile.Enabled = false;
                }
                finally
                {
                    if (null != proteomeDb)
                    {
                        proteomeDb.Dispose();
                    }
                }
                textPath.ForeColor = Color.Black;
            }
            else
            {
                btnAddFastaFile.Enabled = false;
                tbxStatus.Text          = Resources.BuildBackgroundProteomeDlg_RefreshStatus_Click_the_Open_button_to_choose_an_existing_proteome_file_or_click_the_Create_button_to_create_a_new_proteome_file;
                textPath.ForeColor      = string.IsNullOrEmpty(textPath.Text) ? Color.Black : Color.Red;
            }
        }
Exemplo n.º 2
0
        private void RefreshStatus()
        {
            if (File.Exists(textPath.Text))
            {
                btnAddFastaFile.Enabled = true;
                ProteomeDb proteomeDb = null;
                try
                {
                    using (var longWaitDlg = new LongWaitDlg
                    {
                        Text = Resources.BuildBackgroundProteomeDlg_RefreshStatus_Loading_Proteome_File,
                        Message =
                            string.Format(
                                Resources.BuildBackgroundProteomeDlg_RefreshStatus_Loading_protein_information_from__0__,
                                textPath.Text)
                    })
                    {
                        longWaitDlg.PerformWork(this, 1000, () => proteomeDb = ProteomeDb.OpenProteomeDb(textPath.Text));
                    }
                    if (proteomeDb == null)
                    {
                        throw new Exception();
                    }

                    int proteinCount = proteomeDb.GetProteinCount();
                    var digestions   = proteomeDb.ListDigestions();
                    tbxStatus.Text =
                        string.Format(
                            Resources.BuildBackgroundProteomeDlg_RefreshStatus_The_proteome_file_contains__0__proteins,
                            proteinCount);
                    if (proteinCount != 0 && digestions.Count > 0)
                    {
                        tbxStatus.Text = TextUtil.LineSeparate(tbxStatus.Text,
                                                               Resources.BuildBackgroundProteomeDlg_RefreshStatus_The_proteome_has_already_been_digested);
                    }
                }
                catch (Exception)
                {
                    tbxStatus.Text          = Resources.BuildBackgroundProteomeDlg_OkDialog_The_proteome_file_is_not_valid;
                    btnAddFastaFile.Enabled = false;
                }
                finally
                {
                    if (null != proteomeDb)
                    {
                        proteomeDb.Dispose();
                    }
                }
            }
            else
            {
                btnAddFastaFile.Enabled = false;
                tbxStatus.Text          = Resources.BuildBackgroundProteomeDlg_RefreshStatus_Click_the_Open_button_to_choose_an_existing_proteome_file_or_click_the_Create_button_to_create_a_new_proteome_file;
            }
        }
Exemplo n.º 3
0
        public void DoTestOlderProteomeDb(TestContext testContext, bool doActualWebAccess)
        {
            using (var testFilesDir = new TestFilesDir(testContext, ZIP_FILE))
            {
                string fastaPath  = testFilesDir.GetTestPath("tiny.fasta");
                string protDbPath = testFilesDir.GetTestPath("celegans_mini.protdb"); // a version 0 protdb file
                string blibPath   = testFilesDir.GetTestPath("random.blib");          // a bibliospec file

                // What happens when you try to open a random file as a protdb file?
                AssertEx.ThrowsException <DbException>(() => ProteomeDb.OpenProteomeDb(fastaPath));

                // What happens when you try to open a non-protdb database file as a protdb file?
                AssertEx.ThrowsException <FileLoadException>(() => ProteomeDb.OpenProteomeDb(blibPath));

                using (ProteomeDb proteomeDb = ProteomeDb.OpenProteomeDb(protDbPath))
                {
                    Assert.IsTrue(proteomeDb.GetSchemaVersionMajor() == 0); // the initial db from our zipfile should be ancient
                    Assert.IsTrue(proteomeDb.GetSchemaVersionMinor() == 0); // the initial db from our zipfile should be ancient
                    Assert.AreEqual(9, proteomeDb.GetProteinCount());

                    var protein = proteomeDb.GetProteinByName("Y18D10A.20");
                    Assert.IsNotNull(protein);
                    Assert.IsTrue(String.IsNullOrEmpty(protein.Accession)); // old db won't have this populated

                    WebEnabledFastaImporter searcher = new WebEnabledFastaImporter(doActualWebAccess ? null :new WebEnabledFastaImporter.FakeWebSearchProvider());
                    bool            searchComplete;
                    IProgressStatus status = new ProgressStatus(string.Empty);
                    Assert.IsTrue(proteomeDb.LookupProteinMetadata(new SilentProgressMonitor(), ref status, searcher, false, out searchComplete)); // add any missing protein metadata
                    Assert.IsTrue(searchComplete);

                    protein = proteomeDb.GetProteinByName("Y18D10A.20");
                    Assert.IsNotNull(protein);
                    if (doActualWebAccess) // We can actually go to the web for metadata
                    {
                        Assert.AreEqual("Q9XW16", protein.Accession);
                    }

                    using (var reader = new StreamReader(fastaPath))
                    {
                        proteomeDb.AddFastaFile(reader, new SilentProgressMonitor(), ref status, false);
                    }
                    // the act of writing should update to the current version
                    Assert.AreEqual(ProteomeDb.SCHEMA_VERSION_MAJOR_CURRENT, proteomeDb.GetSchemaVersionMajor());
                    Assert.AreEqual(ProteomeDb.SCHEMA_VERSION_MINOR_CURRENT, proteomeDb.GetSchemaVersionMinor());
                    Assert.AreEqual(19, proteomeDb.GetProteinCount());

                    // check for propery processed protein metadata
                    Assert.IsTrue(proteomeDb.LookupProteinMetadata(new SilentProgressMonitor(), ref status, searcher, false, out searchComplete));
                    Assert.IsTrue(searchComplete);
                    protein = proteomeDb.GetProteinByName("IPI00000044");
                    Assert.IsNotNull(protein);
                    Assert.AreEqual("P01127", protein.Accession); // We get this offline with our ipi->uniprot mapper
                    if (doActualWebAccess)
                    {
                        Assert.AreEqual("PDGFB_HUMAN", protein.PreferredName); // But this we get only with web access
                    }

/*
 *                  // TODO(bspratt): fix  "GetDigestion has no notion of a Db that has been added to, doesn't digest the new proteins and returns immediately (issue #304)"
 *                  Enzyme trypsin = EnzymeList.GetDefault();
 *                  proteomeDb.Digest(trypsin,  new SilentProgressMonitor());
 *                  Digestion digestion = proteomeDb.GetDigestion(trypsin.Name);
 *                  var digestedProteins0 = digestion.GetProteinsWithSequencePrefix("EDGWVK", 100);
 *                  Assert.IsTrue(digestedProteins0.Count >= 1);
 * */
                }
            }
        }