/// <summary> /// Loads baseline data for alignment. /// </summary> private IList <UMCLight> LoadBaselineData(DatasetInformation baselineInfo, MsFeatureFilteringOptions msFilterOptions, LcmsFeatureFindingOptions lcmsFindingOptions, LcmsFeatureFilteringOptions lcmsFilterOptions, DataLoadingOptions dataLoadOptions, FeatureDataAccessProviders dataProviders, MassTagDatabase database, bool shouldUseMassTagDbAsBaseline) { IList <UMCLight> baselineFeatures = null; UpdateStatus("Loading baseline features."); if (!shouldUseMassTagDbAsBaseline) { if (baselineInfo == null) { throw new Exception("The baseline dataset was never set."); } var cache = new FeatureLoader { Providers = dataProviders }; RegisterProgressNotifier(cache); UpdateStatus("Loading baseline features from " + baselineInfo.DatasetName + " for alignment."); baselineFeatures = cache.LoadDataset(baselineInfo, msFilterOptions, lcmsFindingOptions, lcmsFilterOptions, dataLoadOptions, m_scanSummaryProviderCache, this.m_identificationsProvider); cache.CacheFeatures(baselineFeatures); if (BaselineFeaturesLoaded != null) { BaselineFeaturesLoaded(this, new BaselineFeaturesLoadedEventArgs(baselineInfo, baselineFeatures.ToList())); } DeRegisterProgressNotifier(cache); } else { if (database == null) { throw new NullReferenceException( "The mass tag database has to have data in it if it's being used for drift time alignment."); } UpdateStatus("Setting baseline features for post drift time alignment from mass tag database."); var tags = FeatureDataConverters.ConvertToUMC(database.MassTags); if (BaselineFeaturesLoaded == null) { return(tags); } if (tags != null) { BaselineFeaturesLoaded(this, new BaselineFeaturesLoadedEventArgs(null, tags.ToList(), database)); } } return(baselineFeatures); }
internal void LoadFeatures(List <DatasetInformationViewModel> workFlowDatasets = null, IProgress <ProgressData> workflowProgress = null) { var featureCache = new FeatureLoader { Providers = this.analysis.DataProviders }; this.ShouldShowProgress = true; var selectedFiles = workFlowDatasets ?? this.Datasets.Where(file => !file.DoingWork).Where(ds => ds.IsSelected).ToList(); foreach (var file in selectedFiles) { file.DatasetState = DatasetInformationViewModel.DatasetStates.FindingFeatures; ThreadSafeDispatcher.Invoke(() => this.PlotMsFeaturesCommand.RaiseCanExecuteChanged()); ThreadSafeDispatcher.Invoke(() => this.FindMsFeaturesCommand.RaiseCanExecuteChanged()); } var taskBarProgress = TaskBarProgress.GetInstance(); taskBarProgress.ShowProgress(this, true); workflowProgress = workflowProgress ?? new Progress <ProgressData>(); IProgress <ProgressData> totalProgressRpt = new Progress <ProgressData>(pd => { this.TotalProgress = pd.Percent; taskBarProgress.SetProgress(this, pd.Percent); workflowProgress.Report(pd); }); var totalProgressData = new ProgressData(totalProgressRpt); DatabaseIndexer.IndexClustersDrop(NHibernateUtil.Path); DatabaseIndexer.IndexFeaturesDrop(NHibernateUtil.Path); var i = 1; foreach (var file in selectedFiles) { // Set range based on file totalProgressData.StepRange((i++ *100.0) / selectedFiles.Count); var fileInstance = file; var progData = new ProgressData(new Progress <ProgressData>(pd => { fileInstance.Progress = pd.Percent; // Report file progress totalProgressData.Report(fileInstance.Progress); })); var progressRpt = new Progress <ProgressData>(pd => progData.Report(pd.Percent)); progData.StepRange(30); IList <UMCLight> features; // Load features from the database. try { this.analysis.DataProviders.DatabaseLock.EnterReadLock(); features = featureCache.LoadDataset( file.Dataset, this.analysis.Options.MsFilteringOptions, this.analysis.Options.LcmsFindingOptions, this.analysis.Options.LcmsFilteringOptions, this.analysis.Options.DataLoadOptions, this.analysis.DataProviders.ScanSummaryProviderCache, this.analysis.DataProviders.IdentificationProviderCache, progressRpt); } finally { // Always close read lock, even during failure condition so we don't have a recursive lock error. this.analysis.DataProviders.DatabaseLock.ExitReadLock(); } if (!this.featuresByDataset.ContainsKey(file.Dataset)) { this.featuresByDataset.Add(file.Dataset, new List <UMCLight>()); } this.featuresByDataset[file.Dataset] = features; file.DatasetState = DatasetInformationViewModel.DatasetStates.PersistingFeatures; ThreadSafeDispatcher.Invoke(() => this.PlotMsFeaturesCommand.RaiseCanExecuteChanged()); // TODO: We were using this log file to track speed changes for writing the database. We probably don't need it anymore. using (var logger = new StreamWriter("nhibernate_stats.txt", true)) { logger.WriteLine(); var stopWatch = new Stopwatch(); stopWatch.Start(); var scanSumProvider = this.analysis.DataProviders.ScanSummaryProviderCache.GetScanSummaryProvider( file.Dataset.DatasetId); if (scanSumProvider.IsBackedByFile) { var ssDao = this.analysis.DataProviders.ScanSummaryDao; ssDao.DeleteByDatasetId(file.Dataset.DatasetId); // Add all of the Scan Summaries for this dataset to the database, but first properly set the dataset ID ssDao.AddAllStateless( scanSumProvider.GetScanSummaries().Select( summ => { summ.DatasetId = file.Dataset.DatasetId; return(summ); }).ToList()); } progData.StepRange(100); // Cache features to database. try { this.analysis.DataProviders.DatabaseLock.EnterWriteLock(); featureCache.CacheFeatures(features, progressRpt); } catch (NonUniqueObjectException ex) { MessageBox.Show("Could not completely persist features: " + ex.Message); } catch (Exception ex) // TODO: Figure out which exception should actually be caught here { MessageBox.Show("Could not persist features to database: " + ex.Message); file.DatasetState = DatasetInformationViewModel.DatasetStates.Loaded; continue; } finally { // Always close write lock, even during failure condition so we don't have a recursive lock error. this.analysis.DataProviders.DatabaseLock.ExitWriteLock(); } stopWatch.Stop(); logger.WriteLine("Writing: {0}s", stopWatch.Elapsed.TotalSeconds); } file.DatasetState = DatasetInformationViewModel.DatasetStates.FeaturesFound; ThreadSafeDispatcher.Invoke(() => this.FindMsFeaturesCommand.RaiseCanExecuteChanged()); file.Progress = 0; } DatabaseIndexer.IndexFeatures(NHibernateUtil.Path); taskBarProgress.ShowProgress(this, false); this.ShouldShowProgress = false; }
/// <summary> /// Load the data from the dataset information objects to the cache at the analysis Path /// </summary> private void PerformDataLoadAndAlignment(AnalysisConfig config) { UmcLoaderFactory.Status += UMCLoaderFactory_Status; UpdateStatus("Loading data."); var analysisOptions = config.Analysis.Options; var datasets = config.Analysis.MetaData.Datasets.ToList(); var lcmsFilterOptions = analysisOptions.LcmsFilteringOptions; var msFilterOptions = analysisOptions.MsFilteringOptions; var dataLoadOptions = analysisOptions.DataLoadOptions; var baselineDataset = config.Analysis.MetaData.BaselineDataset; var baselineFeatures = LoadBaselineData(baselineDataset, msFilterOptions, analysisOptions.LcmsFindingOptions, lcmsFilterOptions, dataLoadOptions, config.Analysis.DataProviders, config.Analysis.MassTagDatabase, config.Analysis.Options.AlignmentOptions.IsAlignmentBaselineAMasstagDB); var alignmentData = new AlignmentDAOHibernate(); alignmentData.ClearAll(); var providers = config.Analysis.DataProviders; var featureCache = new FeatureLoader { Providers = providers }; RegisterProgressNotifier(featureCache); MassTagDatabase database = null; if (config.Analysis.MassTagDatabase != null) { database = new MassTagDatabase(config.Analysis.MassTagDatabase, config.Analysis.Options.AlignmentOptions.MassTagObservationCount); } SingletonDataProviders.Providers = config.Analysis.DataProviders; foreach (var dataset in datasets) { if (dataset.IsBaseline) { continue; } var features = featureCache.LoadDataset(dataset, analysisOptions.MsFilteringOptions, analysisOptions.LcmsFindingOptions, analysisOptions.LcmsFilteringOptions, analysisOptions.DataLoadOptions, m_scanSummaryProviderCache, m_identificationsProvider); features = AlignDataset(features, baselineFeatures, database, dataset, baselineDataset); featureCache.CacheFeatures(features); } UmcLoaderFactory.Status -= UMCLoaderFactory_Status; }