Ejemplo n.º 1
0
        public override IEnumerable <string> Process()
        {
            var searchEngine = EnumUtils.StringToEnum <SearchEngineType>(options.EngineType, SearchEngineType.Unknown);
            var factory      = searchEngine.GetFactory();

            string suffix = options.Rank2 ? ".rank2" : string.Empty;
            var    result = new List <string>();

            foreach (var inputfile in options.InputFiles)
            {
                ISpectrumParser parser = factory.GetParser(inputfile, options.Rank2);
                if (!string.IsNullOrEmpty(options.TitleType))
                {
                    parser.TitleParser = TitleParserUtils.FindByName(options.TitleType);
                }
                parser.Progress = this.Progress;

                Progress.SetMessage("Parsing " + inputfile + "...");
                var spectra = parser.ReadFromFile(inputfile);
                var format  = factory.GetPeptideFormat(true);

                var outputFile = string.IsNullOrEmpty(options.OutputFile) ? inputfile + suffix + ".peptides" : options.OutputFile;
                Progress.SetMessage("Writing {0} PSMs to {1}...", spectra.Count, outputFile);
                format.WriteToFile(outputFile, spectra);

                result.Add(outputFile);
            }

            return(result);
        }
        public override bool PrepareOptions()
        {
            foreach (var inputfile in this.InputFiles)
            {
                if (!File.Exists(inputfile))
                {
                    ParsingErrors.Add(string.Format("Input file not exists {0}.", inputfile));
                }
            }

            var engine = GetSearchEngineType();

            if (engine == SearchEngineType.Unknown)
            {
                if (!this.EngineType.ToLower().Equals("help"))
                {
                    ParsingErrors.Add(string.Format("Unknown search engine type {0}", this.EngineType));
                }
                ParsingErrors.Add(string.Format("  Those engines are valid: {0}", (GetValidEngines()).Merge(", ")));
            }

            if (!string.IsNullOrEmpty(TitleType) && TitleParserUtils.FindByName(TitleType) == null)
            {
                if (!this.TitleType.ToLower().Equals("help"))
                {
                    ParsingErrors.Add(string.Format("Unknown title type {0}.", this.TitleType));
                }
                ParsingErrors.Add("  Those titles are valid:");
                (from t in TitleParserUtils.GetTitleParsers()
                 select t.FormatName).ToList().ForEach(m => ParsingErrors.Add("    " + m));
            }

            if (Rank2 && engine != SearchEngineType.Unknown)
            {
                foreach (var inputfile in InputFiles)
                {
                    try
                    {
                        var parser = engine.GetFactory().GetParser(inputfile, this.Rank2);
                    }
                    catch (Exception ex)
                    {
                        ParsingErrors.Add(ex.Message);
                        break;
                    }
                }
            }

            return(ParsingErrors.Count == 0);
        }