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));
        }
        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>();
        }
        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<DatasetInformationViewModel>(new List<DatasetInformationViewModel>());
            this.msFeatureWindowFactory = new MSFeatureViewFactory();

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

            this.FindMSFeaturesCommand = new RelayCommand(
                                        async () => await this.LoadMSFeaturesAsync(),
                                        () => this.selectedDatasets != null && 
                                              this.selectedDatasets.Count > 0 && 
                                              this.selectedDatasets.Any(file => !file.DoingWork));
            this.PlotMSFeaturesCommand = new RelayCommand(
                                        async () => await this.PlotMSFeatures(), 
                                        () => this.selectedDatasets.Any(file => file.FeaturesFound));
        }
        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 (database.DatabaseName == null || database.DatabaseServer == null)
                        {
                            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;
        }
예제 #5
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);
        }
예제 #6
0
 public void TestXMLParameterWriterDriftTimeAlignment(string path)
 {
     try
     {
         XMLParameterFileWriter writer   = new XMLParameterFileWriter();
         XMLParamterFileReader reader    = new XMLParamterFileReader();
         MultiAlignAnalysis analysis     = new MultiAlignAnalysis();
         analysis.Options.DriftTimeAlignmentOptions = ChangeObjectValues(analysis.Options.DriftTimeAlignmentOptions) as MultiAlignCore.Algorithms.Alignment.DriftTimeAlignmentOptions;
         writer.WriteParameterFile(path, analysis);
         MultiAlignAnalysis newAnalysis = new MultiAlignAnalysis();
         reader.ReadParameterFile(path, ref newAnalysis);
         Compare(analysis.Options.DriftTimeAlignmentOptions, newAnalysis.Options.DriftTimeAlignmentOptions);
     }
     catch (Exception ex)
     {
         throw;
     }
     finally
     {
         try
         {
             bool exists = File.Exists(path);
             if (exists)
             {
                 File.Delete(path);
             }
         }
         catch
         {
             Console.WriteLine("The file was not deleted.");
         }
     }
 }
예제 #7
0
 public static FeatureDataAccessProviders CreateDataAccessProviders(MultiAlignAnalysis analysis,
     bool deleteIfExists)
 {
     var path = AnalysisPathUtils.BuildAnalysisName(analysis.MetaData.AnalysisPath,
         analysis.MetaData.AnalysisName);
     return CreateDataAccessProviders(path, deleteIfExists);
 }
        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);
        }
