예제 #1
0
 private void OnStatus(string message)
 {
     ThreadSafeDispatcher.Invoke(() =>
     {
         ApplicationStatusMediator.SetStatus(message);
         Status = message;
     });
 }
예제 #2
0
        public void CreateAlignmentPlots(FeaturesAlignedEventArgs e)
        {
            Action workAction = () =>
            {
                BuildAlignmentPlotView(e);
                Reporter.CreateAlignmentPlots(e);
            };

            ThreadSafeDispatcher.Invoke(workAction);
        }
예제 #3
0
        public void CreateMassTagPlot(MassTagsLoadedEventArgs e)
        {
            Action workAction = () =>
            {
                BuildMassTagPlots(e);
                Reporter.CreateMassTagPlot(e);
            };

            ThreadSafeDispatcher.Invoke(workAction);
        }
예제 #4
0
        public void CreateBaselinePlots(BaselineFeaturesLoadedEventArgs e)
        {
            Action workAction = () =>
            {
                BuildBaselineView(e);
                Reporter.CreateBaselinePlots(e);
            };

            ThreadSafeDispatcher.Invoke(workAction);
        }
예제 #5
0
        public void CreateClusterPlots(FeaturesClusteredEventArgs clusters)
        {
            Action workAction = () =>
            {
                BuildClusterPlots(clusters.Clusters);
                Reporter.CreateClusterPlots(clusters);
            };

            ThreadSafeDispatcher.Invoke(workAction);
        }
예제 #6
0
        private void ControllerOnAnalysisStarted(object sender, AnalysisGraphEventArgs analysisGraphEventArgs)
        {
            Action workAction = () =>
            {
                AnalysisNodes.Clear();
                analysisGraphEventArgs.AnalysisGraph.Nodes.ForEach(
                    x => AnalysisNodes.Add(new AnalysisGraphNodeViewModel(x)));
            };

            ThreadSafeDispatcher.Invoke(workAction);
        }
예제 #7
0
        /// <summary>
        /// Cosntructor
        /// </summary>
        /// <param name="analysis"></param>
        /// <param name="datasets"></param>
        /// <param name="msFeatureWindowFactory"></param>
        public FeatureFindingSettingsViewModel(
            MultiAlignAnalysis analysis,
            ObservableCollection <DatasetInformationViewModel> datasets,
            IFeatureWindowFactory msFeatureWindowFactory = null)
        {
            this.analysis = analysis;
            this.Datasets = datasets;
            this.msFeatureWindowFactory = msFeatureWindowFactory ?? new MSFeatureViewFactory();
            this.msFeatureWindowFactory = new MSFeatureViewFactory();
            this.featuresByDataset      = new Dictionary <DatasetInformation, IList <UMCLight> >();
            this.MsFeatureClusterers    = new ObservableCollection <MsFeatureClusteringAlgorithmType>(
                Enum.GetValues(typeof(MsFeatureClusteringAlgorithmType)).Cast <MsFeatureClusteringAlgorithmType>());
            this.LcmsFeatureClusterers = new ObservableCollection <GenericClusteringAlgorithmType>(
                Enum.GetValues(typeof(GenericClusteringAlgorithmType)).Cast <GenericClusteringAlgorithmType>());

            this.CanCreateXics = datasets.Select(dataset => RawLoaderFactory.CreateFileReader(dataset.Dataset.RawFile.Path, dataset.DatasetId))
                                 .Any(reader => reader is ISpectraProvider);

            // When dataset is selected/unselected, update can executes.
            this.MessengerInstance.Register <PropertyChangedMessage <bool> >(this, this.UpdateDatasetSelection);

            // When dataset state changes, update can executes.
            this.MessengerInstance.Register <PropertyChangedMessage <DatasetInformationViewModel.DatasetStates> >(this, args =>
            {
                if (args.Sender is DatasetInformationViewModel && args.PropertyName == "DatasetState")
                {
                    ThreadSafeDispatcher.Invoke(() =>
                    {
                        this.FindMsFeaturesCommand.RaiseCanExecuteChanged();
                        this.PlotMsFeaturesCommand.RaiseCanExecuteChanged();
                        this.PlotAlignedFeaturesCommand.RaiseCanExecuteChanged();
                    });
                }
            });

            this.FindMsFeaturesCommand = new RelayCommand(
                async() => await this.LoadMsFeaturesAsync(),
                () => this.Datasets.Any(ds => ds.IsSelected && !ds.IsFindingFeatures));

            this.PlotMsFeaturesCommand = new RelayCommand(
                async() => await this.PlotMsFeatures(false),
                () => this.Datasets.Any(
                    ds =>
                    ds.DatasetState >
                    DatasetInformationViewModel.DatasetStates.FindingFeatures &&
                    ds.IsSelected));

            this.PlotAlignedFeaturesCommand = new RelayCommand(
                async() => await this.PlotMsFeatures(true),
                () => this.Datasets.Any(ds => ds.IsAligned));

            this.RestoreDefaultsCommand = new RelayCommand(this.RestoreDefaults);
        }
