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);
        }
Ejemplo n.º 2
0
        public List <IIdentifiedSpectrum> ReadFromFile(string fileName)
        {
            var result = baseParser.ReadFromFile(fileName);

            var resultMap = result.ToDictionary(m => m.Id.ToString());

            var input = GetInputFile(fileName);

            using (var sr = new StreamReader(input))
            {
                string line;

                while ((line = sr.ReadLine()) != null)
                {
                    if (line.Contains("<fragSpectrumScan"))
                    {
                        var scanNumber = line.StringAfter("scanNumber=\"").StringBefore("\"");
                        IIdentifiedSpectrum spec;
                        if (resultMap.TryGetValue(scanNumber, out spec))
                        {
                            line     = sr.ReadLine();
                            spec.Tag = line.StringAfter("id=\"").StringBefore("\"");
                        }
                        else
                        {
                            Console.WriteLine("Cannot find {0} in database", scanNumber);
                        }
                    }
                }
            }

            result.ForEach(m =>
            {
                if (string.IsNullOrEmpty(m.Tag))
                {
                    Console.WriteLine("Cannot find query {0} at input file, score {1}", m.Query.FileScan.LongFileName, m.Score);
                }
            });

            var inputMap = result.Where(m => !string.IsNullOrEmpty(m.Tag)).ToDictionary(m => m.Tag);

            var      output = GetOutputFile(fileName);
            XElement root   = XElement.Load(output);
            var      psms   = root.FindElement("psms").FindElements("psm");

            foreach (var psm in psms)
            {
                var id = psm.FindAttribute("psm_id").Value;
                IIdentifiedSpectrum spec;
                if (inputMap.TryGetValue(id, out spec))
                {
                    spec.SpScore = double.Parse(psm.FindElement("svm_score").Value);
                }
            }

            return(result);
        }