Exemplo n.º 1
0
        public void CreateDb(string fileName)
        {
            // If the file exists, then the user chose to overwrite,
            // so delete the existing file.
            try
            {
                FileEx.SafeDelete(fileName);
            }
            catch (IOException x)
            {
                MessageDlg.ShowException(this, x);
                return;
            }

            Settings.Default.ProteomeDbDirectory = Path.GetDirectoryName(fileName);

            try
            {
                ProteomeDb.CreateProteomeDb(fileName);
            }
            catch (Exception x)
            {
                var message = TextUtil.LineSeparate(string.Format(
                                                        Resources
                                                        .BuildBackgroundProteomeDlg_btnCreate_Click_An_error_occurred_attempting_to_create_the_proteome_file__0__,
                                                        fileName), x.Message);
                MessageDlg.ShowWithException(this, message, x);
            }

            if (textName.Text.Length == 0)
            {
                textName.Text = Path.GetFileNameWithoutExtension(fileName);
            }
            textPath.Text = fileName;   // This will cause RefreshStatus()
        }
Exemplo n.º 2
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            string filterProtDb = TextUtil.FileDialogFiltersAll(FILTER_PROTDB);

            string fileName;

            using (var saveFileDialog = new SaveFileDialog
            {
                Filter = filterProtDb,
                InitialDirectory = Settings.Default.ProteomeDbDirectory,
                Title = Resources.BuildBackgroundProteomeDlg_btnCreate_Click_Create_Background_Proteome,
                OverwritePrompt = true,
            })
            {
                if (saveFileDialog.ShowDialog(this) == DialogResult.Cancel)
                {
                    return;
                }

                fileName = saveFileDialog.FileName;
            }

            // If the file exists, then the user chose to overwrite,
            // so delete the existing file.
            try
            {
                FileEx.SafeDelete(fileName);
            }
            catch (IOException x)
            {
                MessageDlg.ShowException(this, x);
                return;
            }

            Settings.Default.ProteomeDbDirectory = Path.GetDirectoryName(fileName);

            textPath.Text = fileName;
            if (textName.Text.Length == 0)
            {
                textName.Text = Path.GetFileNameWithoutExtension(fileName);
            }

            try
            {
                ProteomeDb.CreateProteomeDb(fileName);
            }
            catch (Exception x)
            {
                var message = TextUtil.LineSeparate(string.Format(Resources.BuildBackgroundProteomeDlg_btnCreate_Click_An_error_occurred_attempting_to_create_the_proteome_file__0__,
                                                                  fileName), x.Message);
                MessageDlg.ShowWithException(this, message, x);
            }

            RefreshStatus();
        }
Exemplo n.º 3
0
        public void AddFastaFile(string fastaFilePath)
        {
            String databasePath = textPath.Text;

            Settings.Default.FastaDirectory = Path.GetDirectoryName(fastaFilePath);
            int duplicateSequenceCount = 0;

            using (var longWaitDlg = new LongWaitDlg {
                ProgressValue = 0
            })
            {
                try
                {
                    longWaitDlg.PerformWork(this, 0, progressMonitor =>
                    {
                        ProteomeDb proteomeDb = File.Exists(databasePath)
                            ? ProteomeDb.OpenProteomeDb(databasePath)
                            : ProteomeDb.CreateProteomeDb(databasePath);
                        using (proteomeDb)
                        {
                            using (var reader = File.OpenText(fastaFilePath))
                            {
                                IProgressStatus status = new ProgressStatus(longWaitDlg.Message);
                                proteomeDb.AddFastaFile(reader, progressMonitor, ref status, false, out duplicateSequenceCount);
                            }
                        }
                    });
                }
                catch (Exception x)
                {
                    var message = TextUtil.LineSeparate(string.Format(Resources.BuildBackgroundProteomeDlg_AddFastaFile_An_error_occurred_attempting_to_add_the_FASTA_file__0__,
                                                                      fastaFilePath), x.Message);
                    MessageDlg.ShowWithException(this, message, x);
                    return;
                }
            }

            string path = Path.GetFileName(fastaFilePath);

            if (path != null)
            {
                listboxFasta.Items.Add(path);
            }
            RefreshStatus();

            if (duplicateSequenceCount > 0)
            {
                MessageDlg.Show(this, string.Format(Resources.BuildBackgroundProteomeDlg_AddFastaFile_The_added_file_included__0__repeated_protein_sequences__Their_names_were_added_as_aliases_to_ensure_the_protein_list_contains_only_one_copy_of_each_sequence_, duplicateSequenceCount));
            }
        }
Exemplo n.º 4
0
        public void TestTooManyProteinMatches()
        {
            int proteinCount = 30000;

            Directory.CreateDirectory(TestContext.TestDir);
            var          proteomeDbPath      = Path.Combine(TestContext.TestDir, "manySimilarProteins.protdb");
            var          proteomeDb          = ProteomeDb.CreateProteomeDb(proteomeDbPath);
            StringWriter repetitiveFastaFile = new StringWriter();

            WriteRepetitiveFastaFile(repetitiveFastaFile, "ELVISLIVES", proteinCount);
            IProgressStatus progressStatus = new ProgressStatus();

            proteomeDb.AddFastaFile(new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(repetitiveFastaFile.ToString()))), new SilentProgressMonitor(), ref progressStatus, false);
            var digestion = proteomeDb.GetDigestion();
            var proteins  = digestion.GetProteinsWithSequence("VISLIV");

            Assert.AreEqual(proteinCount, proteins.Count);
        }
