Beispiel #1
0
        /// <summary>
        /// Saves the database to a new directory with only the charged peptides used
        /// in a given document.
        /// </summary>
        /// <param name="pathDestDir">The directory to save to</param>
        /// <param name="document">The document for which charged peptides are to be kept</param>
        /// <param name="smallMoleculeConversionMap">Used for changing charge,modifedSeq to adduct,molecule in small molecule conversion</param>
        /// <returns>The full path to the file saved</returns>
        public override string PersistMinimized(string pathDestDir,
                                                SrmDocument document, IDictionary <LibKey, LibKey> smallMoleculeConversionMap)
        {
            RequireUsable();

            var fname = Path.GetFileName(PersistencePath);

            if (smallMoleculeConversionMap != null && fname != null &&
                !fname.Contains(BiblioSpecLiteSpec.DotConvertedToSmallMolecules))
            {
                fname = fname.Replace(IonMobilityDb.EXT, BiblioSpecLiteSpec.DotConvertedToSmallMolecules + IonMobilityDb.EXT);
            }
            string persistPath = Path.Combine(pathDestDir, fname ?? String.Empty);

            using (var fs = new FileSaver(persistPath))
            {
                var ionMobilityDbMinimal = IonMobilityDb.CreateIonMobilityDb(fs.SafeName);

                // Calculate the minimal set of peptides needed for this document
                var dbPeptides      = _database.GetPeptides().ToList();
                var persistPeptides = new List <ValidatingIonMobilityPeptide>();

                var dictPeptides = dbPeptides.ToDictionary(pep => pep.GetLibKey());
                foreach (var pair in document.MoleculePrecursorPairs)
                {
                    var test =
                        new ValidatingIonMobilityPeptide(pair.NodePep.ModifiedTarget, pair.NodeGroup.PrecursorAdduct, 0, 0);
                    var key = test.GetLibKey();
                    DbIonMobilityPeptide dbPeptide;
                    if (dictPeptides.TryGetValue(key, out dbPeptide))
                    {
                        if (smallMoleculeConversionMap != null)
                        {
                            // We are in the midst of converting a document to small molecules for test purposes
                            LibKey smallMolInfo;
                            if (smallMoleculeConversionMap.TryGetValue(new LibKey(pair.NodePep.ModifiedSequence, pair.NodeGroup.PrecursorCharge), out smallMolInfo))
                            {
                                var precursorAdduct         = smallMolInfo.Adduct;
                                var smallMoleculeAttributes = smallMolInfo.SmallMoleculeLibraryAttributes;
                                dbPeptide = new DbIonMobilityPeptide(smallMoleculeAttributes, precursorAdduct, dbPeptide.CollisionalCrossSection, dbPeptide.HighEnergyDriftTimeOffsetMsec);
                            }
                            else
                            {
                                // Not being converted
                                Assume.IsTrue(pair.NodeGroup.Peptide.IsDecoy);
                                continue;
                            }
                        }
                        persistPeptides.Add(new ValidatingIonMobilityPeptide(dbPeptide));
                        // Only add once
                        dictPeptides.Remove(key);
                    }
                }

                ionMobilityDbMinimal.UpdatePeptides(persistPeptides, new ValidatingIonMobilityPeptide[0]);
                fs.Commit();
            }

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

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

            using (var fs = new FileSaver(persistPath))
            {
                var ionMobilityDbMinimal = IonMobilityDb.CreateIonMobilityDb(fs.SafeName);

                // Calculate the minimal set of peptides needed for this document
                var dbPeptides      = _database.GetPeptides().ToList();
                var persistPeptides = new List <ValidatingIonMobilityPeptide>();
                var dictPeptides    = dbPeptides.ToDictionary(pep => pep.PeptideModSeq);
                foreach (var peptide in document.Molecules)
                {
                    string modifiedSeq = document.Settings.GetSourceTextId(peptide);
                    DbIonMobilityPeptide dbPeptide;
                    if (dictPeptides.TryGetValue(modifiedSeq, out dbPeptide))
                    {
                        persistPeptides.Add(new ValidatingIonMobilityPeptide(dbPeptide.Sequence, dbPeptide.CollisionalCrossSection, dbPeptide.HighEnergyDriftTimeOffsetMsec));
                        // Only add once
                        dictPeptides.Remove(modifiedSeq);
                    }
                }

                ionMobilityDbMinimal.UpdatePeptides(persistPeptides, new ValidatingIonMobilityPeptide[0]);
                fs.Commit();
            }

            return(persistPath);
        }