private ProteinMatchSettings CreateProteinMatchSettings(SrmDocument srmDocument, ProteinMatchTypes matchTypes, String searchText) { var peptideSettings = srmDocument.Settings.PeptideSettings; var backgroundProteome = peptideSettings.BackgroundProteome; if (backgroundProteome.IsNone) { return(null); } try { if (_proteomeDb != null && _proteomeDb.Path != backgroundProteome.DatabasePath) { _proteomeDb.Dispose(); _proteomeDb = null; } if (_proteomeDb == null) { _proteomeDb = backgroundProteome.OpenProteomeDb(_cancellationTokenSource.Token); } return(new ProteinMatchSettings(_proteomeDb.ProteomeDbPath, matchTypes, searchText)); } catch (SQLiteException) { // CONSIDER: Silent failure could be confusing. Show a message box // about failing to open the database. return(null); } }
public void Detach() { if (TextBox == null) { return; } HideStatementCompletionForm(); if (_cancellationTokenSource != null) { _cancellationTokenSource.Cancel(); _cancellationTokenSource = null; } _proteinMatcher = null; if (null != _proteomeDb) { _proteomeDb.Dispose(); _proteomeDb = null; } TextBox.KeyDown -= TextBox_KeyDown; TextBox.TextChanged -= TextBox_TextChanged; TextBox.GotFocus -= TextBox_GotFocus; TextBox.LostFocus -= TextBox_LostFocus; TextBox.LocationChanged -= TextBox_LocationChanged; TextBox = null; }
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() }
public bool LookupProteinMetadata(ref IProgressStatus progressStatus) { using (var proteomeDb = ProteomeDb.OpenProteomeDb(_pathProteome, _isTemporary)) { _progressStatus = progressStatus.ChangeMessage( string.Format(Resources.BackgroundProteomeManager_LoadBackground_Resolving_protein_details_for__0__proteome, _nameProteome)); bool result = false; // Well formatted Uniprot headers don't require web access, so do an inital pass in hopes of finding those, then a second pass that requires web access for (var useWeb = 0; useWeb <= 1; useWeb++) { if (_progressStatus.IsCanceled) { break; } if (useWeb == 1 && !_manager.FastaImporter.HasWebAccess()) // Do we even have web access? { _progressStatus = _progressStatus.ChangeMessage(Resources.DigestHelper_LookupProteinMetadata_Unable_to_access_internet_to_resolve_protein_details_) .ChangeWarningMessage(Resources.DigestHelper_LookupProteinMetadata_Unable_to_access_internet_to_resolve_protein_details_).Cancel(); result = false; } else { bool done; result |= proteomeDb.LookupProteinMetadata(this, ref _progressStatus, _manager.FastaImporter, useWeb == 0, out done); // first pass, just parse descriptions, second pass use web. if (done) { break; } } } progressStatus = _progressStatus; return(result); } }
private void RefreshOrganisms() { lbxOrganisms.Items.Clear(); if (ProteomeDb != null) { foreach (Organism organism in ProteomeDb.ListOrganisms()) { lbxOrganisms.Items.Add(organism.Name); } if (lbxOrganisms.Items.Count > 0) { lbxOrganisms.SelectedIndex = 0; btnDigest.Enabled = true; } else { btnDigest.Enabled = false; } btnAddOrganism.Enabled = true; } else { btnDigest.Enabled = false; btnAddOrganism.Enabled = false; } }
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; } }
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; } }
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(); }
public void OkDialog() { if (!_messageBoxHelper.ValidateNameTextBox(textName, out _name)) { return; } if (_backgroundProteomeSpec == null || _name != _backgroundProteomeSpec.Name) { foreach (BackgroundProteomeSpec backgroundProteomeSpec in _existing) { if (_name == backgroundProteomeSpec.Name) { _messageBoxHelper.ShowTextBoxError(textName, Resources.BuildBackgroundProteomeDlg_OkDialog_The_background_proteome__0__already_exists, _name); return; } } } if (string.IsNullOrEmpty(textPath.Text)) { _messageBoxHelper.ShowTextBoxError(textPath, Resources.BuildBackgroundProteomeDlg_OkDialog_You_must_specify_a_proteome_file); return; } try { if (textPath.Text != Path.GetFullPath(textPath.Text)) { _messageBoxHelper.ShowTextBoxError(textPath, Resources.BuildBackgroundProteomeDlg_OkDialog_Please_specify_a_full_path_to_the_proteome_file); return; } else if (!File.Exists(textPath.Text)) { _messageBoxHelper.ShowTextBoxError(textPath, string.Format(Resources.BuildBackgroundProteomeDlg_OkDialog_The_proteome_file__0__does_not_exist, textPath.Text)); return; } ProteomeDb.OpenProteomeDb(textPath.Text); } catch (Exception x) { // In case exception is thrown opening protdb string message = TextUtil.LineSeparate(Resources.BuildBackgroundProteomeDlg_OkDialog_The_proteome_file_is_not_valid, Resources.BuildBackgroundProteomeDlg_OkDialog_Choose_a_valid_proteome_file__or_click_the__Create__button_to_create_a_new_one_from_FASTA_files); MessageDlg.ShowWithException(this, message, x); return; } _databasePath = textPath.Text; _name = textName.Text; _backgroundProteomeSpec = new BackgroundProteomeSpec(_name, _databasePath); DialogResult = DialogResult.OK; Close(); }
public IList <Protein> ListProteins() { using (ISession session = ProteomeDb.OpenSession()) { DbOrganism organism = GetEntity(session); List <Protein> proteins = new List <Protein>(); foreach (DbProtein dbProtein in organism.Proteins) { proteins.Add(new Protein(this, dbProtein)); } return(proteins); } }
public IList <Digestion> ListDigestions() { using (ISession session = ProteomeDb.OpenSession()) { DbOrganism organism = GetEntity(session); List <Digestion> digestions = new List <Digestion>(); foreach (DbDigestion dbDigestion in organism.Digestions) { digestions.Add(new Digestion(this, dbDigestion)); } return(digestions); } }
public bool Digest(ref IProgressStatus progressStatus, bool delayDbIndexing) { using (var proteomeDb = ProteomeDb.OpenProteomeDb(_pathProteome, _isTemporary)) { var enzyme = _settings.Enzyme; _progressStatus = progressStatus.ChangeMessage( string.Format(Resources.DigestHelper_Digest_Digesting__0__proteome_with__1__, _nameProteome, enzyme.Name)); var digestion = proteomeDb.Digest(new ProteaseImpl(enzyme), ProteomeDb.PROTDB_MAX_MISSED_CLEAVAGES, this, ref _progressStatus, delayDbIndexing); progressStatus = _progressStatus; return(digestion != null); } }
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)); } }
// ReSharper disable RedundantAssignment public Digestion Digest(ref ProgressStatus progressStatus) // ReSharper restore RedundantAssignment { using (var proteomeDb = ProteomeDb.OpenProteomeDb(_pathProteome, _isTemporary)) { var enzyme = _document.Settings.PeptideSettings.Enzyme; _progressStatus = new ProgressStatus( string.Format(Resources.DigestHelper_Digest_Digesting__0__proteome_with__1__, _nameProteome, enzyme.Name)); var digestion = proteomeDb.Digest(new ProteaseImpl(enzyme), Progress); progressStatus = _progressStatus; return(digestion); } }
// ReSharper disable RedundantAssignment public bool LookupProteinMetadata(ref ProgressStatus progressStatus) // ReSharper restore RedundantAssignment { if (!_manager.FastaImporter.HasWebAccess()) // Do we even have web access? { return(false); // Return silently rather than flashing the progress bar } using (var proteomeDb = ProteomeDb.OpenProteomeDb(_pathProteome, _isTemporary)) { _progressStatus = new ProgressStatus( string.Format(Resources.BackgroundProteomeManager_LoadBackground_Resolving_protein_details_for__0__proteome, _nameProteome)); var result = proteomeDb.LookupProteinMetadata(Progress, _manager.FastaImporter, true); // true means be polite, don't try to resolve all in one go progressStatus = _progressStatus; return(result); } }
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); }
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(); }
public void TestNewerProteomeDb() { using (var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE)) { string protDbPath = testFilesDir.GetTestPath("testv9999.protdb"); // a version 9999(!) protdb file try { using (var db = ProteomeDb.OpenProteomeDb(protDbPath)) { using (var session = db.OpenSession()) session.Close(); Assert.Fail("should not be able to open a version 9999 protdb file."); // Not L10N } } // ReSharper disable once EmptyGeneralCatchClause catch { } } }
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); } } }
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); } } }
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); } } }
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); * */ } } }
public ProteomeDb OpenProteomeDb() { return(ProteomeDb.OpenProteomeDb(DatabasePath)); }
public Digestion Digest(IProtease protease, String name, String description, ProgressMonitor progressMonitor) { DbOrganism organism; DbDigestion digestion; List <DbProtein> proteins; using (ISession session = ProteomeDb.OpenWriteSession()) { organism = GetEntity(session); session.BeginTransaction(); digestion = new DbDigestion { Name = name, Description = description, Organism = organism, MaxMissedCleavages = protease.MaxMissedCleavages }; session.Save(digestion); if (!progressMonitor.Invoke("Listing proteins", 0)) { return(null); } proteins = new List <DbProtein>(organism.Proteins); Dictionary <String, long> digestedPeptideIds = new Dictionary <string, long>(); const String sqlPeptide = "INSERT INTO ProteomeDbDigestedPeptide (Digestion, MissedCleavages, Sequence, Version) VALUES(@Digestion,@MissedCleavages,@Sequence,1);select last_insert_rowid();"; var commandPeptide = session.Connection.CreateCommand(); commandPeptide.CommandText = sqlPeptide; commandPeptide.Parameters.Add(new SQLiteParameter("@Digestion")); commandPeptide.Parameters.Add(new SQLiteParameter("@MissedCleavages")); commandPeptide.Parameters.Add(new SQLiteParameter("@Sequence")); const String sqlPeptideProtein = "INSERT INTO ProteomeDbDigestedPeptideProtein (StartIndex, Peptide, Protein, Version) VALUES(?,?,?,1);"; var commandProtein = session.Connection.CreateCommand(); commandProtein.CommandText = sqlPeptideProtein; commandProtein.Parameters.Add(new SQLiteParameter("@StartIndex")); commandProtein.Parameters.Add(new SQLiteParameter("@Peptide")); commandProtein.Parameters.Add(new SQLiteParameter("@Protein")); for (int i = 0; i < proteins.Count; i++) { if (!progressMonitor.Invoke("Digesting " + proteins.Count + " proteins", 100 * i / proteins.Count)) { return(null); } Protein protein = new Protein(this, proteins[i]); foreach (DigestedPeptide digestedPeptide in protease.Digest(protein)) { if (digestedPeptide.Sequence.Length > MAX_PEPTIDE_LENGTH) { continue; } long digestedPeptideId; if (!digestedPeptideIds.TryGetValue(digestedPeptide.Sequence, out digestedPeptideId)) { ((SQLiteParameter)commandPeptide.Parameters[0]).Value = digestion.Id; ((SQLiteParameter)commandPeptide.Parameters[1]).Value = digestedPeptide.MissedCleavages; ((SQLiteParameter)commandPeptide.Parameters[2]).Value = digestedPeptide.Sequence; digestedPeptideId = Convert.ToInt64(commandPeptide.ExecuteScalar()); digestedPeptideIds.Add(digestedPeptide.Sequence, digestedPeptideId); } ((SQLiteParameter)commandProtein.Parameters[0]).Value = digestedPeptide.Index; ((SQLiteParameter)commandProtein.Parameters[1]).Value = digestedPeptideId; ((SQLiteParameter)commandProtein.Parameters[2]).Value = proteins[i].Id; commandProtein.ExecuteNonQuery(); } } if (!progressMonitor.Invoke("Committing transaction", 99)) { return(null); } session.Transaction.Commit(); progressMonitor.Invoke( "Digested " + proteins.Count + " proteins into " + digestedPeptideIds.Count + " unique peptides", 100); return(new Digestion(this, digestion)); } }
/// <summary> /// Opens a proteome database (creates a session factory, etc.). The ProteomeDb /// returned by this method must be Dispose'd. /// </summary> public ProteomeDb OpenProteomeDb() { return(ProteomeDb.OpenProteomeDb(FilePath)); }
public Organism(ProteomeDb proteomeDb, DbOrganism organism) : base(proteomeDb, organism) { Name = organism.Name; }
/// <summary> /// Tries to match each library peptide to document settings. /// </summary> public void MatchAllPeptides(ILongWaitBroker broker) { _chargeSettingsMap = new AdductMap <SrmSettings>(); // Build a dictionary mapping sequence to proteins because getting this information is slow. var dictSequenceProteins = new Dictionary <string, IList <ProteinInfo> >(); var dictNewNodePeps = new Dictionary <PeptideSequenceModKey, PeptideMatch>(); PeptideMatches = null; MatchedPeptideCount = 0; int peptides = 0; int totalPeptides = _libraryPepInfos.Count; ProteomeDb proteomeDb = null; IStatelessSession session = null; try { foreach (ViewLibraryPepInfo pepInfo in _libraryPepInfos) { if (broker.IsCanceled) { return; } var charge = pepInfo.Key.Adduct; // Find the matching peptide. var nodePepMatched = AssociateMatchingPeptide(pepInfo, charge).PeptideNode; if (nodePepMatched != null) { MatchedPeptideCount++; PeptideMatch peptideMatchInDict; // If peptide is already in the dictionary of peptides to add, merge the children. if (!dictNewNodePeps.TryGetValue(nodePepMatched.SequenceKey, out peptideMatchInDict)) { IList <ProteinInfo> matchedProteins = null; var target = nodePepMatched.Peptide.Target; // This is only set if the user has checked the associate peptide box. if (target.IsProteomic && _backgroundProteome != null) { var sequence = target.Sequence; // We want to query the background proteome as little as possible, // so sequences are mapped to protein lists in a dictionary. if (!dictSequenceProteins.TryGetValue(sequence, out matchedProteins)) { if (proteomeDb == null) { proteomeDb = _backgroundProteome.OpenProteomeDb(broker.CancellationToken); session = proteomeDb.OpenStatelessSession(false); } var digestion = proteomeDb.GetDigestion(); if (sequence.Length >= MIN_PEPTIDE_LENGTH) { matchedProteins = digestion.GetProteinsWithSequence(session, sequence) .Select(protein => new ProteinInfo(protein)).ToList(); } if (matchedProteins == null || matchedProteins.Count > MAX_PROTEIN_MATCHES) { // If the peptide was too short, or matched too many proteins, then // treat it as if it was not found in any proteins. matchedProteins = new List <ProteinInfo>(); } dictSequenceProteins.Add(sequence, matchedProteins); } } dictNewNodePeps.Add(nodePepMatched.SequenceKey, new PeptideMatch(nodePepMatched, matchedProteins, MatchesFilter(target, charge))); } else { PeptideDocNode nodePepInDictionary = peptideMatchInDict.NodePep; if (!nodePepInDictionary.HasChildCharge(charge)) { List <DocNode> newChildren = nodePepInDictionary.Children.ToList(); newChildren.AddRange(nodePepMatched.Children); newChildren.Sort(Peptide.CompareGroups); var key = nodePepMatched.SequenceKey; dictNewNodePeps.Remove(key); dictNewNodePeps.Add(key, new PeptideMatch((PeptideDocNode)nodePepInDictionary.ChangeChildren(newChildren), peptideMatchInDict.Proteins, peptideMatchInDict.MatchesFilterSettings)); } } } peptides++; int progressValue = (int)((peptides + 0.0) / totalPeptides * PERCENT_PEPTIDE_MATCH); broker.ProgressValue = progressValue; } PeptideMatches = dictNewNodePeps; } finally { using (proteomeDb) using (session) { } } }
public Digestion GetDigestion(ProteomeDb proteomeDb, PeptideSettings peptideSettings) { return(proteomeDb.GetDigestion()); }
public ProteomeDb OpenProteomeDb(CancellationToken cancellationToken) { return(ProteomeDb.OpenProteomeDb(FilePath, cancellationToken)); }
private BackgroundProteome Load(IDocumentContainer container, PeptideSettings settings, SrmDocument docCurrent, bool isBackgroundLoad) { // Only allow one background proteome to load at a time. This can // get tricky, if the user performs an undo and then a redo across // a change in background proteome. // Our only priority is accessing web services to add missing protein metadata. // There may also be a load initiation by the Peptide Settings dialog as foreground task, // it takes priority over the background task. lock (_lockLoadBackgroundProteome) { BackgroundProteome originalBackgroundProteome = settings.BackgroundProteome; BackgroundProteome validatedBackgroundProtome = originalBackgroundProteome.DatabaseValidated ? originalBackgroundProteome : new BackgroundProteome(originalBackgroundProteome.BackgroundProteomeSpec); if (IsNotLoadedExplained(settings, validatedBackgroundProtome, true) == null) { // protein metadata is resolved CompleteProcessing(container, validatedBackgroundProtome); Helpers.AssignIfEquals(ref validatedBackgroundProtome, originalBackgroundProteome); return(validatedBackgroundProtome); // No change needed } // we are here to resolve the protein metadata string name = originalBackgroundProteome.Name; IProgressStatus progressStatus = new ProgressStatus(string.Format(Resources.BackgroundProteomeManager_LoadBackground_Resolving_protein_details_for__0__proteome, name)); try { // The transaction commit for writing the digestion info can be very lengthy, avoid lock timeouts // by doing that work in a tempfile that no other thread knows aboout using (FileSaver fs = new FileSaver(originalBackgroundProteome.DatabasePath, StreamManager)) { File.Copy(originalBackgroundProteome.DatabasePath, fs.SafeName, true); var digestHelper = new DigestHelper(this, container, docCurrent, name, fs.SafeName, true); bool success = digestHelper.LookupProteinMetadata(ref progressStatus); if (digestHelper.IsCanceled || !success) { // Processing was canceled if (docCurrent != null) { EndProcessing(docCurrent); } UpdateProgress(progressStatus.Cancel()); return(null); } using (var proteomeDb = ProteomeDb.OpenProteomeDb(originalBackgroundProteome.DatabasePath)) { proteomeDb.DatabaseLock.AcquireWriterLock(int.MaxValue); // Wait for any existing readers to complete, prevent any new ones try { if (File.GetLastWriteTime(fs.RealName) <= File.GetLastWriteTime(fs.SafeName)) // Don't overwrite if foreground task has already updated { proteomeDb.CloseDbConnection(); // Get rid of any file handles if (!fs.Commit()) { if (docCurrent != null) { EndProcessing(docCurrent); } throw new IOException(string.Format(Resources.BackgroundProteomeManager_LoadBackground_Unable_to_rename_temporary_file_to__0__, fs.RealName)); } } } finally { proteomeDb.DatabaseLock.ReleaseWriterLock(); } } var updatedProteome = new BackgroundProteome(originalBackgroundProteome); using (var proteomeDb = originalBackgroundProteome.OpenProteomeDb()) { proteomeDb.AnalyzeDb(); // Now it's safe to start this potentially lengthy indexing operation } CompleteProcessing(container, updatedProteome); UpdateProgress(progressStatus.Complete()); return(updatedProteome); } } catch (Exception x) { var message = new StringBuilder(); message.AppendLine( string.Format(Resources.BackgroundProteomeManager_LoadBackground_Failed_updating_background_proteome__0__, name)); message.Append(x.Message); UpdateProgress(progressStatus.ChangeErrorException(new IOException(message.ToString(), x))); return(null); } } }