Ejemplo n.º 1
0
        public void LoadWithoutDriftTime(string server, string databaseName)
        {
            var analysis = new MultiAlignAnalysis();

            analysis.Options.MassTagDatabaseOptions.OnlyLoadTagsWithDriftTime = false;

            analysis.MetaData.Database = new InputDatabase(MassTagDatabaseFormat.MassTagSystemSql)
            {
                DatabaseServer = server,
                DatabaseName   = databaseName
            };

            MassTagDatabaseLoader loader = new MtsMassTagDatabaseLoader(databaseName, server,
                                                                        analysis.Options.MassTagDatabaseOptions);
            var database = loader.LoadDatabase();

            MassTagDatabaseLoader loader2 = new MtsMassTagDatabaseLoader(databaseName, server,
                                                                         analysis.Options.MassTagDatabaseOptions);

            loader2.Options.OnlyLoadTagsWithDriftTime = true;
            var database2 = loader.LoadDatabase();


            Assert.Greater(database.MassTags.Count, database2.MassTags.Count);
        }
Ejemplo n.º 2
0
        public void TestXMLParameterWriterFeatureFinderOptions(string path)
        {
            try
            {
                XMLParameterFileWriter writer   = new XMLParameterFileWriter();
                XMLParamterFileReader  reader   = new XMLParamterFileReader();
                MultiAlignAnalysis     analysis = new MultiAlignAnalysis();
                analysis.Options.AlignmentOptions.IsAlignmentBaselineAMasstagDB = true;

                analysis.Options.FeatureFindingOptions = ChangeObjectValues(analysis.Options.FeatureFindingOptions) as MultiAlignCore.Algorithms.FeatureFinding.LCMSFeatureFindingOptions;
                writer.WriteParameterFile(path, analysis);
                MultiAlignAnalysis newAnalysis = new MultiAlignAnalysis();
                reader.ReadParameterFile(path, ref newAnalysis);
                Compare(analysis.Options.FeatureFindingOptions, newAnalysis.Options.FeatureFindingOptions);
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                try
                {
                    bool exists = File.Exists(path);
                    if (exists)
                    {
                        File.Delete(path);
                    }
                }
                catch
                {
                    Console.WriteLine("The file was not deleted.");
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="analysis"></param>
        public DataLoadingSettingsViewModel(
            MultiAlignAnalysis analysis)
        {
            this.analysis = analysis;

            this.RestoreDefaultsCommand = new RelayCommand(this.RestoreDefaults);
        }
Ejemplo n.º 4
0
 public void TestXMLParameterWriterMTDB(string path)
 {
     try
     {
         XMLParameterFileWriter writer   = new XMLParameterFileWriter();
         XMLParamterFileReader  reader   = new XMLParamterFileReader();
         MultiAlignAnalysis     analysis = new MultiAlignAnalysis();
         analysis.Options.MassTagDatabaseOptions = ChangeObjectValues(analysis.Options.MassTagDatabaseOptions) as MultiAlignCore.IO.MTDB.MassTagDatabaseOptions;
         writer.WriteParameterFile(path, analysis);
         MultiAlignAnalysis newAnalysis = new MultiAlignAnalysis();
         reader.ReadParameterFile(path, ref newAnalysis);
         Compare(analysis.Options.MassTagDatabaseOptions, newAnalysis.Options.MassTagDatabaseOptions);
     }
     catch (Exception ex)
     {
         throw;
     }
     finally
     {
         try
         {
             bool exists = File.Exists(path);
             if (exists)
             {
                 File.Delete(path);
             }
         }
         catch
         {
             Console.WriteLine("The file was not deleted.");
         }
     }
 }
Ejemplo n.º 5
0
        private void LoadDatasets(MultiAlignAnalysis analysis)
        {
            var datasets = analysis.MetaData.Datasets.ToList();

            // Sort the datasets for the view...
            datasets.Sort(delegate(DatasetInformation x, DatasetInformation y)
            {
                if (x.DatasetId == y.DatasetId)
                {
                    return(0);
                }

                if (x.IsBaseline)
                {
                    return(-1);
                }

                return(x.DatasetName.CompareTo(y.DatasetName));
            });

            // Make the dataset plots.
            var plotPath = Path.Combine(analysis.MetaData.AnalysisPath, "plots");

            if (Directory.Exists(plotPath))
            {
                var loader = new DatasetPlotLoader();
                loader.LoadDatasetPlots(plotPath, analysis.MetaData.Datasets.ToList());
            }

            Datasets = new DatasetCollectionViewModel(datasets);
        }
Ejemplo n.º 6
0
        public FeatureFindingSettingsViewModel(
            MultiAlignAnalysis analysis,
            FeatureLoader featureCache,
            IFeatureWindowFactory msFeatureWindowFactory = null,
            IProgress <int> progressReporter             = null)
        {
            this.analysis               = analysis;
            this.featureCache           = featureCache;
            this.msFeatureWindowFactory = msFeatureWindowFactory ?? new MSFeatureViewFactory();
            this.progress               = progressReporter ?? new Progress <int>();
            this.selectedDatasets       = new ReadOnlyCollection <DatasetInformation>(new List <DatasetInformation>());
            this.msFeatureWindowFactory = new MSFeatureViewFactory();

            MessengerInstance.Register <PropertyChangedMessage <IReadOnlyCollection <DatasetInformation> > >(this, sds =>
            {
                this.selectedDatasets = sds.NewValue;
                this.FindMSFeaturesCommand.RaiseCanExecuteChanged();
                this.PlotMSFeaturesCommand.RaiseCanExecuteChanged();
            });

            FindMSFeaturesCommand = new RelayCommand(
                async() => await LoadMSFeaturesAsync(),
                () => this.selectedDatasets != null &&
                this.selectedDatasets.Count > 0 &&
                this.selectedDatasets.Any(file => !file.DoingWork));
            PlotMSFeaturesCommand = new RelayCommand(
                async() => await PlotMSFeatures(),
                () => this.selectedDatasets.Any(file => file.FeaturesFound));
        }
Ejemplo n.º 7
0
        public AnalysisBaselineSelectionViewModel(MultiAlignAnalysis analysis)
        {
            var filter =
                "Mass Tag Database (.db3)|*.db3|Direct Infusion IMS Database (.dims)|*.dims|All Files (*.*)|*.*";

            m_analysis = analysis;

            IsDatabaseDms     = false;
            IsDatabaseLocal   = false;
            IsBaselineDataset = true;

            SetDatabaseToDms      = new BaseCommand(SetDatabaseToDmsDelegate, BaseCommand.AlwaysPass);
            SetDatabaseToLocal    = new BaseCommand(SetDatabaseToLocalDelegate, BaseCommand.AlwaysPass);
            SetBaselineToDatabase = new BaseCommand(SetBaselineToDatabaseDelegate, BaseCommand.AlwaysPass);
            SetBaselineToDataset  = new BaseCommand(SetBaselineToDatasetDelegate, BaseCommand.AlwaysPass);
            FindLocalDatabase     = new BrowseOpenFileCommand(x =>
            {
                DatabaseFilePath = x;
                IsDatabaseLocal  = true;
                OnPropertyChanged("RequiresDatabaseSelection");
            }, filter);
            FindDmsDatabase = new BaseCommand(FindDmsDatabaseDelegate, BaseCommand.AlwaysPass);
            ClearDatabase   = new BaseCommand(ClearDatabaseDelegate, BaseCommand.AlwaysPass);
            Datasets        = new ObservableCollection <DatasetInformationViewModel>();
            UpdateDatasets();

            StacOptionsViewModel            = new StacOptionsViewModel(analysis.Options.StacOptions);
            MassTagDatabaseOptionsViewModel =
                new MassTagDatabaseOptionsViewModel(analysis.Options.MassTagDatabaseOptions);
        }
Ejemplo n.º 8
0
        public static FeatureDataAccessProviders CreateDataAccessProviders(MultiAlignAnalysis analysis,
                                                                           bool deleteIfExists)
        {
            var path = AnalysisPathUtils.BuildAnalysisName(analysis.MetaData.AnalysisPath,
                                                           analysis.MetaData.AnalysisName);

            return(CreateDataAccessProviders(path, deleteIfExists));
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        private void DisplayAnalysis(MultiAlignAnalysis analysis)
        {
            // Change the title
            var version = ApplicationUtility.GetEntryAssemblyData();

            Title = string.Format("{0} - {1}", version, analysis.MetaData.AnalysisName);

            var model = new AnalysisViewModel(analysis);

            CurrentAnalysis = model;
            StateModerator.CurrentViewState = ViewState.AnalysisView;
            var recent = new RecentAnalysis(analysis.MetaData.AnalysisPath,
                                            analysis.MetaData.AnalysisName);

            GettingStartedViewModel.CurrentWorkspace.AddAnalysis(recent);
        }
Ejemplo n.º 11
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();
        }
Ejemplo n.º 12
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>());
        }
Ejemplo n.º 13
0
        public void OnlyLoadWithDriftTime(string server, string databaseName)
        {
            var analysis = new MultiAlignAnalysis();

            analysis.Options.MassTagDatabaseOptions.OnlyLoadTagsWithDriftTime = true;

            analysis.MetaData.Database = new InputDatabase(MassTagDatabaseFormat.MassTagSystemSql)
            {
                DatabaseServer = server,
                DatabaseName   = databaseName
            };

            var loader   = new MTSMassTagDatabaseLoader(databaseName, server, analysis.Options.MassTagDatabaseOptions);
            var database = loader.LoadDatabase();

            foreach (var tag in database.MassTags)
            {
                Assert.IsTrue(tag.DriftTime > 0);
            }
        }
Ejemplo n.º 14
0
        public AnalysisViewModel(MultiAlignAnalysis analysis)
        {
            m_showDriftTime = false;

            LoadDatasets(analysis);

            // Create matching clusters and AMT Matches.
            var matches  = analysis.DataProviders.MassTagMatches.FindAll();
            var clusters =
                analysis.Clusters.MapMassTagsToClusters(matches, analysis.MassTagDatabase);

            // Cache the clusters so that they can be readily accessible later on.
            // This will help speed up performance, so that we dont have to hit the database
            // when we want to find matching mass tags, and dont have to map clusters to tags multiple times.
            FeatureCacheManager <UMCClusterLightMatched> .SetFeatures(clusters.Item1);

            FeatureCacheManager <MassTagToCluster> .SetFeatures(clusters.Item2);

            SingletonDataProviders.Providers = analysis.DataProviders;


            // Create sub-view models
            MassTags                       = new ObservableCollection <MassTagToCluster>(clusters.Item2);
            ClusterTree                    = new UmcClusterCollectionTreeViewModel(clusters.Item1);
            ClusterSpectraViewModel        = new UmcClusterSpectraViewModel();
            ClusterIdentificationViewModel = new UMCClusterIdentificationViewModel();
            AnalysisOptionsViewModel       = new AnalysisOptionsViewModel(analysis.Options);
            ClusterViewModel               = new ClusterDetailViewModel();

            var charges = SingletonDataProviders.Providers.FeatureCache.RetrieveChargeStates();

            GlobalStatisticsViewModel = new GlobalStatisticsViewModel(clusters.Item1, charges);
            HasIdentifications        = (MassTags.Count > 0);


            SelectedClusterName = "Cluster Details:";
            LoadClusters(clusters.Item1);
            ApplyViewAsFilter = new BaseCommand(FilterFromView);
        }
Ejemplo n.º 15
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));
        }