예제 #8
0
        public AnalysisGraphNodeViewModel(AnalysisGraphNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            // This safely updates the UI thread in case the current analysis is running on a separate thread.
            Action update = () => OnPropertyChanged("IsCurrent");

            m_node = node;
            m_node.StatusChanged += (sender, args) => ThreadSafeDispatcher.Invoke(update);
        }
예제 #9
0
        /// <summary>
        ///     Loads the analysis.
        /// </summary>
        /// <param name="recentAnalysis"></param>
        public void LoadAnalysis(RecentAnalysis recentAnalysis)
        {
            if (recentAnalysis == null)
            {
                OnStatus("Cannot open analysis file.");
                return;
            }


            Action loadAnalysis = delegate
            {
                var filename = Path.Combine(recentAnalysis.Path, recentAnalysis.Name);

                OnStatus("Gaining access to the analysis database...");
                var providers = DataAccessFactory.CreateDataAccessProviders(filename, false);
                var analysis  = new MultiAlignAnalysis();
                analysis.MetaData.AnalysisPath      = recentAnalysis.Path;
                analysis.MetaData.AnalysisName      = recentAnalysis.Name;
                analysis.MetaData.AnalysisSetupInfo = null;
                analysis.DataProviders = providers;

                OnStatus("Detecting your clusters...");
                analysis.Clusters = providers.ClusterCache.FindAll();

                OnStatus("Updating your datasets...");
                analysis.MetaData.Datasets = providers.DatasetCache.FindAll().ToObservableCollection();

                OnStatus("Securing mass tags...");
                var provider = new MassTagDatabaseLoaderCache();
                provider.Provider        = analysis.DataProviders.MassTags;
                analysis.MassTagDatabase = provider.LoadDatabase();

                OnStatus("Analysis Loaded...");
                ThreadSafeDispatcher.Invoke(() =>
                {
                    if (AnalysisLoaded != null)
                    {
                        AnalysisLoaded(this, new AnalysisStatusArgs(analysis));
                    }
                });
            };


            m_loadingTask = new Task(loadAnalysis);
            m_loadingTask.Start();
        }
