Ejemplo n.º 1
0
 public bool GetNeedsProteinMetadataSearch()
 {
     if (!_needsProteinMetadataSearch.HasValue)
     {
         _needsProteinMetadataSearch = true; // Until proven otherwise
         if (!_parent.IsNone)
         {
             try
             {
                 using (var proteomeDb = _parent.OpenProteomeDb())
                 {
                     _needsProteinMetadataSearch = proteomeDb.HasProteinNamesWithUnresolvedMetadata();
                 }
             }
             catch (Exception)
             {
                 _parent.DatabaseInvalid = true;  // Note this breaks immutabilty, but has been that way forever
             }
         }
         else
         {
             _needsProteinMetadataSearch = false; // No parent, no proteins, no search needed
         }
     }
     return(_needsProteinMetadataSearch.Value);
 }
Ejemplo n.º 2
0
        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);
                }
            }
        }