Ejemplo n.º 1
0
        /// <summary>
        ///     Aligns all of the datasets.
        /// </summary>
        public void PerformAlignment(AnalysisConfig config)
        {
            UpdateStatus("Performing Alignment");

            // Connect to database of features.
            var featureCache = config.Analysis.DataProviders.FeatureCache;

            var options = config.Analysis.Options;

            // Load the baseline data.
            var baselineInfo     = config.Analysis.MetaData.BaselineDataset;
            var baselineFeatures = LoadBaselineData(baselineInfo,
                                                    options.MsFilteringOptions,
                                                    options.LcmsFindingOptions,
                                                    options.LcmsFilteringOptions,
                                                    options.DataLoadOptions,
                                                    config.Analysis.DataProviders,
                                                    config.Analysis.MassTagDatabase,
                                                    config.Analysis.Options.AlignmentOptions.IsAlignmentBaselineAMasstagDB);

            // Create the alignment cache and clear it.
            var alignmentCache = new AlignmentDAOHibernate();

            alignmentCache.ClearAll();


            //config.Analysis.Options.AlignmentOptions

            foreach (var datasetInfo in config.Analysis.MetaData.Datasets)
            {
                if (!datasetInfo.IsBaseline)
                {
                    UpdateStatus("Retrieving data from " + datasetInfo.DatasetName + " for alignment.");
                    var features = featureCache.FindByDatasetId(datasetInfo.DatasetId) as IList <UMCLight>;
                    features = AlignDataset(features,
                                            baselineFeatures,
                                            config.Analysis.MassTagDatabase,
                                            datasetInfo,
                                            baselineInfo);
                    featureCache.UpdateAllStateless(features);

                    // This dataset is done!
                    if (FeaturesLoaded != null)
                    {
                        FeaturesLoaded(this, new FeaturesLoadedEventArgs(datasetInfo, features));
                    }
                }
                else
                {
                    config.Analysis.AlignmentData.Add(null);
                }
            }
        }