예제 #10
0
        public ClusterSettingsViewModel(
            MultiAlignAnalysis analysis,
            ObservableCollection <DatasetInformationViewModel> datasets,
            IClusterViewFactory clusterViewFactory = null,
            IProgress <int> progressReporter       = null)
        {
            this.progress           = progressReporter ?? new Progress <int>();
            this.analysis           = analysis;
            this.Datasets           = datasets;
            this.options            = analysis.Options;
            this.builder            = new AlgorithmBuilder();
            this.clusterViewFactory = clusterViewFactory ?? new ClusterViewFactory(analysis.DataProviders);

            // When dataset state changes, update can executes.
            this.MessengerInstance.Register <PropertyChangedMessage <DatasetInformationViewModel.DatasetStates> >(this, args =>
            {
                if (args.Sender is DatasetInformationViewModel && args.PropertyName == "DatasetState")
                {
                    ThreadSafeDispatcher.Invoke(() => this.ClusterFeaturesCommand.RaiseCanExecuteChanged());
                    ThreadSafeDispatcher.Invoke(() => this.DisplayClustersCommand.RaiseCanExecuteChanged());
                }
            });

            this.ClusterFeaturesCommand = new RelayCommand(this.AsyncClusterFeatures, () => this.Datasets.Any(ds => ds.FeaturesFound));
            this.DisplayClustersCommand = new RelayCommand(
                async() => await this.DisplayFeatures(),
                () => this.Datasets.Any(ds => ds.IsClustered));

            this.DistanceMetrics = new ObservableCollection <DistanceMetric>();
            Enum.GetValues(typeof(DistanceMetric)).Cast <DistanceMetric>().ToList().ForEach(x => this.DistanceMetrics.Add(x));
            this.CentroidRepresentations = new ObservableCollection <ClusterCentroidRepresentation>
            {
                ClusterCentroidRepresentation.Mean,
                ClusterCentroidRepresentation.Median
            };

            this.ClusteringMethods = new ObservableCollection <LcmsFeatureClusteringAlgorithmType>();
            Enum.GetValues(typeof(LcmsFeatureClusteringAlgorithmType)).Cast <LcmsFeatureClusteringAlgorithmType>().ToList().ForEach(x => this.ClusteringMethods.Add(x));

            this.PostProcessingComparisonType = new ObservableCollection <ClusterPostProcessingOptions.ClusterComparisonType>(
                Enum.GetValues(typeof(ClusterPostProcessingOptions.ClusterComparisonType)).Cast <ClusterPostProcessingOptions.ClusterComparisonType>());
        }
예제 #11
0
        private void LoadFeatures()
        {
            this.featureCache.Providers = this.analysis.DataProviders;
            var selectedFiles = selectedDatasets;

            foreach (var file in selectedFiles.Where(file => !file.DoingWork)) // Do not try to run on files already loading features.
            {
                file.DoingWork = true;
                ThreadSafeDispatcher.Invoke(() => PlotMSFeaturesCommand.RaiseCanExecuteChanged());
                ThreadSafeDispatcher.Invoke(() => FindMSFeaturesCommand.RaiseCanExecuteChanged());
                var features = this.featureCache.LoadDataset(file, this.analysis.Options.MsFilteringOptions, this.analysis.Options.LcmsFindingOptions, this.analysis.Options.LcmsFilteringOptions);
                this.featureCache.CacheFeatures(features);

                file.FeaturesFound = true;
                progress.Report(0);

                file.DoingWork = false;
                ThreadSafeDispatcher.Invoke(() => PlotMSFeaturesCommand.RaiseCanExecuteChanged());
                ThreadSafeDispatcher.Invoke(() => FindMSFeaturesCommand.RaiseCanExecuteChanged());
            }
        }
예제 #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StacSettingsViewModel"/> class.
        /// </summary>
        /// <param name="analysis">The analysis information to run matching on.</param>
        /// <param name="datasets">All possible datasets to run AMT tag matching on.</param>
        public StacSettingsViewModel(MultiAlignAnalysis analysis, ObservableCollection <DatasetInformationViewModel> datasets)
        {
            this.analysis = analysis;
            this.datasets = datasets;
            this.DatabaseSelectionViewModel = DatabaseSelectionViewModel.Instance;
            this.PeakMatchingTypes          = new ObservableCollection <PeakMatchingType>(
                Enum.GetValues(typeof(PeakMatchingType))
                .Cast <PeakMatchingType>());

            // When a dataset's state changes, update the CanExecute of the PerformMatchingCommand.
            MessengerInstance.Register <PropertyChangedMessage <DatasetInformationViewModel.DatasetStates> >(
                this,
                args =>
            {
                if (args.Sender is DatasetInformationViewModel && args.PropertyName == "DatasetState")
                {
                    ThreadSafeDispatcher.Invoke(this.PerformMatchingCommand.RaiseCanExecuteChanged);
                }
            });

            // When a dataset is selected/unselected, update the CanExecute of the PerformMatchingCommand.
            MessengerInstance.Register <PropertyChangedMessage <bool> >(
                this,
                args =>
            {
                if (args.Sender is DatasetInformationViewModel && args.PropertyName == "IsSelected")
                {
                    ThreadSafeDispatcher.Invoke(this.PerformMatchingCommand.RaiseCanExecuteChanged);
                }
            });

            // Perform matching on datasets that have cluster info available, and are not
            // currently being run.
            this.PerformMatchingCommand = new RelayCommand(
                async() => await this.PerformMatchingAsync(
                    this.datasets.Where(ds => ds.IsClustered)
                    .Where(ds => !ds.DoingWork)),
                () => this.datasets.Any(ds => ds.IsClustered && !ds.DoingWork));
        }