예제 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewModel"/> class.
        /// </summary>
        public MainViewModel()
        {
            m_config = new AnalysisConfig();
            Analysis = new MultiAlignAnalysis();
            m_config.AnalysisName = "Analysis.db3";
            m_config.Analysis = Analysis;

            this.WindowTitle = "MultiAlign Rogue";

            DataSelectionViewModel = new AnalysisDatasetSelectionViewModel(Analysis);

            SelectFilesCommand = new RelayCommand(SelectFiles, () => !string.IsNullOrWhiteSpace(this.ProjectPath));
            SelectDirectoryCommand = new RelayCommand(SelectDirectory, () => !string.IsNullOrWhiteSpace(this.ProjectPath));
            AddFolderCommand = new RelayCommand(AddFolderDelegate, () => !string.IsNullOrWhiteSpace(this.InputFilePath) && Directory.Exists(this.InputFilePath) && !string.IsNullOrWhiteSpace(this.ProjectPath));
            SearchDmsCommand = new RelayCommand(SearchDms, () => this.ShowOpenFromDms && !string.IsNullOrWhiteSpace(this.ProjectPath));
            CreateNewProjectCommand = new RelayCommand(this.CreateNewProject);
            SaveProjectCommand = new RelayCommand(SaveProject, () => !string.IsNullOrWhiteSpace(this.ProjectPath));
            LoadProjectCommand = new RelayCommand(LoadProject);
            SaveAsProjectCommand = new RelayCommand(this.SaveProjectAs, () => !string.IsNullOrWhiteSpace(this.ProjectPath));

            featureCache = new FeatureLoader { Providers = Analysis.DataProviders };
            this.SelectedDatasets = new List<DatasetInformationViewModel>();
            Datasets = new ObservableCollection<DatasetInformationViewModel>();

            featureCache.Providers = Analysis.DataProviders;
            this.FeatureFindingSettingsViewModel = new FeatureFindingSettingsViewModel(Analysis, featureCache);
            this.AlignmentSettingsViewModel = new AlignmentSettingsViewModel(Analysis, featureCache);
            this.ClusterSettingsViewModel = new ClusterSettingsViewModel(Analysis);
        }
        /// <summary>
        /// Saves the analysis parameters to file.
        /// </summary>
        /// <param name="filename">File to save to.</param>
        /// <param name="analysis">Analysis with options to save.</param>
        public void WriteParametersToFile(string filename, MultiAlignAnalysis analysis)
        {
            using (TextWriter writer = File.CreateText(filename))
            {

                WriteOptionGroup(writer, ALIGNMENT_TAG,         analysis.Options.AlignmentOptions);
                WriteOptionGroup(writer, FEATURE_FINDING_TAG,   analysis.Options.FeatureFindingOptions);
                WriteOptionGroup(writer, MASS_TAG_DATABASE_TAG, analysis.Options.MassTagDatabaseOptions);
                WriteOptionGroup(writer, CLUSTER_TAG,           analysis.Options.ClusterOptions);

                writer.WriteLine("[" + GLOBAL_TAG + "]" );
                WriteOption(writer, GLOBAL_OPTION_USE_MTDB_AS_BASELINE, analysis.Options.AlignmentOptions.IsAlignmentBaselineAMasstagDB);
                writer.WriteLine();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameterFilePath"></param>
        /// <returns></returns>
        public void ReadParameterFile(string parameterFilePath, ref MultiAlignAnalysis analysis)
        {
            if (!File.Exists(parameterFilePath))
                throw new FileNotFoundException("The parameter file was not found. " + parameterFilePath);

            // Parse the data.
            string[] lines = File.ReadAllLines(parameterFilePath);
            ExtractGroups(lines);

            LoadParameterOptions(ProcessSubSectionData(ALIGNMENT_TAG),           analysis.Options.AlignmentOptions);
            LoadParameterOptions(ProcessSubSectionData(FEATURE_FINDING_TAG),     analysis.Options.FeatureFindingOptions);
            LoadParameterOptions(ProcessSubSectionData(MASS_TAG_DATABASE_TAG),   analysis.Options.MassTagDatabaseOptions);
            LoadParameterOptions(ProcessSubSectionData(CLUSTER_TAG),             analysis.Options.ClusterOptions);
            LoadGlobalOptions(ref analysis);
        }
예제 #12
0
        public ClusterSettingsViewModel(MultiAlignAnalysis analysis, IProgress<int> progressReporter = null)
        {
            this.analysis = analysis;
            this.options = analysis.Options;
            this.builder = new AlgorithmBuilder();

            this.ClusterFeaturesCommand = new RelayCommand(this.AsyncClusterFeatures);
            this.DisplayClustersCommand = new RelayCommand(this.DisplayFeatures);

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

        }
예제 #13
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();
        }
예제 #14
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);
            }
        }
예제 #15
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);
        }
예제 #16
0
        /// <summary>
        ///     Constructs dataset infromation from the input analysis information.
        /// </summary>
        private void ConstructDatasetInformation(InputAnalysisInfo analysisSetupInformation, MultiAlignAnalysis analysis,
            bool insertIntoDatabase)
        {
            // Create dataset information.
            Logger.PrintMessage("Creating dataset and other input information.");

            var datasets = DatasetInformation.CreateDatasetsFromInputFile(analysisSetupInformation.Files);
            analysis.MetaData.Datasets.AddRange(datasets);

            if (insertIntoDatabase)
            {
                m_config.Analysis.DataProviders.DatasetCache.AddAll(datasets);
            }
        }
예제 #17
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);
        }
예제 #18
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="analysis"></param>
 public AnalysisCompleteEventArgs(MultiAlignAnalysis analysis)
 {
     Analysis = analysis;
 }
예제 #19
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();
            }
             * */
        }
예제 #20
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);
        }
