Ejemplo n.º 1
0
        /// <summary>
        ///     Starts a multi-Align analysis job.
        /// </summary>
        public void StartAnalysis(AnalysisConfig config)
        {
            m_config = config;

            if (m_algorithms == null)
            {
                throw new NullReferenceException("The algorithms have not been set for this analysis.");
            }

            if (config.Analysis == null)
            {
                throw new NullReferenceException("The analysis data storage cannot be null.");
            }

            if (config.Analysis.DataProviders == null)
            {
                throw new NullReferenceException("The data cache providers have not been set for this analysis.");
            }
            Logger.LogPath = AnalysisPathUtils.BuildLogPath(config.AnalysisPath, config.AnalysisName);

            // Make sure we start with a fresh analysis.
            AbortAnalysisThread(m_analysisThread);

            var threadStart = new ThreadStart(PerformAnalysis);

            m_analysisThread = new Thread(threadStart);
            m_analysisThread.Start();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static int Main(string[] args)
        {
            var handle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;

            SetConsoleMode(handle, ENABLE_EXTENDED_FLAGS);

            var clusterIdMap = new Dictionary <int, UMCClusterLight>();

            try
            {
                if (args.Length < 2)
                {
                    Console.WriteLine("MultiAlignSTACRunner crosstabDirectory databasePath outputName");
                    Console.WriteLine("\tThe cross-tab file will be named similar to the database path");
                    return(1);
                }

                // Setup the analysis processing
                Logger.PrintMessage("Find all datasets", true);
                var directoryPath = args[0].Replace("\r", "").Replace("\n", "");
                var databasePath  = args[1].Replace("\r", "").Replace("\n", "");
                var name          = args[2].Replace("\r", "").Replace("\n", "");
                var files         = Directory.GetFiles(directoryPath, "*.csv");

                Logger.PrintMessage("Creating Log File");
                var loggerPath = AnalysisPathUtils.BuildLogPath(Path.GetDirectoryName(name), Path.GetFileNameWithoutExtension(name));
                Logger.LogPath = loggerPath;
                Logger.PrintMessage("Saving Log Data to: " + loggerPath);


                Logger.PrintMessage(string.Format("Creating STAC"), true);

                // Hardcode bad, but per discussions with OHSU
                var stac = new STACAdapter <UMCClusterLight>
                {
                    Options = new FeatureMatcherParameters
                    {
                        UserTolerances =
                        {
                            MassTolerancePPM   =   25,
                            NETTolerance       = .035,
                            DriftTimeTolerance = 3
                        },
                        UseDriftTime = true
                    }
                };


                var clusterFilteringOptions = new FilteringOptions();

                WriteOptionsToLogFile(clusterFilteringOptions);
                WriteOptionsToLogFile(stac.Options);


                // Read the cluster data
                var allClusters = new List <UMCClusterLight>();
                var clusterId   = 0;
                foreach (var file in files)
                {
                    var filename = Path.GetFileName(file);
                    Logger.PrintMessage(string.Format("Reading {0}", filename));
                    const string chargeString = "charge";

                    if (filename == null)
                    {
                        continue;
                    }

                    if (!filename.Contains(chargeString))
                    {
                        continue;
                    }

                    // Read each file.
                    var start = DateTime.Now;

                    var xname = filename.Replace("_", "");
                    // ReSharper disable once StringIndexOfIsCultureSpecific.1
                    var indexOfChargeString = xname.IndexOf(chargeString);
                    var charge = Convert.ToInt32(xname.Substring(indexOfChargeString + chargeString.Length, 1));

                    var clusters = ReadClusters(file, clusterFilteringOptions);
                    var end      = DateTime.Now;
                    Logger.PrintMessage(string.Format("\tReading Took {0:.00} seconds", end.Subtract(start).TotalSeconds));

                    foreach (var cluster in clusters)
                    {
                        clusterIdMap.Add(clusterId, cluster);
                        cluster.Id          = clusterId++;
                        cluster.ChargeState = charge;
                    }

                    allClusters.AddRange(clusters);
                }


                // Load the database
                Logger.PrintMessage(string.Format("Loading Mass Tag Database: {0}", Path.GetFileNameWithoutExtension(databasePath)));
                var options            = new MassTagDatabaseOptions();
                var databaseDefinition = new InputDatabase
                {
                    DatabaseFormat = MassTagDatabaseFormat.Sqlite,
                    LocalPath      = databasePath
                };
                var database = MtdbLoaderFactory.LoadMassTagDatabase(databaseDefinition, options);

                // Run stac
                try
                {
                    Logger.PrintMessage("Matching clusters to peptides in mass tag database.");
                    var matches = stac.PerformPeakMatching(allClusters, database);

                    Logger.PrintMessage(string.Format("Writing Results To {0}", name));
                    var duplicateMatches = new Dictionary <int, Dictionary <int, FeatureMatchLight <UMCClusterLight, MassTagLight> > >();

                    foreach (var match in matches)
                    {
                        if (!duplicateMatches.ContainsKey(match.Observed.Id))
                        {
                            duplicateMatches.Add(match.Observed.Id, new Dictionary <int, FeatureMatchLight <UMCClusterLight, MassTagLight> >());
                        }

                        if (!duplicateMatches[match.Observed.Id].ContainsKey(match.Target.Id))
                        {
                            duplicateMatches[match.Observed.Id].Add(match.Target.Id, match);
                        }
                    }
                    WriteClusterData(name, duplicateMatches, clusterIdMap);


                    Logger.PrintMessage("ANALYSIS SUCCESS");
                    return(0);
                }
                catch (Exception ex)
                {
                    Logger.PrintMessage("Unhandled Error: " + ex.Message);
                    var innerEx = ex.InnerException;
                    while (innerEx != null)
                    {
                        Logger.PrintMessage("Inner Exception: " + innerEx.Message);
                        innerEx = innerEx.InnerException;
                    }
                    Logger.PrintMessage("Stack: " + ex.StackTrace);
                    Logger.PrintMessage("");
                    Logger.PrintMessage("ANALYSIS FAILED");
                    return(1);
                }
            }
            catch (Exception ex)
            {
                Logger.PrintMessage("Unhandled Error: " + ex.Message, true);
                var innerEx = ex.InnerException;
                while (innerEx != null)
                {
                    Logger.PrintMessage("Inner Exception: " + innerEx.Message);
                    innerEx = innerEx.InnerException;
                }
                Logger.PrintMessage("Stack: " + ex.StackTrace, true);
                Logger.PrintMessage("");
                Logger.PrintMessage("ANALYSIS FAILED");
                return(1);
            }
        }