예제 #13
0
        private void AnalysisEnded(string reason, bool isCancelled, bool isComplete)
        {
            Action workAction = delegate
            {
                IsAnalysisRunning = false;
                ApplicationStatusMediator.SetStatus(reason);

                Controller.AnalysisComplete  -= Controller_AnalysisComplete;
                Controller.AnalysisError     -= Controller_AnalysisError;
                Controller.AnalysisCancelled -= Controller_AnalysisCancelled;

                if (isComplete)
                {
                    if (AnalysisComplete != null)
                    {
                        AnalysisComplete(this, new AnalysisStatusArgs(m_configuration));
                    }
                    return;
                }
                if (!isCancelled)
                {
                    if (AnalysisComplete != null)
                    {
                        AnalysisComplete(this, new AnalysisStatusArgs(m_configuration));
                    }
                }
                else
                {
                    if (AnalysisCancelled != null)
                    {
                        AnalysisCancelled(this, new AnalysisStatusArgs(m_configuration));
                    }
                }
            };

            ThreadSafeDispatcher.Invoke(workAction);
        }
예제 #14
0
        /// <summary>
        /// Copy files from DMS dataset folder to output directory.
        /// </summary>
        /// <returns>Task for awaiting file copy.</returns>
        public async Task CopyFilesAsync()
        {
            this.cancellationTokenSource = new CancellationTokenSource();
            await Task.Run(
                () =>
            {
                if (!Directory.Exists(this.OutputDirectory))
                {
                    return;
                }

                ThreadSafeDispatcher.Invoke(() => this.IsCopying = true);
                this.Progress = 0;

                var files = this.Datasets.Where(ds => ds.Selected).SelectMany(ds => ds.GetAvailableFiles()).ToArray();

                for (int i = 0; i < files.Length; i++)
                {
                    if (this.cancellationTokenSource.IsCancellationRequested)
                    {
                        break;
                    }

                    var fileName        = Path.GetFileName(files[i]);
                    this.CopyStatusText = string.Format("Copying {0}", fileName);
                    File.Copy(files[i], string.Format("{0}\\{1}", this.OutputDirectory, fileName), true);

                    this.Progress = ((i + 1) / (double)files.Length) * 100;
                }

                this.CopyStatusText = string.Empty;
                ThreadSafeDispatcher.Invoke(() => this.IsCopying = false);
                this.Progress = 100;
            },
                this.cancellationTokenSource.Token);
        }
예제 #15
0
        public void CreatePlotReport()
        {
            Action workAction = () => Reporter.CreatePlotReport();

            ThreadSafeDispatcher.Invoke(workAction);
        }
예제 #16
0
        /// <summary>
        ///     Updates the current messages windows.
        /// </summary>
        private void Logger_Status(object sender, StatusEventArgs e)
        {
            Action workAction = () => Messages.Insert(0, e);

            ThreadSafeDispatcher.Invoke(workAction);
        }