예제 #21
0
 private MultiAlignAnalysis ConstructAnalysisObject(InputAnalysisInfo analysisSetupInformation)
 {
     Logger.PrintMessage("Creating Analysis Objects.");
     var analysis = new MultiAlignAnalysis
     {
         MetaData = { AnalysisPath = m_config.AnalysisPath, AnalysisName = m_config.AnalysisName }
     };
     analysis.Options.AlignmentOptions.IsAlignmentBaselineAMasstagDB = true;
     analysis.MetaData.ParameterFile = m_config.ParameterFile;
     analysis.MetaData.InputFileDefinition = m_config.InputPaths;
     analysis.MetaData.AnalysisSetupInfo = analysisSetupInformation;
     return analysis;
 }
 /// <summary>
 /// Loads the global options manually.
 /// </summary>
 /// <param name="analysis"></param>
 private void LoadGlobalOptions(ref MultiAlignAnalysis analysis)
 {
     Dictionary<string, string> map  = ProcessSubSectionData(GLOBAL_TAG);
     analysis.Options.AlignmentOptions.IsAlignmentBaselineAMasstagDB = Convert.ToBoolean(map["Use Mass Tag DB As Baseline"]);
 }
예제 #23
0
 public AnalysisStatusArgs(MultiAlignAnalysis analysis)
 {
     Analysis = analysis;
 }
예제 #24
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="parameterFilePath"></param>
 /// <returns></returns>
 public void ReadParameterFile(string parameterFilePath, ref MultiAlignAnalysis analysis)
 {
     AnalysisOptions options = analysis.Options;
     ReadParameterFile(parameterFilePath, ref options);
 }
예제 #25
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="analysis"></param>
 public AnalysisCompleteEventArgs(MultiAlignAnalysis analysis)
 {
     Analysis = analysis;
 }
예제 #26
0
 public void WriteParameterFile(string parameterFilePath, MultiAlignAnalysis analysis)
 {
     WriteParameterFile(parameterFilePath, analysis.Options);
 }
예제 #27
0
        /// <summary>
        ///     Writes the parameters to the log file and database.
        /// </summary>
        private void PrintParameters(MultiAlignAnalysis analysis, bool insertIntoDatabase)
        {
            Logger.PrintMessage("Parameters Loaded");
            var options = new Dictionary<string, object>
            {
                {"Instrument Tolerances", analysis.Options.InstrumentTolerances},
                {"Ms Feature Filtering Options", analysis.Options.MsFilteringOptions},
                {"Feature Filtering Options", analysis.Options.LcmsFilteringOptions},
                {"Mass Tag Database Options", analysis.Options.MassTagDatabaseOptions},
                {"Alignment Options", analysis.Options.AlignmentOptions},
                {"Clustering Options", analysis.Options.LcmsClusteringOptions},
                {"STAC Options", analysis.Options.StacOptions}
            };

            var allmappings = new List<ParameterHibernateMapping>();
            foreach (var key in options.Keys)
            {
                //var o = options[key];
                Logger.PrintMessage(key, true);
                //var parameters = ParameterUtility.ConvertParameterObjectToStrings(o);
                //foreach (var parameter in parameters)
                //{
                //    Logger.PrintMessage("\t" + parameter, true);
                //}

                //var mappings = ParameterUtility.ExtractParameterMapObjects(o, key);
                //allmappings.AddRange(mappings);
            }

            var assemblyData = ApplicationUtility.GetAssemblyData();
            var assemblyMap = new ParameterHibernateMapping
            {
                OptionGroup = "Assembly Info",
                Parameter = "Version",
                Value = assemblyData
            };
            allmappings.Add(assemblyMap);

            var systemData = ApplicationUtility.GetSystemData();
            var systemMap = new ParameterHibernateMapping
            {
                OptionGroup = "Assembly Info",
                Parameter = "System Info",
                Value = systemData
            };
            allmappings.Add(systemMap);

            if (insertIntoDatabase)
            {
                Logger.PrintMessage("Writing parameters to the analysis database.");
                var parameterCache = new GenericDAOHibernate<ParameterHibernateMapping>();
                parameterCache.AddAll(allmappings);
            }
        }