Ejemplo n.º 2
0
        private void AlignToBaseline()
        {
            if (this.SelectedBaseline != null && this.SelectedBaseline.Dataset.FeaturesFound)
            {
                //Update algorithms and providers
                this.featureCache.Providers = this.analysis.DataProviders;
                this.algorithms = this.builder.GetAlgorithmProvider(this.analysis.Options);
                this.aligner.m_algorithms = this.algorithms;

                var baselineFeatures = this.featureCache.LoadDataset(this.selectedBaseline.Dataset, this.analysis.Options.MsFilteringOptions,
                    this.analysis.Options.LcmsFindingOptions, this.analysis.Options.LcmsFilteringOptions);
                var alignmentData = new AlignmentDAOHibernate();
                alignmentData.ClearAll();

                this.SelectedBaseline.IsAligning = true;
                var selectedFiles = this.selectedDatasets.Where(file => !file.DoingWork).ToList();
                foreach (var file in selectedFiles)
                {
                    file.IsAligning = true;
                }

                foreach (var file in selectedFiles)
                {
                    ThreadSafeDispatcher.Invoke(() => this.AlignToBaselineCommand.RaiseCanExecuteChanged());
                    ThreadSafeDispatcher.Invoke(() => this.DisplayAlignmentCommand.RaiseCanExecuteChanged());
                    if (file.Dataset.IsBaseline || !file.FeaturesFound)
                    {
                        file.IsAligned = true;
                        file.IsAligning = false;
                        continue;
                    }
                    var features = this.featureCache.LoadDataset(file.Dataset, this.analysis.Options.MsFilteringOptions,
                        this.analysis.Options.LcmsFindingOptions, this.analysis.Options.LcmsFilteringOptions);
                    var alignment = this.aligner.AlignToDataset(ref features, baselineFeatures, file.Dataset, this.selectedBaseline.Dataset);
                    //Check if there is information from a previous alignment for this dataset. If so, replace it. If not, just add the new one.
                    var priorAlignment = from x in this.alignmentInformation where x.DatasetID == alignment.DatasetID select x;
                    if (priorAlignment.Any())
                    {
                        this.alignmentInformation.Remove(priorAlignment.Single());
                        this.alignmentInformation.Add(alignment);
                    }
                    else
                    {
                        this.alignmentInformation.Add(alignment);
                    }

                    this.featureCache.CacheFeatures(features);
                    file.IsAligned = true;
                    file.IsAligning = false;
                    ThreadSafeDispatcher.Invoke(() => this.AlignToBaselineCommand.RaiseCanExecuteChanged());
                    ThreadSafeDispatcher.Invoke(() => this.DisplayAlignmentCommand.RaiseCanExecuteChanged());
                }

                this.SelectedBaseline.IsAligning = false;
            }
            else
            {
                MessageBox.Show("Please select a baseline with detected features.");
            }
        }
        /// <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 baselineDataset = config.Analysis.MetaData.BaselineDataset;
            var baselineFeatures = LoadBaselineData(baselineDataset,
                msFilterOptions,
                analysisOptions.LcmsFindingOptions,
                lcmsFilterOptions,
                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);
                features = AlignDataset(features,
                    baselineFeatures,
                    database,
                    dataset,
                    baselineDataset);
                featureCache.CacheFeatures(features);
            }
            UmcLoaderFactory.Status -= UMCLoaderFactory_Status;
        }
        /// <summary>
        ///     Aligns all of the datasets.
        /// </summary>
        public void PerformAlignment(AnalysisConfig config)
        {
            UpdateStatus("Performing Alignment");

            // Connect to database of features.
            var featureCache = config.Analysis.DataProviders.FeatureCache;

            var options = config.Analysis.Options;

            // Load the baseline data.
            var baselineInfo = config.Analysis.MetaData.BaselineDataset;
            var baselineFeatures = LoadBaselineData(baselineInfo,
                options.MsFilteringOptions,
                options.LcmsFindingOptions,
                options.LcmsFilteringOptions,
                config.Analysis.DataProviders,
                config.Analysis.MassTagDatabase,
                config.Analysis.Options.AlignmentOptions.IsAlignmentBaselineAMasstagDB);

            // Create the alignment cache and clear it.
            var alignmentCache = new AlignmentDAOHibernate();
            alignmentCache.ClearAll();

            //config.Analysis.Options.AlignmentOptions

            foreach (var datasetInfo in config.Analysis.MetaData.Datasets)
            {
                if (!datasetInfo.IsBaseline)
                {
                    UpdateStatus("Retrieving data from " + datasetInfo.DatasetName + " for alignment.");
                    var features = featureCache.FindByDatasetId(datasetInfo.DatasetId) as IList<UMCLight>;
                    features = AlignDataset(features,
                        baselineFeatures,
                        config.Analysis.MassTagDatabase,
                        datasetInfo,
                        baselineInfo);
                    featureCache.UpdateAll(features);

                    // This dataset is done!
                    if (FeaturesLoaded != null)
                        FeaturesLoaded(this, new FeaturesLoadedEventArgs(datasetInfo, features));
                }
                else
                {
                    config.Analysis.AlignmentData.Add(null);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Perform alignment.
        /// </summary>
        /// <param name="workFlowDatasets">Datasets to run on when being called externally form this view model.</param>
        /// <param name="workflowProgress">The progress reporter for when this method is called externally from this view model.</param>
        internal void AlignToBaseline(List <DatasetInformationViewModel> workFlowDatasets = null, IProgress <ProgressData> workflowProgress = null)
        {
            // Use Promiscuous points when aligning to an AMT tag database
            // Do not use Promiscuous points when aligning to a baseline dataset
            this.analysis.Options.AlignmentOptions.UsePromiscuousPoints = !this.ShouldAlignToBaseline;

            // Flag whether we are aligning to an AMT tag database
            this.analysis.Options.AlignmentOptions.LCMSWarpOptions.AlignToMassTagDatabase = !this.ShouldAlignToBaseline;

            // Show the progress bar
            this.ShowAlignmentProgress = true;
            var taskBarProgress = TaskBarProgress.GetInstance();

            taskBarProgress.ShowProgress(this, true);

            // Update algorithms and providers
            var featureCache = new FeatureLoader {
                Providers = this.analysis.DataProviders
            };

            this.algorithms = this.builder.GetAlgorithmProvider(this.analysis.Options);

            ////this.algorithms.DatabaseAligner.Progress += aligner_Progress;
            ////this.algorithms.DatasetAligner.Progress += aligner_Progress;

            this.aligner.m_algorithms = this.algorithms;
            var baselineFeatures = new List <UMCLight>();

            if (this.ShouldAlignToBaseline)
            {
                baselineFeatures = featureCache.Providers.FeatureCache.FindByDatasetId(this.selectedBaseline.DatasetId);
                this.SelectedBaseline.DatasetState = DatasetInformationViewModel.DatasetStates.Baseline;
                var priorAlignment = (from x in this.alignmentInformation where x.DatasetID == this.selectedBaseline.DatasetId select x).ToList();
                if (priorAlignment.Any())
                {
                    this.alignmentInformation.Remove(priorAlignment.Single());
                }
            }
            var alignmentData = new AlignmentDAOHibernate();

            alignmentData.ClearAll();

            var selectedFiles = workFlowDatasets ??
                                this.Datasets.Where(file => file.IsSelected && !file.DoingWork &&
                                                    (this.ShouldAlignToAMT || !file.IsBaseline)).ToList();

            foreach (var file in selectedFiles)
            {
                file.DatasetState = DatasetInformationViewModel.DatasetStates.Aligning;
            }

            workflowProgress = workflowProgress ?? new Progress <ProgressData>();
            IProgress <ProgressData> totalProgress = new Progress <ProgressData>(pd =>
            {
                this.AlignmentProgress = pd.Percent;
                workflowProgress.Report(pd);
                taskBarProgress.SetProgress(this, pd.Percent);
            });
            var totalProgressData = new ProgressData(totalProgress);

            DatabaseIndexer.IndexClustersDrop(NHibernateUtil.Path);
            DatabaseIndexer.IndexFeaturesDrop(NHibernateUtil.Path);

            var i = 1;

            foreach (var file in selectedFiles)
            {
                ThreadSafeDispatcher.Invoke(() => this.AlignCommand.RaiseCanExecuteChanged());
                ThreadSafeDispatcher.Invoke(() => this.DisplayAlignmentCommand.RaiseCanExecuteChanged());
                ThreadSafeDispatcher.Invoke(() => this.SaveAlignmentPlotsCommand.RaiseCanExecuteChanged());
                if ((file.Dataset.IsBaseline || !file.FeaturesFound) && this.ShouldAlignToBaseline)
                {
                    file.DatasetState = DatasetInformationViewModel.DatasetStates.Aligned;
                    continue;
                }

                this.analysis.DataProviders.DatabaseLock.EnterReadLock();
                IList <UMCLight> features = featureCache.Providers.FeatureCache.FindByDatasetId(file.DatasetId);
                this.analysis.DataProviders.DatabaseLock.ExitReadLock();
                AlignmentData alignment;

                totalProgressData.StepRange((100.0 * i++) / selectedFiles.Count);

                var fileInstance    = file;
                var datasetProgress =
                    new Progress <ProgressData>(
                        pd =>
                {
                    fileInstance.Progress = pd.Percent;
                    totalProgressData.Report(pd.Percent);
                });

                if (this.ShouldAlignToBaseline)
                {
                    // Aligning to a baseline dataset
                    alignment = this.aligner.AlignToDataset(ref features, file.Dataset, baselineFeatures, datasetProgress);
                    alignment.BaselineIsAmtDB = false;
                }
                else
                {
                    // Aligning to a database
                    alignment = this.aligner.AlignToDatabase(ref features, file.Dataset, this.analysis.MassTagDatabase, datasetProgress);
                    alignment.BaselineIsAmtDB = true;
                }

                // Check if there is information from a previous alignment for this dataset. If so, replace it. If not, just add the new one.
                var priorAlignment = this.alignmentInformation.Where(x => x.DatasetID == alignment.DatasetID).ToList();
                if (priorAlignment.Any())
                {
                    this.alignmentInformation.Remove(priorAlignment.Single());
                    this.alignmentInformation.Add(alignment);
                }
                else
                {
                    this.alignmentInformation.Add(alignment);
                }
                file.Dataset.AlignmentData = alignment;

                this.analysis.DataProviders.DatabaseLock.EnterWriteLock();
                featureCache.CacheFeatures(features);
                this.analysis.DataProviders.DatabaseLock.ExitWriteLock();
                file.DatasetState = DatasetInformationViewModel.DatasetStates.Aligned;
                ThreadSafeDispatcher.Invoke(() => this.AlignCommand.RaiseCanExecuteChanged());
                ThreadSafeDispatcher.Invoke(() => this.DisplayAlignmentCommand.RaiseCanExecuteChanged());
                ThreadSafeDispatcher.Invoke(() => this.SaveAlignmentPlotsCommand.RaiseCanExecuteChanged());
                file.Progress = 0;
            }

            if (this.ShouldAlignToBaseline)
            {
                this.SelectedBaseline.DatasetState = DatasetInformationViewModel.DatasetStates.Aligned;
            }

            DatabaseIndexer.IndexFeatures(NHibernateUtil.Path);

            taskBarProgress.ShowProgress(this, false);
            this.ShowAlignmentProgress = false;
            this.AlignmentProgress     = 0;
        }
Ejemplo n.º 6
0
        /// <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;
        }