예제 #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AlignmentSettingsViewModel"/> class.
        /// </summary>
        /// <param name="analysis">The analysis information to run alignment on.</param>
        /// <param name="datasets">List of all potential datasets to run alignment on.</param>
        /// <param name="alignmentWindowFactory">
        /// Factory for creating windows related to alignment (such as alignment plot windows).
        /// </param>
        public AlignmentSettingsViewModel(MultiAlignAnalysis analysis,
                                          ObservableCollection <DatasetInformationViewModel> datasets,
                                          IAlignmentWindowFactory alignmentWindowFactory = null)
        {
            this.analysis = analysis;
            this.Datasets = datasets;
            if (analysis.MetaData.BaselineDataset != null)
            {
                // Don't set baseline if there are no files to choose from yet
                this.selectedBaseline = datasets.First(x => x.Name == analysis.MetaData.BaselineDataset.DatasetName);
            }

            this.alignmentWindowFactory = alignmentWindowFactory ?? new AlignmentViewFactory();
            this.aligner             = new LCMSFeatureAligner();
            this.builder             = new AlgorithmBuilder();
            this.CalibrationOptions  = new ObservableCollection <LcmsWarpAlignmentType>(Enum.GetValues(typeof(LcmsWarpAlignmentType)).Cast <LcmsWarpAlignmentType>());
            this.AlignmentAlgorithms = new ObservableCollection <FeatureAlignmentType>(
                Enum.GetValues(typeof(FeatureAlignmentType)).Cast <FeatureAlignmentType>());
            this.alignmentInformation = new List <AlignmentData>();

            this.DatabaseSelectionViewModel = DatabaseSelectionViewModel.Instance;

            // When dataset is selected/unselected, update CanExecutes for alignment and plotting commands.
            this.MessengerInstance.Register <PropertyChangedMessage <bool> >(
                this,
                args =>
            {
                if (args.Sender is DatasetInformationViewModel && args.PropertyName == "IsSelected")
                {
                    ThreadSafeDispatcher.Invoke(() => this.AlignCommand.RaiseCanExecuteChanged());
                    ThreadSafeDispatcher.Invoke(() => this.DisplayAlignmentCommand.RaiseCanExecuteChanged());
                    ThreadSafeDispatcher.Invoke(() => this.SaveAlignmentPlotsCommand.RaiseCanExecuteChanged());
                }
            });

            // When dataset state changes, update CanExecutes for alignment and plotting commands.
            this.MessengerInstance.Register <PropertyChangedMessage <DatasetInformationViewModel.DatasetStates> >(
                this,
                args =>
            {
                if (args.Sender is DatasetInformationViewModel && args.PropertyName == "DatasetState")
                {
                    ThreadSafeDispatcher.Invoke(() => this.AlignCommand.RaiseCanExecuteChanged());
                    ThreadSafeDispatcher.Invoke(() => this.DisplayAlignmentCommand.RaiseCanExecuteChanged());
                    ThreadSafeDispatcher.Invoke(() => this.SaveAlignmentPlotsCommand.RaiseCanExecuteChanged());
                }
            });

            // When database server is selected, update CanExecute for the alignment command.
            this.MessengerInstance.Register <PropertyChangedMessage <DmsDatabaseServerViewModel> >(
                this,
                args =>
            {
                if (args.Sender is DatabaseSelectionViewModel && args.PropertyName == "SelectedDatabase")
                {
                    ThreadSafeDispatcher.Invoke(() => this.AlignCommand.RaiseCanExecuteChanged());
                }
            });

            this.AlignCommand = new RelayCommand(this.AsyncAlign, this.CanAlign);

            // Executable if the selected files are aligned and alignment information is available.
            this.DisplayAlignmentCommand = new RelayCommand(
                this.DisplayAlignment,
                () => this.Datasets.Any(file => file.IsAligned && file.IsSelected &&
                                        this.alignmentInformation.Any(data => data.DatasetID == file.DatasetId)));

            // Executable if the selected files are aligned and alignment information is available.
            this.SaveAlignmentPlotsCommand = new RelayCommand(
                this.SaveAlignmentPlots,
                () => this.Datasets.Any(file => file.IsAligned && file.IsSelected &&
                                        this.alignmentInformation.Any(data => data.DatasetID == file.DatasetId)));

            this.RestoreDefaultsCommand = new RelayCommand(this.RestoreDefaults);
        }
예제 #18
0
        public void CreateChargePlots(Dictionary <int, int> chargeMap)
        {
            Action workAction = () => Reporter.CreateChargePlots(chargeMap);

            ThreadSafeDispatcher.Invoke(workAction);
        }
