public AlignmentSettingsViewModel(MultiAlignAnalysis analysis,
                                          FeatureLoader featureCache,
                                          IAlignmentWindowFactory alignmentWindowFactory = null,
                                          IProgress<int> progressReporter = null)
        {
            this.analysis = analysis;
            this.featureCache = featureCache;
            this.alignmentWindowFactory = alignmentWindowFactory ?? new AlignmentViewFactory();
            this.progress = progressReporter ?? new Progress<int>();
            this.aligner = new LCMSFeatureAligner();
            this.builder = new AlgorithmBuilder();
            this.CalibrationOptions = new ObservableCollection<AlignmentType>(Enum.GetValues(typeof(AlignmentType)).Cast<AlignmentType>());
            this.AlignmentAlgorithms = new ObservableCollection<FeatureAlignmentType>(
                                           Enum.GetValues(typeof(FeatureAlignmentType)).Cast<FeatureAlignmentType>());
            this.selectedDatasets = new ReadOnlyCollection<DatasetInformationViewModel>(new List<DatasetInformationViewModel>());
            this.alignmentInformation = new List<classAlignmentData>();

            this.MessengerInstance.Register<PropertyChangedMessage<IReadOnlyCollection<DatasetInformationViewModel>>>(this, sds =>
            {
                this.selectedDatasets = sds.NewValue;
                ThreadSafeDispatcher.Invoke(() => this.AlignToBaselineCommand.RaiseCanExecuteChanged());
                ThreadSafeDispatcher.Invoke(() => this.DisplayAlignmentCommand.RaiseCanExecuteChanged());
            });

            this.AlignToBaselineCommand = new RelayCommand(this.AsyncAlignToBaseline, () => this.SelectedBaseline != null && 
                                                                                  this.selectedDatasets != null &&
                                                                                  this.selectedDatasets.Count > 0 &&
                                                                                  this.selectedDatasets.Any(file => !file.DoingWork));
            this.DisplayAlignmentCommand = new RelayCommand(this.DisplayAlignment, () => this.selectedDatasets.Any(file => file.IsAligned));
        }
Пример #2
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);
        }