Ejemplo n.º 16
0
        public AnalysisDatasetSelectionViewModel(MultiAlignAnalysis analysis)
        {
            m_inputFileFilter   = "Input Files (*.txt)| *.txt| All Files (*.*)|*.*";
            m_featureFileFilter = DatasetFilterFactory.BuildFileFilters(InputFileType.Features);
            m_openFileDialog    = new OpenFileDialog {
                Filter = m_inputFileFilter
            };
            m_analysis = analysis;
            ShouldSearchSubDirectories = SearchOption.TopDirectoryOnly;


            // Create The Dataset View Model for Binding
            Datasets = new ObservableCollection <DatasetInformationViewModel>();
            foreach (var information in analysis.MetaData.Datasets)
            {
                var info = new DatasetInformationViewModel(information);
                info.Selected += info_Selected;
                Datasets.Add(info);
            }


            // Route the events here...
            AddFolderCommand     = new BaseCommand(AddFolderDelegate, BaseCommand.AlwaysPass);
            AddInputFileCommand  = new BaseCommand(AddInputFileDelegate, BaseCommand.AlwaysPass);
            AddSingleFileCommand = new BaseCommand(AddSingleFileDelegate, BaseCommand.AlwaysPass);

            BrowseSingleFileCommand = new BaseCommand(BrowseSingleFile, BaseCommand.AlwaysPass);
            BrowseInputFileCommand  = new BaseCommand(BrowseInput, BaseCommand.AlwaysPass);
            BrowseDataFolderCommand = new BrowseFolderCommand(x => { DataFolderPath = x; });

            RemoveSelectedCommand = new BaseCommand(RemoveSelected, BaseCommand.AlwaysPass);
            SelectAllCommand      = new BaseCommand(SelectAllDelegate, BaseCommand.AlwaysPass);
            SelectNoneCommand     = new BaseCommand(SelectNoneDelegate, BaseCommand.AlwaysPass);

            SelectedDatasets = new ObservableCollection <DatasetInformationViewModel>();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 18
0
 public AnalysisStatusArgs(MultiAlignAnalysis analysis)
 {
     Analysis = analysis;
 }
Ejemplo n.º 19
0
        private static bool ValidateBaseline(MultiAlignAnalysis analysis, ref string errorMessage)
        {
            var isStepValid = true;

            if (analysis.Options.AlignmentOptions.IsAlignmentBaselineAMasstagDB)
            {
                var database     = analysis.MetaData.Database;
                var databasePath = analysis.MetaData.Database.DatabaseName;

                switch (database.DatabaseFormat)
                {
                case MassTagDatabaseFormat.None:
                    errorMessage = "No database was selected.";
                    isStepValid  = false;
                    break;

                case MassTagDatabaseFormat.MassTagSystemSql:
                    if (string.IsNullOrWhiteSpace(database.DatabaseName) || string.IsNullOrWhiteSpace(database.DatabaseServer))
                    {
                        isStepValid  = false;
                        errorMessage = "The database or server was not set.";
                    }
                    break;

                case MassTagDatabaseFormat.SkipAlignment:
                case MassTagDatabaseFormat.Sqlite:
                    databasePath = analysis.MetaData.Database.LocalPath;
                    if (databasePath == null)
                    {
                        errorMessage = "No MTDB database file was selected.";
                        isStepValid  = false;
                    }
                    else
                    {
                        if (!File.Exists(databasePath))
                        {
                            errorMessage = "The database file provided does not exist.";
                            isStepValid  = false;
                        }
                    }
                    break;

                case MassTagDatabaseFormat.DelimitedTextFile:
                    errorMessage = "Invalid database type.";
                    isStepValid  = false;
                    break;
                }
            }
            else
            {
                if (analysis.MetaData.Datasets.Count < 2)
                {
                    isStepValid  = false;
                    errorMessage = "You must align a single dataset to a database.";
                }
                else if (analysis.MetaData.BaselineDataset == null)
                {
                    errorMessage = "No baseline dataset was selected.";
                    isStepValid  = false;
                }
            }
            return(isStepValid);
        }
Ejemplo n.º 20
0
 /// <summary>
 ///     Writes a list of mamoth clusters back to the mass tag system at the server and database provided.
 /// </summary>
 /// <param name="server">Server the database exists on.</param>
 /// <param name="database">Database to write results to.</param>
 /// <param name="clusters">Clusters that are peak matched to.</param>
 public void WriteClusters(MultiAlignAnalysis analysis,
                           List <UMCClusterLight> clusters,
                           string databasePath)
 {
     /*
      * //clsMassTag[] massTagArray                                       = analysis.PeakMatchingResults.marrMasstags;
      * //clsProtein[] proteinArray                                       = analysis.PeakMatchingResults.marrProteins;
      * //List<clsMassTag> massTagList                                    = new List<clsMassTag>();
      * //List<clsProtein> proteinList                                    = new List<clsProtein>();
      * //List<ClusterToMassTagMap> clusterToMassTagMapList               = new List<ClusterToMassTagMap>();
      * //List<MassTagToProteinMap> massTagToProteinMapList               = new List<MassTagToProteinMap>();
      * //List<StacFDR> stacFDRResultsList                                = new List<StacFDR>();
      * //Dictionary<int, int> clusterMatchDict                           = new Dictionary<int,int>();            // Unique matches to mass tags.
      * //Dictionary<int, List<ClusterToMassTagMap>> clusterMassTagDict   = new Dictionary<int, List<ClusterToMassTagMap>>();
      * //Dictionary<double, int> stacFdrDict                             = new Dictionary<double,int>();            // counts number of matches with FDR's > key
      * //double [] fdrScores                                             = new double[] {.01, .05, .10, .25, .50};
      *
      * //foreach(int fdrCutoffScore in fdrScores)
      * //{
      * //    stacFdrDict.Add(fdrCutoffScore, 0);
      * //}
      *
      * //foreach (clsPeakMatchingResults.clsPeakMatchingTriplet triplet in analysis.PeakMatchingResults.marrPeakMatchingTriplet)
      * //{
      * //    clsMassTag massTag                      = massTagArray[triplet.mintMassTagIndex];
      * //    clsProtein protein                      = proteinArray[triplet.mintProteinIndex];
      * //    ClusterToMassTagMap clusterToMassTagMap = new ClusterToMassTagMap(triplet.mintFeatureIndex, massTag.Id);
      * //    MassTagToProteinMap massTagToProteinMap = new MassTagToProteinMap(massTag.Id, protein.Id);
      *
      * //    if (!clusterToMassTagMapList.Contains(clusterToMassTagMap))
      * //    {
      * //        clusterToMassTagMapList.Add(clusterToMassTagMap);
      * //        if (!clusterMatchDict.ContainsKey(triplet.mintFeatureIndex))
      * //        {
      * //            clusterMassTagDict.Add(triplet.mintFeatureIndex, new List<ClusterToMassTagMap>());
      * //            clusterMatchDict.Add(triplet.mintFeatureIndex, 1);
      * //        }
      * //        else
      * //        {
      * //            clusterMatchDict[triplet.mintFeatureIndex]++;
      * //        }
      * //        clusterMassTagDict[triplet.mintFeatureIndex].Add(clusterToMassTagMap);
      *
      * //        if (analysis.STACResults != null)
      * //        {
      * //            // See if a SMART score exists
      * //            List<classSMARTProbabilityResult> smartScores = null;
      * //            smartScores = analysis.STACResults.GetResultFromUMCIndex(triplet.mintFeatureIndex);
      *
      * //            if (smartScores != null)
      * //            {
      * //                // Then pull out the SMART score that matches for this triplet Mass Tag
      * //                classSMARTProbabilityResult finalResult = null;
      * //                foreach (classSMARTProbabilityResult score in smartScores)
      * //                {
      * //                    if (score.MassTagID == massTag.Id)
      * //                    {
      * //                        finalResult = score;
      * //                        break;
      * //                    }
      * //                }
      *
      * //                if (finalResult != null)
      * //                {
      * //                    double score                    = finalResult.Score;
      * //                    clusterToMassTagMap.StacScore   = score;
      * //                    clusterToMassTagMap.StacUP      = finalResult.Specificity;
      *
      * //                    foreach(int fdrCutoffScore in fdrScores)
      * //                    {
      * //                        if (score <= fdrCutoffScore) stacFdrDict[score]++;
      * //                    }
      * //                }
      * //            }
      * //        }
      * //    }
      *
      * //    if (!massTagToProteinMapList.Contains(massTagToProteinMap)) massTagToProteinMapList.Add(massTagToProteinMap);
      * //    if (!massTagList.Contains(massTag)) massTagList.Add(massTag);
      * //    if (!proteinList.Contains(protein)) proteinList.Add(protein);
      * //}
      *
      * //if (analysis.STACResults != null)
      * //{
      * //    foreach (classSMARTFdrResult fdrResult in analysis.STACResults.GetSummaries())
      * //    {
      * //        stacFDRResultsList.Add(new StacFDR(fdrResult));
      * //    }
      * //}
      *
      * //// find the minimum NET value for any cluster.
      * //double minClusterNET = double.MaxValue;
      * //double maxClusterNET = double.MinValue;
      * //foreach(clsCluster cluster in clusters)
      * //{
      * //    if (analysis.ClusterOptions.AlignClusters)
      * //    {
      * //        minClusterNET = Math.Min(minClusterNET, cluster.NetAligned);
      * //        maxClusterNET = Math.Max(maxClusterNET, cluster.NetAligned);
      * //    }
      * //    else
      * //    {
      * //        minClusterNET = Math.Min(minClusterNET, cluster.Net);
      * //        maxClusterNET = Math.Max(maxClusterNET, cluster.Net);
      * //    }
      * //}
      *
      * // now write to the MTS System.
      * string connectionString = "";
      * string versionID        = "";
      * string parameters       = "";
      * string peakMatchingType = "1";
      * int    redundantCount   = analysis.MatchResults.Matches.Count;
      * int    matchMakingID    = -1;
      *
      * string parameterFile    = "";
      *
      * if (analysis.MetaData.ParameterFile != null)
      * {
      *  parameterFile = analysis.MetaData.ParameterFile;
      * }
      *
      * using (IDbConnection connection = CreateConnection(connectionString))
      * {
      *  connection.Open();
      *  using (IDbCommand command = connection.CreateCommand())
      *  {
      *      command.CommandType = System.Data.CommandType.StoredProcedure;
      *      command.Parameters.Add(CreateParameter("Reference_Job",                analysis.MetaData.JobID));
      *      command.Parameters.Add(CreateParameter("File",                         peakMatchingType));
      *      command.Parameters.Add(CreateParameter("Type",                         1));
      *      command.Parameters.Add(CreateParameter("Parameters",                   parameters));
      *      command.Parameters.Add(CreateParameter("PeaksCount",                   redundantCount));
      *
      *      IDbDataParameter matchMakingParameter = CreateOutputParameter(  "MatchMakingID",
      *                                                                      DbType.Int32,
      *                                                                      sizeof(int),
      *                                                                      10,
      *                                                                      0);
      *      command.Parameters.Add(matchMakingParameter);
      *      command.Parameters.Add(CreateParameter("ToolVersion",                  versionID));
      *      command.Parameters.Add(CreateParameter("ComparisonMassTagCount",       analysis.MassTagDatabase.MassTags.Count));
      *      command.Parameters.Add(CreateParameter("UMCTolerancePPM",              analysis.Options.FeatureFindingOptions.ConstraintMonoMass)); //TODO: do not necessarily have if using LCMS Feature Finder Data
      *      command.Parameters.Add(CreateParameter("UMCCount",                     clusters.Count));
      *      command.Parameters.Add(CreateParameter("NetAdjTolerancePPM",           analysis.Options.AlignmentOptions.MassTolerance));
      *      command.Parameters.Add(CreateParameter("NetAdjUMCsHitCount",           analysis.MatchResults.Matches.Count));        //TODO:  is this right?
      *      command.Parameters.Add(CreateParameter("NetAdjTopAbuPct",              0)); // Per direction from Matt
      *      command.Parameters.Add(CreateParameter("NetAdjIterationCount",         1)); // Per direction from Matt
      *      command.Parameters.Add(CreateParameter("MMATolerancePPM",              analysis.Options.STACOptions.MassTolerancePPM));
      *      command.Parameters.Add(CreateParameter("NETTolerance",                 analysis.Options.STACOptions.NETTolerance));
      *      command.Parameters.Add(CreateParameter("State",                        2));
      *      command.Parameters.Add(CreateParameter("GANETFit",                     0)); //TODO: do not have
      *      command.Parameters.Add(CreateParameter("GANETSlope",                   0)); //TODO: do not have
      *      command.Parameters.Add(CreateParameter("GANETIntercept",               0)); //TODO: do not have
      *      command.Parameters.Add(CreateParameter("NetAdjNetMin",                 minClusterNET));
      *      command.Parameters.Add(CreateParameter("NetAdjNetMax",                 maxClusterNET));
      *      command.Parameters.Add(CreateParameter("RefineMassCalPPMShift",        0)); //TODO: do not have
      *      command.Parameters.Add(CreateParameter("RefineMassCalPeakHeightCounts",0)); //TODO: do not have
      *      command.Parameters.Add(CreateParameter("RefineMassTolUsed",            0)); //TODO: do not have
      *      command.Parameters.Add(CreateParameter("RefineNETTolUsed",             0)); //TODO: do not have
      *      command.Parameters.Add(CreateParameter("MinimumHighNormalizedScore",   analysis.MassTagDBOptions.mfltMinXCorr));
      *      command.Parameters.Add(CreateParameter("MinimumPMTQualityScore",       Convert.ToDouble(analysis.MassTagDBOptions.mdecimalMinPMTScore)));
      *      command.Parameters.Add(CreateParameter("IniFileName",                  parameterFile));
      *      command.Parameters.Add(CreateParameter("MinimumHighDiscriminantScore", analysis.MassTagDBOptions.mdblMinDiscriminant));
      *      command.Parameters.Add(CreateParameter("ExperimentFilter",             analysis.MassTagDBOptions.mstrExperimentFilter));
      *      command.Parameters.Add(CreateParameter("ExperimentExclusionFilter",    analysis.MassTagDBOptions.mstrExperimentExclusionFilter));
      *      command.Parameters.Add(CreateParameter("RefineMassCalPeakWidthPPM",    0));    //TODO: do not have
      *      command.Parameters.Add(CreateParameter("RefineMassCalPeakCenterPPM",   0));    //TODO: do not have
      *      command.Parameters.Add(CreateParameter("RefineNETTolPeakHeightCounts", 0));    //TODO: do not have
      *      command.Parameters.Add(CreateParameter("RefineNETTolPeakWidthNET",     0));    //TODO: do not have
      *      command.Parameters.Add(CreateParameter("RefineNETTolPeakCenterNET",    0));    //TODO: do not have
      *      command.Parameters.Add(CreateParameter("LimitToPMTsFromDataset",       0));
      *      command.Parameters.Add(CreateParameter("MinimumPeptideProphetProbability", analysis.MassTagDBOptions.mdblPeptideProphetVal));
      *      command.Parameters.Add(CreateParameter("MatchScoreMode",               Convert.ToInt32(analysis.PeakMatchingOptions.UseSTAC)));
      *      command.Parameters.Add(CreateParameter("STACUsedPriorProbability",     Convert.ToInt32(analysis.STACOptions.UsePriorProbabilities)));
      *      command.Parameters.Add(CreateParameter("AMTCount1pctFDR",              stacFdrDict[.01]));
      *      command.Parameters.Add(CreateParameter("AMTCount5pctFDR",              stacFdrDict[.05]));
      *      command.Parameters.Add(CreateParameter("AMTCount10pctFDR",             stacFdrDict[.10]));
      *      command.Parameters.Add(CreateParameter("AMTCount25pctFDR",             stacFdrDict[.25]));
      *      command.Parameters.Add(CreateParameter("AMTCount50pctFDR",             stacFdrDict[.50]));
      *      command.ExecuteNonQuery();
      *
      *      matchMakingID = Convert.ToInt32(matchMakingParameter.Value);
      *  }
      *
      *  using (IDbTransaction transaction = connection.BeginTransaction())
      *  {
      *      Dictionary<int, clsCluster> resultIDClusterMap = new Dictionary<int,clsCluster>();
      *
      *      foreach (clsCluster cluster in clusters)
      *      {
      *          int matchCount  = 0;
      *          int resultID   = 0;
      *          if (clusterMatchDict.ContainsKey(cluster.Id))
      *          {
      *              matchCount = clusterMatchDict[cluster.Id];
      *          }
      *          using (IDbCommand command = connection.CreateCommand())
      *          {
      *              command.CommandType = CommandType.StoredProcedure;
      *              command.Parameters.Add(new SqlParameter("MDID",                     matchMakingID));
      *              command.Parameters.Add(new SqlParameter("UMCInd",                   cluster.Id));
      *              command.Parameters.Add(new SqlParameter("MemberCount",              cluster.MemberCount));
      *              command.Parameters.Add(new SqlParameter("UMCScore",                 cluster.MeanScore));
      *              command.Parameters.Add(new SqlParameter("ScanFirst",                -1));
      *              command.Parameters.Add(new SqlParameter("ScanLast",                 null));
      *              command.Parameters.Add(new SqlParameter("ScanMaxAbundance",         null));
      *              command.Parameters.Add(new SqlParameter("ClassMass",                cluster.Mass));
      *              command.Parameters.Add(new SqlParameter("MonoisotopicMassMin",      null));
      *              command.Parameters.Add(new SqlParameter("MonoisotopicMassMax",      null));
      *              command.Parameters.Add(new SqlParameter("MonoisotopicMassStDev",    null));
      *              command.Parameters.Add(new SqlParameter("MonoisotopicMassMaxAbu",   null));
      *              command.Parameters.Add(new SqlParameter("ClassAbundance",           null));
      *              command.Parameters.Add(new SqlParameter("AbundanceMin",             null));
      *              command.Parameters.Add(new SqlParameter("AbundanceMax",             null));
      *              command.Parameters.Add(new SqlParameter("ChargeStateMin",           null));
      *              command.Parameters.Add(new SqlParameter("ChargeStateMax",           null));
      *              command.Parameters.Add(new SqlParameter("ChargeStateMaxAbu",        null));
      *              command.Parameters.Add(new SqlParameter("FitAverage",               null));
      *              command.Parameters.Add(new SqlParameter("FitMin",                   null));
      *              command.Parameters.Add(new SqlParameter("FitMax",                   null));
      *              command.Parameters.Add(new SqlParameter("FitStDev",                 null));
      *              command.Parameters.Add(new SqlParameter("ElutionTime",              cluster.Net));
      *              command.Parameters.Add(new SqlParameter("ExpressionRatio",          0));
      *              command.Parameters.Add(new SqlParameter("PeakFPRType",              0));
      *              command.Parameters.Add(new SqlParameter("MassTagHitCount",          matchCount));
      *              command.Parameters.Add(new SqlParameter("PairUMCInd",               -1));
      *
      *              SqlParameter idParameter = new SqlParameter("UMCResultsID",
      *                                                      SqlDbType.Int,
      *                                                      sizeof(int),
      *                                                      System.Data.ParameterDirection.Output,
      *                                                      false,
      *                                                      10,
      *                                                      0,
      *                                                      "UMCResultsID",
      *                                                      DataRowVersion.Current,
      *                                                      resultID);
      *              command.Parameters.Add(idParameter);
      *              command.Parameters.Add(new SqlParameter("ClassStatsChargeBasis",                null));
      *              command.Parameters.Add(new SqlParameter("GANETLockerCount",                     null));
      *              command.Parameters.Add(new SqlParameter("ExpressionRatioStDev",                 null));
      *              command.Parameters.Add(new SqlParameter("ExpressionRatioChargeStateBasisCount", null));
      *              command.Parameters.Add(new SqlParameter("ExpressionRatioMemberBasisCount",      null));
      *              command.Parameters.Add(new SqlParameter("MemberCountUsedForAbu",                cluster.MemberCount));
      *              command.Parameters.Add(new SqlParameter("DriftTime",                            cluster.DriftTime));
      *              command.ExecuteNonQuery();
      *
      *              resultID = Convert.ToInt32(idParameter.Value);
      *          }
      *
      *          if (matchCount > 0)
      *          {
      *              using (IDbCommand command = connection.CreateCommand())
      *              {
      *                  double minScore         = double.MaxValue;
      *                  double maxScore         = double.MinValue;
      *                  double deltaMatchScore  = 0;
      *
      *                  foreach(ClusterToMassTagMap massTagMap in clusterMassTagDict[cluster.Id])
      *                  {
      *                      minScore = Math.Min(minScore, massTagMap.StacScore);
      *                      maxScore = Math.Max(maxScore, massTagMap.StacScore);
      *                  }
      *                  deltaMatchScore = Math.Abs(maxScore - minScore);
      *                  foreach(ClusterToMassTagMap massTagMap in clusterMassTagDict[cluster.Id])
      *                  {
      *                      command.CommandType = CommandType.StoredProcedure;
      *                      command.Parameters.Add(new SqlParameter("UMCResultsID",             resultID));
      *                      command.Parameters.Add(new SqlParameter("MassTagID",                massTagMap.MassTagId));
      *                      command.Parameters.Add(new SqlParameter("MatchingMemberCount",      cluster.MemberCount));
      *                      command.Parameters.Add(new SqlParameter("MatchScore",               massTagMap.StacScore));
      *                      command.Parameters.Add(new SqlParameter("MatchState",               6));
      *                      command.Parameters.Add(new SqlParameter("SetIsConfirmedForMT",      1));
      *                      command.Parameters.Add(new SqlParameter("MassTagMods",              "N14"));
      *                      command.Parameters.Add(new SqlParameter("MassTagModMass",           0));
      *                      command.Parameters.Add(new SqlParameter("DelMatchScore",            deltaMatchScore));
      *                      command.Parameters.Add(new SqlParameter("UniquenessProbability",    massTagMap.StacUP));
      *                      command.Parameters.Add(new SqlParameter("FDRThreshold",             1));
      *                      command.ExecuteNonQuery();
      *                  }
      *              }
      *          }
      *      }
      *
      *      List<classSMARTFdrResult> fdrList = analysis.STACResults.GetSummaries();
      *      if (fdrList != null)
      *      {
      *          foreach (classSMARTFdrResult fdr in fdrList)
      *          {
      *              using (IDbCommand command = connection.CreateCommand())
      *              {
      *                  command.Parameters.Add(new SqlParameter("MDID",                 matchMakingID));
      *                  command.Parameters.Add(new SqlParameter("STAC_Cutoff",          fdr.Cutoff));
      *                  command.Parameters.Add(new SqlParameter("UniqueAMTs",           0));
      *                  command.Parameters.Add(new SqlParameter("FDR",                  fdr.FDR));
      *                  command.Parameters.Add(new SqlParameter("Matches",              fdr.NumMatches));
      *                  command.Parameters.Add(new SqlParameter("Errors",               fdr.Error));
      *                  command.Parameters.Add(new SqlParameter("UPFilteredUniqueAMTs", 0));
      *                  command.Parameters.Add(new SqlParameter("UPFilteredFDR",        0));
      *                  command.Parameters.Add(new SqlParameter("UPFilteredMatches",    0));
      *                  command.Parameters.Add(new SqlParameter("UPFilteredErrors",     0));
      *                  command.ExecuteNonQuery();
      *              }
      *          }
      *      }
      *      transaction.Commit();
      *  }
      *  connection.Close();
      * }
      * */
 }