public MassTagDatabase LoadDatabase()
        {
            var database = new MassTagDatabase {Name = ""};

            UpdateStatus("Loading all of the mass tags.");
            // Get all of the mass tags
            var massTags = Provider.FindAll();

            UpdateStatus("Loading all of the tag to protein references.");
            // Then get all of the mass tag to protein maps
            IGenericDAO<MassTagToProteinMap> tagToProteinMapCache = new GenericDAOHibernate<MassTagToProteinMap>();
            var maps = tagToProteinMapCache.FindAll();

            // Then get all of the proteins
            UpdateStatus("Loading all of the protein data.");
            IProteinDAO proteinCache = new ProteinDAO();
            var proteins = proteinCache.FindAll();

            UpdateStatus("Indexing the protein data for faster assembly.");
            var proteinMap = new Dictionary<int, Protein>();
            foreach (var p in proteins)
            {
                if (!proteinMap.ContainsKey(p.ProteinId))
                {
                    proteinMap.Add(p.ProteinId, p);
                }
            }

            var matchedMaps = new Dictionary<int, List<MassTagToProteinMap>>();

            foreach (var singleMap in maps)
            {
                if (!matchedMaps.ContainsKey(singleMap.MassTagId))
                {
                    matchedMaps.Add(singleMap.MassTagId, new List<MassTagToProteinMap>());
                }
                matchedMaps[singleMap.MassTagId].Add(singleMap);
            }

            UpdateStatus("Re-mapping the proteins to the mass tags.");
            var massTagProteinMap = new Dictionary<int, List<Protein>>();

            // Then map them.
            foreach (var tag in massTags)
            {
                var id = tag.Id;

                if (!massTagProteinMap.ContainsKey(id))
                {
                    massTagProteinMap.Add(id, new List<Protein>());
                }

                var matches = new List<MassTagToProteinMap>();

                if (matchedMaps.ContainsKey(id))
                {
                    matches = matchedMaps[id];
                }

                var newProteins = new List<Protein>();
                foreach (var mtMap in matches)
                {
                    if (proteinMap.ContainsKey(mtMap.ProteinId))
                    {
                        newProteins.Add(proteinMap[mtMap.ProteinId]);
                    }
                }
                massTagProteinMap[id].AddRange(newProteins);
            }

            UpdateStatus("Building the in memory mass tag database.");
            database.AddMassTagsAndProteins(massTags, massTagProteinMap);
            database.AllProteins = proteins;

            var totalMassTags = database.MassTags.Count;
            UpdateStatus("Loaded " + totalMassTags + " mass tags.");

            return database;
        }
        /// <summary>
        ///     Creates an entry in the DB if a new database should be created.
        /// </summary>
        /// <param name="config"></param>
        private void CreateMtdb(AnalysisConfig config)
        {
            MassTagDatabase database;

            // Load the mass tag database if we are aligning, or if we are
            // peak matching (but aligning to a reference dataset.
            if (m_config.Analysis.Options.AlignmentOptions.IsAlignmentBaselineAMasstagDB)
            {
                UpdateStatus("Loading Mass Tag database from database:  " +
                             m_config.Analysis.MetaData.Database.DatabaseName);
                database = MtdbLoaderFactory.LoadMassTagDatabase(m_config.Analysis.MetaData.Database,
                    m_config.Analysis.Options.MassTagDatabaseOptions);
            }
            else if (m_config.Analysis.MetaData.Database != null &&
                     m_config.Analysis.MetaData.Database.DatabaseFormat != MassTagDatabaseFormat.None)
            {
                UpdateStatus("Loading Mass Tag database from database:  " +
                             m_config.Analysis.MetaData.Database.DatabaseName);
                database = MtdbLoaderFactory.LoadMassTagDatabase(m_config.Analysis.MetaData.Database,
                    m_config.Analysis.Options.MassTagDatabaseOptions);
            }
            else
            {
                config.Analysis.MassTagDatabase = null;
                config.ShouldPeakMatch = false;
                return;
            }

            if (database != null)
            {
                config.ShouldPeakMatch = true;
                var totalMassTags = database.MassTags.Count;
                UpdateStatus("Loaded " + totalMassTags + " mass tags.");
            }

            config.Analysis.MassTagDatabase = database;

            if (database == null)
                return;

            config.Analysis.DataProviders.MassTags.AddAll(database.MassTags);

            var proteinCache = new ProteinDAO();
            proteinCache.AddAll(database.AllProteins);

            var map = (from massTagId in database.Proteins.Keys
                from p in database.Proteins[massTagId]
                select new MassTagToProteinMap
                {
                    ProteinId = p.ProteinId,
                    MassTagId = massTagId,
                    RefId = p.RefId
                }).ToList();

            var tempCache = new GenericDAOHibernate<MassTagToProteinMap>();
            tempCache.AddAll(map);

            if (MassTagsLoaded != null)
                MassTagsLoaded(this, new MassTagsLoadedEventArgs(database.MassTags, database));
        }