Exemplo n.º 5
0
        public void AddFastaFile(string fastaFilePath)
        {
            String databasePath = textPath.Text;

            Settings.Default.FastaDirectory = Path.GetDirectoryName(fastaFilePath);
            using (var longWaitDlg = new LongWaitDlg {
                ProgressValue = 0
            })
            {
                var progressMonitor = new ProgressMonitor(longWaitDlg);
                try
                {
                    longWaitDlg.PerformWork(this, 0, () =>
                    {
                        ProteomeDb proteomeDb = File.Exists(databasePath)
                            ? ProteomeDb.OpenProteomeDb(databasePath)
                            : ProteomeDb.CreateProteomeDb(databasePath);
                        using (proteomeDb)
                        {
                            using (var reader = File.OpenText(fastaFilePath))
                            {
                                proteomeDb.AddFastaFile(reader, progressMonitor.UpdateProgress);
                            }
                        }
                    });
                }
                catch (Exception x)
                {
                    var message = TextUtil.LineSeparate(string.Format(Resources.BuildBackgroundProteomeDlg_AddFastaFile_An_error_occurred_attempting_to_add_the_FASTA_file__0__,
                                                                      fastaFilePath), x.Message);
                    MessageDlg.ShowWithException(this, message, x);
                    return;
                }
            }

            string path = Path.GetFileName(fastaFilePath);

            if (path != null)
            {
                listboxFasta.Items.Add(path);
            }
            RefreshStatus();
        }
Exemplo n.º 6
0
        public void TestProteomeDb()
        {
            using (var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE))
            {
                string fastaPath  = testFilesDir.GetTestPath("high_ipi.Human.20060111.fasta");
                string protDbPath = testFilesDir.GetTestPath("test.protdb");

                using (ProteomeDb proteomeDb = ProteomeDb.CreateProteomeDb(protDbPath))
                {
                    IProgressStatus status = new ProgressStatus(string.Empty);
                    using (var reader = new StreamReader(fastaPath))
                    {
                        proteomeDb.AddFastaFile(reader, new SilentProgressMonitor(), ref status, true); // Delay indexing
                    }
                    // perform digestion
                    Digestion digestion         = proteomeDb.GetDigestion();
                    var       digestedProteins0 = digestion.GetProteinsWithSequence("EDGWVK");
                    Assert.IsTrue(digestedProteins0.Count >= 1);
                }
            }
        }
Exemplo n.º 7
0
        public void TestProteomeDb()
        {
            using (var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE))
            {
                string fastaPath  = testFilesDir.GetTestPath("high_ipi.Human.20060111.fasta");
                string protDbPath = testFilesDir.GetTestPath("test.protdb");

                using (ProteomeDb proteomeDb = ProteomeDb.CreateProteomeDb(protDbPath))
                {
                    Enzyme trypsin = EnzymeList.GetDefault();
                    using (var reader = new StreamReader(fastaPath))
                    {
                        proteomeDb.AddFastaFile(reader, (msg, progress) => true);
                    }
                    // perform digestion
                    proteomeDb.Digest(new ProteaseImpl(trypsin), (msg, progress) => true);
                    Digestion digestion         = proteomeDb.GetDigestion(trypsin.Name);
                    var       digestedProteins0 = digestion.GetProteinsWithSequencePrefix("EDGWVK", 100);
                    Assert.IsTrue(digestedProteins0.Count >= 1);
                }
            }
        }
Exemplo n.º 8
0
        public void TestProteomeDb()
        {
            using (var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE))
            {
                string fastaPath  = testFilesDir.GetTestPath("high_ipi.Human.20060111.fasta");
                string protDbPath = testFilesDir.GetTestPath("test.protdb");

                using (ProteomeDb proteomeDb = ProteomeDb.CreateProteomeDb(protDbPath))
                {
                    Enzyme          trypsin = EnzymeList.GetDefault();
                    IProgressStatus status  = new ProgressStatus(string.Empty);
                    using (var reader = new StreamReader(fastaPath))
                    {
                        proteomeDb.AddFastaFile(reader, new SilentProgressMonitor(), ref status, true); // Delay indexing
                    }
                    // perform digestion
                    proteomeDb.Digest(new ProteaseImpl(trypsin), ProteomeDb.PROTDB_MAX_MISSED_CLEAVAGES, new SilentProgressMonitor(), ref status);
                    Digestion digestion         = proteomeDb.GetDigestion(trypsin.Name);
                    var       digestedProteins0 = digestion.GetProteinsWithSequencePrefix("EDGWVK", 100);
                    Assert.IsTrue(digestedProteins0.Count >= 1);
                }
            }
        }