Пример #1
0
        /// <summary>
        ///     Performs the analysis.
        /// </summary>
        private void PerformAnalysisGui(AnalysisConfig config, AlgorithmBuilder builder, AnalysisType validated,
            bool createDatabase, WorkerObject worker)
        {
            Logger.PrintMessage("Performing analysis.");

            MultiAlignAnalysisProcessor processor = null;

            try
            {
                // Creates or connects to the underlying analysis database.
                var providers = SetupDataProviders(createDatabase);

                // Create the clustering, analysis, and plotting paths.
                builder.BuildClusterer(config.Analysis.Options.LcmsClusteringOptions.LcmsFeatureClusteringAlgorithm);
                config.Analysis.DataProviders = providers;
                config.Analysis.AnalysisType = validated;
                ConstructPlotPath();

                ExportParameterFile();
                Logger.PrintSpacer();
                PrintParameters(config.Analysis, createDatabase);
                Logger.PrintSpacer();

                // Setup the processor.
                processor = ConstructAnalysisProcessor(builder, providers);

                // Tell the processor whether to load data or not.
                processor.ShouldLoadData = createDatabase;

                // Construct the dataset information for export.// Create dataset information.
                Logger.PrintMessage("Storing dataset information into the database.");

                var information = Enumerable.ToList(config.Analysis.MetaData.Datasets);
                m_config.Analysis.DataProviders.DatasetCache.AddAll(information);

                Logger.PrintMessage("Creating exporter options.");
                if (config.ExporterNames.CrossTabPath == null)
                {
                    config.ExporterNames.CrossTabPath = config.AnalysisName.Replace(".db3", "");
                }
                if (config.ExporterNames.CrossTabAbundance == null)
                {
                    config.ExporterNames.CrossTabAbundance = config.AnalysisName.Replace(".db3", "");
                }
                ConstructExporting();

                Logger.PrintMessage("Cleaning up old analysis branches.");
                CleanupOldAnalysisBranches(config);

                Logger.PrintMessage("Analysis Started.");
                processor.StartAnalysis(config);

                var handleId =
                    WaitHandle.WaitAny(new WaitHandle[] { config.triggerEvent, config.errorEvent, config.stopEvent });

                if (handleId == 1)
                {
                    Logger.PrintMessageWorker("There was an error during processing.", 1, false);
                    config.triggerEvent.Dispose();
                    config.errorEvent.Dispose();
                    processor.Dispose();

                    if (AnalysisError != null)
                    {
                        AnalysisError(this, null);
                    }
                    return;
                }
                if (handleId == 2)
                {
                    Logger.PrintMessageWorker("Stopping the analysis.", 1, false);
                    processor.StopAnalysis();

                    worker.SynchEvent.Set();
                    Thread.Sleep(50);

                    config.triggerEvent.Dispose();
                    config.errorEvent.Dispose();
                    processor.Dispose();

                    if (AnalysisCancelled != null)
                    {
                        AnalysisCancelled(this, null);
                    }
                    return;
                }
            }
            catch (Exception ex)
            {
                Logger.PrintMessage(
                    "There was an error Performing analysis");
                Logger.PrintMessage(ex.Message);
                Logger.PrintMessage(ex.StackTrace);
                return;
            }

            try
            {
                m_reportCreator.CreatePlotReport();
            }
            catch (Exception ex)
            {
                Logger.PrintMessage(
                    "There was an error when trying to create the final analysis plots, however, the data analysis is complete.");
                Logger.PrintMessage(ex.Message);
                Logger.PrintMessage(ex.StackTrace);
            }

            config.triggerEvent.Dispose();
            config.errorEvent.Dispose();
            processor.Dispose();
            CleanupDataProviders();

            Logger.PrintMessage("Indexing Database Clusters for Faster Retrieval");
            var databasePath = Path.Combine(m_config.AnalysisPath, m_config.AnalysisName);
            DatabaseIndexer.IndexClusters(databasePath);
            Logger.PrintMessage("Indexing Database Features");
            DatabaseIndexer.IndexFeatures(databasePath);

            Logger.PrintMessage("Analysis Complete");

            if (AnalysisComplete != null)
            {
                AnalysisComplete(this, null);
            }
        }
Пример #2
0
        /// <summary>
        ///     This is horrible.  A common ground of feature / functionality should be made here.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="reporter"></param>
        /// <returns></returns>
        public void StartMultiAlignGui(AnalysisConfig config, IAnalysisReportGenerator reporter)
        {
            m_worker = new BackgroundWorker();
            m_worker.DoWork += m_worker_DoWork;
            m_workerManager = new WorkerObject(m_worker);
            m_reportCreator = reporter;
            m_config = config;

            m_worker.WorkerSupportsCancellation = true;
            m_worker.RunWorkerAsync();
        }