示例#3
0
        /// <summary>
        ///     Writes the parameters to the log file and database.
        /// </summary>
        private void PrintParameters(MultiAlignAnalysis analysis, bool insertIntoDatabase)
        {
            Logger.PrintMessage("Parameters Loaded");
            var options = new Dictionary<string, object>
            {
                {"Instrument Tolerances", analysis.Options.InstrumentTolerances},
                {"Ms Feature Filtering Options", analysis.Options.MsFilteringOptions},
                {"Feature Filtering Options", analysis.Options.LcmsFilteringOptions},
                {"Mass Tag Database Options", analysis.Options.MassTagDatabaseOptions},
                {"Alignment Options", analysis.Options.AlignmentOptions},
                {"Clustering Options", analysis.Options.LcmsClusteringOptions},
                {"STAC Options", analysis.Options.StacOptions}
            };

            var allmappings = new List<ParameterHibernateMapping>();
            foreach (var key in options.Keys)
            {
                //var o = options[key];
                Logger.PrintMessage(key, true);
                //var parameters = ParameterUtility.ConvertParameterObjectToStrings(o);
                //foreach (var parameter in parameters)
                //{
                //    Logger.PrintMessage("\t" + parameter, true);
                //}

                //var mappings = ParameterUtility.ExtractParameterMapObjects(o, key);
                //allmappings.AddRange(mappings);
            }

            var assemblyData = ApplicationUtility.GetAssemblyData();
            var assemblyMap = new ParameterHibernateMapping
            {
                OptionGroup = "Assembly Info",
                Parameter = "Version",
                Value = assemblyData
            };
            allmappings.Add(assemblyMap);

            var systemData = ApplicationUtility.GetSystemData();
            var systemMap = new ParameterHibernateMapping
            {
                OptionGroup = "Assembly Info",
                Parameter = "System Info",
                Value = systemData
            };
            allmappings.Add(systemMap);

            if (insertIntoDatabase)
            {
                Logger.PrintMessage("Writing parameters to the analysis database.");
                var parameterCache = new GenericDAOHibernate<ParameterHibernateMapping>();
                parameterCache.AddAll(allmappings);
            }
        }
