/// <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);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public static IonMobilityLibrary CreateFromResults(SrmDocument document, string documentFilePath, bool useHighEnergyOffset,
                                                           string libraryName, string dbPath, IProgressMonitor progressMonitor = null)
        {
            // Overwrite any existing measurements with newly derived ones
            var measured      = CreateFromResults(document, documentFilePath, useHighEnergyOffset, progressMonitor);
            var ionMobilityDb = IonMobilityDb.CreateIonMobilityDb(dbPath, libraryName, false).
                                UpdateIonMobilities(measured.Select(m => new PrecursorIonMobilities(
                                                                        m.Key, m.Value)).ToList());

            return(new IonMobilityLibrary(libraryName, dbPath, ionMobilityDb));
        }
Beispiel #4
0
 public bool Equals(IonMobilityDb other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other._path, _path) &&
            other._modifiedTime.Equals(_modifiedTime));
 }
Beispiel #5
0
        public override IonMobilityLibrarySpec Initialize(IProgressMonitor loadMonitor)
        {
            if (_database != null)
            {
                return(this);
            }
            var database = IonMobilityDb.GetIonMobilityDb(DatabasePath, loadMonitor);

            // Check for the case where an exception was handled by the progress monitor
            if (database == null)
            {
                return(null);
            }
            return(ChangeDatabase(database));
        }
Beispiel #6
0
        public static IonMobilityLibrary CreateFromDictionary(string libraryName, string dbDir, IDictionary <LibKey, List <IonMobilityAndCCS> > dict)
        {
            var           fname = Path.GetFullPath(dbDir.Contains(IonMobilityDb.EXT) ? dbDir : Path.Combine(dbDir, libraryName + IonMobilityDb.EXT));
            IonMobilityDb ionMobilityDb;

            using (var fs = new FileSaver(fname))
            {
                ionMobilityDb = IonMobilityDb.CreateIonMobilityDb(fs.SafeName, libraryName, false);
                if (dict != null)
                {
                    var list = dict.Select(kvp => new PrecursorIonMobilities(kvp.Key, kvp.Value));
                    ionMobilityDb = ionMobilityDb.UpdateIonMobilities(list);
                }
                fs.Commit();
            }
            return(new IonMobilityLibrary(libraryName, fname, ionMobilityDb));
        }
Beispiel #7
0
 public bool Equals(IonMobilityDb other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other._path, _path) &&
         other._modifiedTime.Equals(_modifiedTime);
 }
Beispiel #8
0
 public IonMobilityLibrary ChangeDatabase(IonMobilityDb database)
 {
     return(ChangeProp(ImClone(this), im => im._database = database));
 }
 public IonMobilityLibrary ChangeDatabase(IonMobilityDb database)
 {
     return ChangeProp(ImClone(this), im => im._database = database);
 }
Beispiel #10
0
        /// <summary>
        /// Saves the database to a new directory with only the ions used
        /// in a given document.
        /// </summary>
        /// <param name="pathDestDir">The directory to save to</param>
        /// <param name="document">The document for which ions are to be kept</param>
        /// <param name="smallMoleculeConversionMap">Used for changing charge,modifedSeq to adduct,molecule in small molecule conversion</param>
        /// <param name="loadedDatabase">Returns in-memory representation of the revised ion mobility table</param>
        /// <returns>The full path to the file saved</returns>
        public string PersistMinimized(string pathDestDir,
                                       SrmDocument document, IDictionary <LibKey, LibKey> smallMoleculeConversionMap, out IonMobilityDb loadedDatabase)
        {
            RequireUsable();

            var fname = Path.GetFileName(FilePath);

            if (smallMoleculeConversionMap != null && fname != null &&
                !fname.Contains(BiblioSpecLiteSpec.DotConvertedToSmallMolecules))
            {
                fname = fname.Replace(IonMobilityDb.EXT, BiblioSpecLiteSpec.DotConvertedToSmallMolecules + IonMobilityDb.EXT);
            }

            fname = fname ?? string.Empty; // Keeps ReSharper from complaining about possible null
            string persistPath = Path.Combine(pathDestDir, fname);

            using (var fs = new FileSaver(persistPath))
            {
                var libraryName          = fname.Replace(IonMobilityDb.EXT, String.Empty);
                var ionMobilityDbMinimal = IonMobilityDb.CreateIonMobilityDb(fs.SafeName, libraryName, true);

                // Calculate the minimal set of peptides needed for this document
                var dbPrecursors         = _database.DictLibrary.LibKeys;
                var persistIonMobilities = new List <PrecursorIonMobilities>();

                var dictPrecursors = dbPrecursors.ToDictionary(p => p.LibraryKey);
                foreach (var pair in document.MoleculePrecursorPairs)
                {
                    var test =
                        new PrecursorIonMobilities(pair.NodePep.ModifiedTarget, pair.NodeGroup.PrecursorAdduct, 0, 0, 0, eIonMobilityUnits.none);
                    var key = test.Precursor;
                    if (dictPrecursors.TryGetValue(key, out var dbPrecursor))
                    {
                        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;
                                dbPrecursor = new LibKey(smallMoleculeAttributes, precursorAdduct);
                            }
                            else
                            {
                                // Not being converted
                                Assume.IsTrue(pair.NodeGroup.Peptide.IsDecoy);
                                continue;
                            }
                        }
                        persistIonMobilities.Add(new PrecursorIonMobilities(dbPrecursor, test.IonMobilities));
                        // Only add once
                        dictPrecursors.Remove(key);
                    }
                }

                loadedDatabase = ionMobilityDbMinimal.UpdateIonMobilities(persistIonMobilities);
                fs.Commit();
            }

            return(persistPath);
        }
Beispiel #11
0
 public IonMobilityLibrary(string name, string filePath, IonMobilityDb loadedDatabase) : base(name, filePath)
 {
     _database = loadedDatabase;
 }