Beispiel #1
0
        /// <summary>
        /// Saves the database to a new directory with only the optimizations used
        /// in a given document.
        /// </summary>
        /// <param name="pathDestDir">The directory to save to</param>
        /// <param name="document">The document for which peptides are to be kept</param>
        /// <returns>The full path to the file saved</returns>
        public string PersistMinimized(string pathDestDir, SrmDocument document)
        {
            RequireUsable();

            string persistPath = Path.Combine(pathDestDir, Path.GetFileName(PersistencePath) ?? string.Empty);  // ReSharper

            using (var fs = new FileSaver(persistPath))
            {
                var optDbMinimal = OptimizationDb.CreateOptimizationDb(fs.SafeName);

                // Calculate the minimal set of optimizations needed for this document
                var persistOptimizations = new List <DbOptimization>();
                var dictOptimizations    = new OptimizationDictionary(_database.GetOptimizations());
                var persistedKeys        = new HashSet <OptimizationKey>();
                foreach (PeptideGroupDocNode seq in document.MoleculeGroups)
                {
                    // Skip peptide groups with no transitions
                    if (seq.TransitionCount == 0)
                    {
                        continue;
                    }
                    foreach (PeptideDocNode peptide in seq.Children)
                    {
                        foreach (TransitionGroupDocNode group in peptide.Children)
                        {
                            var modSeq = document.Settings.GetSourceTarget(peptide);
                            var charge = group.PrecursorAdduct;
                            foreach (TransitionDocNode transition in group.Children)
                            {
                                foreach (var optType in Enum.GetValues(typeof(OptimizationType)).Cast <OptimizationType>())
                                {
                                    var optimizationKey = new OptimizationKey(optType, modSeq, charge, transition.FragmentIonName, transition.Transition.Adduct);
                                    foreach (var dbOptimization in dictOptimizations.EntriesMatching(optimizationKey))
                                    {
                                        if (persistedKeys.Add(dbOptimization.Key))
                                        {
                                            persistOptimizations.Add(dbOptimization);
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                optDbMinimal.UpdateOptimizations(persistOptimizations, new DbOptimization[0]);
                fs.Commit();
            }

            return(persistPath);
        }
Beispiel #2
0
        /// <summary>
        /// Saves the database to a new directory with only the optimizations used
        /// in a given document.
        /// </summary>
        /// <param name="pathDestDir">The directory to save to</param>
        /// <param name="document">The document for which peptides are to be kept</param>
        /// <returns>The full path to the file saved</returns>
        public string PersistMinimized(string pathDestDir, SrmDocument document)
        {
            RequireUsable();

            string persistPath = Path.Combine(pathDestDir, Path.GetFileName(PersistencePath) ?? string.Empty);  // ReSharper

            using (var fs = new FileSaver(persistPath))
            {
                var optDbMinimal = OptimizationDb.CreateOptimizationDb(fs.SafeName);

                // Calculate the minimal set of optimizations needed for this document
                var persistOptimizations = new List <DbOptimization>();
                var dictOptimizations    = _database.GetOptimizations().ToDictionary(opt => opt.Key);
                foreach (PeptideGroupDocNode seq in document.MoleculeGroups)
                {
                    // Skip peptide groups with no transitions
                    if (seq.TransitionCount == 0)
                    {
                        continue;
                    }
                    foreach (PeptideDocNode peptide in seq.Children)
                    {
                        foreach (TransitionGroupDocNode group in peptide.Children)
                        {
                            string modSeq = document.Settings.GetSourceTextId(peptide);
                            int    charge = group.PrecursorCharge;
                            foreach (TransitionDocNode transition in group.Children)
                            {
                                foreach (var optType in Enum.GetValues(typeof(OptimizationType)).Cast <OptimizationType>())
                                {
                                    var            optimizationKey = new OptimizationKey(optType, modSeq, charge, transition.FragmentIonName, transition.Transition.Charge);
                                    DbOptimization dbOptimization;
                                    if (dictOptimizations.TryGetValue(optimizationKey, out dbOptimization))
                                    {
                                        persistOptimizations.Add(new DbOptimization(dbOptimization.Key, dbOptimization.Value));
                                        // Only add once
                                        dictOptimizations.Remove(optimizationKey);
                                    }
                                }
                            }
                        }
                    }
                }

                optDbMinimal.UpdateOptimizations(persistOptimizations, new DbOptimization[0]);
                fs.Commit();
            }

            return(persistPath);
        }