예제 #19
0
        public void CreatePeakMatchedPlots(FeaturesPeakMatchedEventArgs e)
        {
            Action workAction = () => Reporter.CreatePeakMatchedPlots(e);

            ThreadSafeDispatcher.Invoke(workAction);
        }
예제 #20
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;
        }
예제 #21
0
        internal void ClusterFeatures(IProgress <ProgressData> workflowProgress = null)
        {
            var taskBarProgress = TaskBarProgress.GetInstance();

            taskBarProgress.ShowProgress(this, true);
            workflowProgress = workflowProgress ?? new Progress <ProgressData>();
            IProgress <ProgressData> internalProgress = new Progress <ProgressData>(pd =>
            {
                this.progress.Report((int)pd.Percent);
                this.ProgressPercent = pd.Percent;
                taskBarProgress.SetProgress(this, pd.Percent);
                workflowProgress.Report(pd);
            });

            this.algorithms = this.builder.GetAlgorithmProvider(this.options);
            var clusterer = this.algorithms.Clusterer;

            clusterer.Parameters = LcmsClusteringOptions.ConvertToOmics(this.options.LcmsClusteringOptions);
            this.featureCache    = this.analysis.DataProviders.FeatureCache;
            if (clusterer is PromexClusterer)
            {
                var promexClusterer = clusterer as PromexClusterer;
                promexClusterer.Readers = this.analysis.DataProviders.ScanSummaryProviderCache;
            }

            foreach (var dataset in this.Datasets)
            {
                if (dataset.FeaturesFound)
                {
                    dataset.DatasetState = DatasetInformationViewModel.DatasetStates.Clustering;
                }
            }

            ThreadSafeDispatcher.Invoke(this.ClusterFeaturesCommand.RaiseCanExecuteChanged);
            ThreadSafeDispatcher.Invoke(this.DisplayClustersCommand.RaiseCanExecuteChanged);

            this.ShouldShowProgress = true;
            var progData        = new ProgressData(internalProgress);
            var clusterProgress = new Progress <ProgressData>(pd => progData.Report(pd.Percent));

            this.analysis.DataProviders.DatabaseLock.EnterWriteLock();
            DatabaseIndexer.IndexClustersDrop(NHibernateUtil.Path);
            this.analysis.DataProviders.ClusterCache.ClearAllClusters();
            this.analysis.DataProviders.DatabaseLock.ExitWriteLock();

            // The id for a cluster - keep track here to avoid duplicates when separating by charge.
            var clusterCount = 0;

            // Here we see if we need to separate the charge...
            // IMS is said to require charge separation
            if (!this.analysis.Options.LcmsClusteringOptions.ShouldSeparateCharge)
            {
                progData.StepRange(45);
                var features = new List <UMCLight>();
                var i        = 0;
                var datasets = this.Datasets.Where(ds => ds.FeaturesFound).ToList();
                foreach (var dataset in datasets)
                {
                    this.analysis.DataProviders.DatabaseLock.EnterReadLock();
                    features.AddRange(this.featureCache.FindByDatasetId(dataset.DatasetId));
                    this.analysis.DataProviders.DatabaseLock.ExitReadLock();
                    progData.Report(++i, datasets.Count);
                }

                progData.StepRange(100);
                ClusterGroupOfFeatures(clusterer, features, ref clusterCount, clusterProgress);
            }
            else
            {
                var maxChargeState = this.featureCache.FindMaxCharge();

                // Here we cluster all charge states separately.  Probably IMS Data.
                for (var chargeState = 1; chargeState <= maxChargeState; chargeState++)
                {
                    var maxPercent = ((100.0 * chargeState) / maxChargeState);
                    // TODO: Add restriction by selected dataset ids?
                    var features = this.featureCache.FindByCharge(chargeState);
                    if (features.Count < 1)
                    {
                        continue;
                    }

                    progData.StepRange(maxPercent);
                    ClusterGroupOfFeatures(clusterer, features, ref clusterCount, clusterProgress);
                }

                this.analysis.Clusters = this.analysis.DataProviders.ClusterCache.FindAll();
            }

            this.analysis.DataProviders.DatabaseLock.EnterWriteLock();
            DatabaseIndexer.IndexClusters(NHibernateUtil.Path);
            this.analysis.DataProviders.DatabaseLock.ExitWriteLock();

            foreach (var dataset in this.Datasets)
            {
                if (dataset.DatasetState == DatasetInformationViewModel.DatasetStates.PersistingClusters)
                {
                    dataset.DatasetState = DatasetInformationViewModel.DatasetStates.Clustered;
                }
            }

            try
            {
                // Write to file
                this.WriteClusterData(string.Format("{0}_crosstab.tsv", this.analysis.AnalysisName), this.analysis.Clusters);
            }
            catch (Exception ex)
            {
                var errMsg = "Error writing results to text file: " + ex.Message;
                Logger.PrintMessage(errMsg);

                // Todo: Add this: if (!GlobalSettings.AutomatedAnalysisMode)
                MessageBox.Show(errMsg);
            }

            ThreadSafeDispatcher.Invoke(this.ClusterFeaturesCommand.RaiseCanExecuteChanged);
            ThreadSafeDispatcher.Invoke(this.DisplayClustersCommand.RaiseCanExecuteChanged);

            taskBarProgress.ShowProgress(this, false);
            this.ShouldShowProgress = false;
        }