示例#4
0
        /// <summary>
        ///     Creates an entry in the DB if a new database should be created.
        /// </summary>
        /// <param name="config"></param>
        private void CreateMtdb(AnalysisConfig config)
        {
            MassTagDatabase database;

            // Load the mass tag database if we are aligning, or if we are
            // peak matching (but aligning to a reference dataset.
            if (m_config.Analysis.Options.AlignmentOptions.IsAlignmentBaselineAMasstagDB)
            {
                UpdateStatus("Loading Mass Tag database from database:  " +
                             m_config.Analysis.MetaData.Database.DatabaseName);
                database = MtdbLoaderFactory.LoadMassTagDatabase(m_config.Analysis.MetaData.Database,
                                                                 m_config.Analysis.Options.MassTagDatabaseOptions);
            }
            else if (m_config.Analysis.MetaData.Database != null &&
                     m_config.Analysis.MetaData.Database.DatabaseFormat != MassTagDatabaseFormat.None)
            {
                UpdateStatus("Loading Mass Tag database from database:  " +
                             m_config.Analysis.MetaData.Database.DatabaseName);
                database = MtdbLoaderFactory.LoadMassTagDatabase(m_config.Analysis.MetaData.Database,
                                                                 m_config.Analysis.Options.MassTagDatabaseOptions);
            }
            else
            {
                config.Analysis.MassTagDatabase = null;
                config.ShouldPeakMatch          = false;
                return;
            }


            if (database != null)
            {
                config.ShouldPeakMatch = true;
                var totalMassTags = database.MassTags.Count;
                UpdateStatus("Loaded " + totalMassTags + " mass tags.");
            }

            config.Analysis.MassTagDatabase = database;


            if (database == null)
            {
                return;
            }

            config.Analysis.DataProviders.MassTags.AddAll(database.MassTags);

            var proteinCache = new ProteinDAO();

            proteinCache.AddAll(database.AllProteins);

            var map = (from massTagId in database.Proteins.Keys
                       from p in database.Proteins[massTagId]
                       select new MassTagToProteinMap
            {
                ProteinId = p.ProteinId,
                MassTagId = massTagId,
                RefId = p.RefId
            }).ToList();

            var tempCache = new GenericDAOHibernate <MassTagToProteinMap>();

            tempCache.AddAll(map);

            if (MassTagsLoaded != null)
            {
                MassTagsLoaded(this, new MassTagsLoadedEventArgs(database.MassTags, database));
            }
        }
示例#5
0
        public MassTagDatabase LoadDatabase()
        {
            var database = new MassTagDatabase {
                Name = ""
            };

            UpdateStatus("Loading all of the mass tags.");
            // Get all of the mass tags
            var massTags = Provider.FindAll();


            UpdateStatus("Loading all of the tag to protein references.");
            // Then get all of the mass tag to protein maps
            IGenericDAO <MassTagToProteinMap> tagToProteinMapCache = new GenericDAOHibernate <MassTagToProteinMap>();
            var maps = tagToProteinMapCache.FindAll();

            // Then get all of the proteins
            UpdateStatus("Loading all of the protein data.");
            IProteinDAO proteinCache = new ProteinDAO();
            var         proteins     = proteinCache.FindAll();

            UpdateStatus("Indexing the protein data for faster assembly.");
            var proteinMap = new Dictionary <int, Protein>();

            foreach (var p in proteins)
            {
                if (!proteinMap.ContainsKey(p.ProteinId))
                {
                    proteinMap.Add(p.ProteinId, p);
                }
            }

            var matchedMaps = new Dictionary <int, List <MassTagToProteinMap> >();

            foreach (var singleMap in maps)
            {
                if (!matchedMaps.ContainsKey(singleMap.MassTagId))
                {
                    matchedMaps.Add(singleMap.MassTagId, new List <MassTagToProteinMap>());
                }
                matchedMaps[singleMap.MassTagId].Add(singleMap);
            }

            UpdateStatus("Re-mapping the proteins to the mass tags.");
            var massTagProteinMap = new Dictionary <int, List <Protein> >();

            // Then map them.
            foreach (var tag in massTags)
            {
                var id = tag.Id;

                if (!massTagProteinMap.ContainsKey(id))
                {
                    massTagProteinMap.Add(id, new List <Protein>());
                }

                var matches = new List <MassTagToProteinMap>();

                if (matchedMaps.ContainsKey(id))
                {
                    matches = matchedMaps[id];
                }

                var newProteins = new List <Protein>();
                foreach (var mtMap in matches)
                {
                    if (proteinMap.ContainsKey(mtMap.ProteinId))
                    {
                        newProteins.Add(proteinMap[mtMap.ProteinId]);
                    }
                }
                massTagProteinMap[id].AddRange(newProteins);
            }

            UpdateStatus("Building the in memory mass tag database.");
            database.AddMassTagsAndProteins(massTags, massTagProteinMap);
            database.AllProteins = proteins;

            var totalMassTags = database.MassTags.Count;

            UpdateStatus("Loaded " + totalMassTags + " mass tags.");

            return(database);
        }