示例#1
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>());
        }
示例#2
0
        /// <summary>
        /// Load a project
        /// </summary>
        /// <param name="isNewProject">If the project is a new one</param>
        /// <param name="datasets">Datasets to add to the project, if it is a new project.</param>
        /// <returns></returns>
        private async Task LoadRogueProject(bool isNewProject, List <DatasetInformation> datasets = null)
        {
            Directory.SetCurrentDirectory(this.outputDirectory);
            this.Analysis = new MultiAlignAnalysis
            {
                DataProviders = this.SetupDataProviders(this.ProjectPath, isNewProject),
            };

            var fileName = Path.GetFileNameWithoutExtension(this.projectPath);

            this.Analysis.AnalysisName = fileName;
            this.WindowTitle           = string.Format("MultiAlign Rogue ({0})", fileName);

            this.deletedDatasets.Clear();
            var dbOptions = this.Analysis.DataProviders.OptionsDao.FindAll();

            this.Analysis.Options = OptionsTransformer.ListToProperties(dbOptions);

            if (datasets != null)
            {
                this.analysis.MetaData.Datasets.AddRange(datasets);
            }

            //Prevent updates of ViewModels (that we will recreate anyway) while loading datasets
            this.clusterViewFactory              = null;
            this.DataLoadingSettingsViewModel    = null;
            this.FeatureFindingSettingsViewModel = null;
            this.AlignmentSettingsViewModel      = null;
            this.StacSettingsViewModel           = null;

            var dbDatasets = this.Analysis.DataProviders.DatasetCache.FindAll();

            // Resolve the relative paths
            if (!string.IsNullOrWhiteSpace(this.projectDirectory))
            {
                foreach (var dataset in dbDatasets)
                {
                    foreach (var file in dataset.InputFiles)
                    {
                        if (!string.IsNullOrWhiteSpace(file.RelativePath))
                        {
                            var combined = Path.Combine(this.projectDirectory, file.RelativePath);
                            var cleaned  = Path.GetFullPath(combined);
                            if (File.Exists(cleaned))
                            {
                                file.Path = cleaned;
                            }
                        }
                        // TODO: show warning if file cannot be found.
                        // TODO: OR disable redo of step that needs specified file, if file is only needed for e.g. feature finding
                    }
                }
            }
            this.Analysis.MetaData.Datasets.AddRange(dbDatasets);

            this.Analysis.MetaData.BaselineDataset = this.Analysis.MetaData.Datasets.FirstOrDefault(ds => ds.IsBaseline);

            this.analysisConfig.AnalysisPath = this.ProjectPath;
            await this.UpdateDatasets();

            this.clusterViewFactory = new ClusterViewFactory(this.Analysis.DataProviders);

            this.DataLoadingSettingsViewModel            = new DataLoadingSettingsViewModel(this.Analysis);
            this.FeatureFindingSettingsViewModel         = new FeatureFindingSettingsViewModel(this.Analysis, this.Datasets);
            this.AlignmentSettingsViewModel              = new AlignmentSettingsViewModel(this.Analysis, this.Datasets);
            this.StacSettingsViewModel                   = new StacSettingsViewModel(this.Analysis, this.Datasets);
            DatabaseSelectionViewModel.Instance.Analysis = this.Analysis;
            if (this.Analysis.Options.AlignmentOptions.InputDatabase != null)
            {
                await DatabaseSelectionViewModel.Instance.LoadMassTagDatabase(this.Analysis.Options.AlignmentOptions.InputDatabase);
            }

            this.ClusterSettingsViewModel = new ClusterSettingsViewModel(this.Analysis, this.Datasets, this.clusterViewFactory);
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClusterViewModel"/> class.
        /// </summary>
        /// <param name="viewFactory">Factory for creating child windows.</param>
        /// <param name="matches">The clusters.</param>
        /// <param name="providers">Database access provider</param>
        /// <param name="rawProvider">Provider for LCMSRun for access to PBF files.</param>
        public ClusterViewModel(IClusterViewFactory viewFactory, List <ClusterMatch> matches, FeatureDataAccessProviders providers, ScanSummaryProviderCache rawProvider)
        {
            this.viewFactory                 = viewFactory;
            this.providers                   = providers;
            this.dbLock                      = new object();
            this.throttler                   = new Throttler(TimeSpan.FromMilliseconds(500));
            this.XicPlotViewModel            = new XicPlotViewModel(rawProvider);
            this.ClusterFeaturePlotViewModel = new ClusterFeaturePlotViewModel();
            this.Matches                     = new ObservableCollection <ClusterMatch>(matches ?? new List <ClusterMatch>());
            var clusters = this.Matches.Select(match => match.Cluster).ToList();

            this.rawProvider = rawProvider;

            this.SettingsCommand = new RelayCommand(() => this.viewFactory.CreateSettingsWindow(this.ClusterPlotViewModel.ClusterViewerSettings));

            this.Features    = new ObservableCollection <UMCLightViewModel>();
            this.MsMsSpectra = new ObservableCollection <MSSpectra>();

            this.ClusterPlotViewModel = new ClusterPlotViewModel(clusters);

            this.ShowChargeStateDistributionCommand = new RelayCommand(this.ShowChargeStateDistributionImpl);
            this.ShowDatasetHistogramCommand        = new RelayCommand(this.ShowDatasetHistogramImpl);

            this.layoutUpdated    = false;
            this.originalSettings = new ClusterViewerSettings();

            // Set up standard layout path
            var assemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

            if (!string.IsNullOrEmpty(assemblyPath))
            {
                this.standardLayoutFilePath = Path.Combine(assemblyPath, StandardLayoutFileName);
            }

            // Listen for changes in selected cluster in ClusterViewModel.
            Messenger.Default.Register <PropertyChangedMessage <UMCClusterLight> >(
                this,
                args =>
            {
                if (args.Sender == this.ClusterPlotViewModel && !this.ClusterPlotViewModel.SelectedCluster.Equals(this.SelectedMatch))
                {
                    this.SelectedMatch = this.Matches.FirstOrDefault(match => match.Cluster == this.ClusterPlotViewModel.SelectedCluster);
                }
            });

            // Listen for changes in selected cluster internally.
            Messenger.Default.Register <PropertyChangedMessage <ClusterMatch> >(
                this,
                arg =>
            {
                if (arg.Sender == this)
                {
                    this.throttler.Run(() => this.MatchSelected(arg));
                }
            });

            // When the selected MSFeature changes, update MS/MS spectra
            Messenger.Default.Register <PropertyChangedMessage <MSFeatureLight> >(
                this,
                arg =>
            {
                if (arg.Sender == this.XicPlotViewModel && arg.NewValue != null)
                {
                    this.MsMsSpectra.Clear();
                    foreach (var msmsSpectrum in arg.NewValue.MSnSpectra)
                    {
                        this.MsMsSpectra.Add(msmsSpectrum);
                    }

                    var first = this.MsMsSpectra.FirstOrDefault();
                    if (first != null)
                    {
                        this.SelectedMsMsSpectra = first;
                    }
                }
            });

            // Load layout.
            this.layoutFilePath = "layout.xml";
            this.LoadLayoutFile();

            if (this.Matches.Count > 0)
            {
                this.SelectedMatch = this.Matches[0];
            }
        }