예제 #22
0
        internal void ClusterGroupOfFeatures(IClusterer <UMCLight, UMCClusterLight> clusterer, List <UMCLight> features, ref int clusterCount, IProgress <ProgressData> internalProgress = null)
        {
            var progData        = new ProgressData(internalProgress);
            var clusterProgress = new Progress <ProgressData>(pd => progData.Report(pd.Percent));

            if (this.ShouldRefineWithMsMs)
            {
                progData.StepRange(35);
            }
            else
            {
                progData.StepRange(70);
            }

            var clusters = clusterer.Cluster(features, clusterProgress);

            foreach (var cluster in clusters)
            {
                cluster.Id = clusterCount++;
                cluster.UmcList.ForEach(x => x.ClusterId = cluster.Id);

                // Updates the cluster with statistics
                foreach (var feature in cluster.UmcList)
                {
                    cluster.MsMsCount += feature.MsMsCount;
                    cluster.IdentifiedSpectraCount += feature.IdentifiedSpectraCount;
                }
            }

            if (this.ShouldRefineWithMsMs)
            {
                try
                {
                    progData.StepRange(70);
                    var clusterRefiner =
                        ClusterPostProcessorBuilder.GetClusterPostProcessor <UMCClusterLight, UMCLight>(
                            this.analysis.Options.ClusterPostProcessingoptions,
                            this.analysis.DataProviders);
                    clusters = clusterRefiner.Cluster(clusters, clusterProgress);
                }
                catch (DatasetInformation.MissingRawDataException e)
                {
                    MessageBox.Show(string.Format("{0}\nDataset: {1}", e.Message, e.GroupId));
                }
            }

            this.analysis.Clusters            = clusters;
            clusters.ForEach(c => c.Abundance = c.UmcList.Sum(umc => umc.AbundanceSum));

            foreach (var dataset in this.Datasets)
            {
                if (dataset.DatasetState == DatasetInformationViewModel.DatasetStates.Clustering)
                {
                    dataset.DatasetState = DatasetInformationViewModel.DatasetStates.PersistingClusters;
                }
            }

            ThreadSafeDispatcher.Invoke(this.ClusterFeaturesCommand.RaiseCanExecuteChanged);
            ThreadSafeDispatcher.Invoke(this.DisplayClustersCommand.RaiseCanExecuteChanged);

            this.analysis.DataProviders.DatabaseLock.EnterWriteLock();
            progData.StepRange(85);
            this.analysis.DataProviders.ClusterCache.AddAllStateless(clusters, clusterProgress);

            progData.StepRange(100);
            this.analysis.DataProviders.FeatureCache.UpdateAll(features, clusterProgress);
            this.analysis.DataProviders.DatabaseLock.ExitWriteLock();
        }
예제 #23
0
        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;
        }