Esempio n. 1
0
 private bool LoadParserConfig(CommandLineOptions options, out ParserConfig config)
 {
     config = new ParserConfig();
     if (options.ParserConfig != null)
     {
         try
         {
             config = ParserConfig.LoadFromJSON(options.ParserConfig);
             if (config == null)
             {
                 _logger.LogException(string.Format(
                                          "error reading parser configuration JSON object, " +
                                          "check if the given file '{0}' exists and is accessible.",
                                          options.ParserConfig));
                 return(false);
             }
         }
         catch (Exception e)
         {
             _logger.LogException("error reading parser configuration JSON object: " + e.Message);
             Environment.ExitCode = 1;
             return(false);
         }
     }
     return(true);
 }
Esempio n. 2
0
        public Bed <Peak> LoadSample(string fileName, ParserConfig parserConfig)
        {
            var bedParser = new BedParser(parserConfig)
            {
                PValueFormat           = parserConfig.PValueFormat,
                DefaultValue           = parserConfig.DefaultValue,
                DropPeakIfInvalidValue = parserConfig.DropPeakIfInvalidValue
            };
            var parsedSample = bedParser.Parse(fileName);

            _samples.Add(parsedSample);
            return(parsedSample);
        }
Esempio n. 3
0
        private bool ParseFiles(IReadOnlyList <string> files, ParserConfig parserConfig, out List <Bed <Peak> > samples)
        {
            try
            {
                samples = new List <Bed <Peak> >();
                _logger.LogStartOfASection("Parsing Samples");
                _logger.InitializeLoggingParser(files.Count);

                int counter = 0;
                foreach (var file in files)
                {
                    var bedParser = new BedParser(parserConfig)
                    {
                        PValueFormat           = parserConfig.PValueFormat,
                        DefaultValue           = parserConfig.DefaultValue,
                        DropPeakIfInvalidValue = parserConfig.DropPeakIfInvalidValue,
                        Culture = parserConfig.Culture
                    };
                    var parsedData = bedParser.Parse(file);
                    samples.Add(parsedData);
                    counter++;
                    _logger.LogParser(
                        counter,
                        files.Count,
                        file,
                        parsedData.IntervalsCount,
                        parsedData.PValueMin.Value,
                        parsedData.PValueMean,
                        parsedData.PValueMax.Value);
                }

                return(true);
            }
            catch (Exception e)
            {
                samples = null;
                _logger.LogException("error parsing data: " + e.Message);
                Environment.ExitCode = 1;
                return(false);
            }
        }
Esempio n. 4
0
        public static void Main(string[] args)
        {
            string mspcCannotContinue = "\r\nMSPC cannot continue.";
            var    cliOptions         = new CommandLineOptions();

            try
            {
                cliOptions.Parse(args, out bool helpIsDisplayed);
                if (helpIsDisplayed)
                {
                    return;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + mspcCannotContinue);
                return;
            }

            if (cliOptions.Input.Count < 2)
            {
                Console.WriteLine(string.Format(
                                      "At least two samples are required; {0} is given.{1}",
                                      cliOptions.Input.Count, mspcCannotContinue));
                return;
            }

            foreach (var file in cliOptions.Input)
            {
                if (!File.Exists(file))
                {
                    Console.WriteLine(string.Format("Missing file: {0}{1}", file, mspcCannotContinue));
                    return;
                }
            }

            var orchestrator = new Orchestrator(cliOptions.Options);

            var parserConfig = new ParserConfig();

            if (cliOptions.ParserConfig != null)
            {
                parserConfig = ParserConfig.LoadFromJSON(cliOptions.ParserConfig);
            }

            var et = new Stopwatch();

            foreach (var file in cliOptions.Input)
            {
                Console.WriteLine(string.Format("Parsing sample: {0}", file));
                et.Restart();

                var parsedSample = orchestrator.LoadSample(file, parserConfig);
                et.Stop();
                Console.WriteLine("Done...  ET:\t{0}", et.Elapsed.ToString());
                Console.WriteLine("Read peaks#:\t{0}", parsedSample.IntervalsCount.ToString("N0", CultureInfo.InvariantCulture));
                Console.WriteLine("Min p-value:\t{0}", string.Format("{0:E3}", parsedSample.PValueMin.Value));
                Console.WriteLine("Max p-value:\t{0}", string.Format("{0:E3}", parsedSample.PValueMax.Value));
                Console.WriteLine("");
            }

            Console.WriteLine("Analysis started ...");
            et.Restart();
            orchestrator.Run();

            Console.WriteLine("\n\rSaving results ...");
            orchestrator.Export();

            et.Stop();
            Console.WriteLine(" ");
            Console.WriteLine(string.Format("All processes successfully finished [Analysis ET: {0}]", et.Elapsed.ToString()));
            Console.WriteLine(" ");

            orchestrator.WriteSummaryStats();
        }