Example #1
0
        public override IEnumerable <string> Process()
        {
            var result = new List <string>();

            var titleParser = options.GetTitleParser();
            var writer      = new MascotGenericFormatWriter <Peak>();

            Progress.SetRange(0, options.InputFiles.Count);
            int count = 0;

            foreach (var file in options.InputFiles)
            {
                count++;

                string resultFilename = options.GetOutputFile(file);
                Progress.SetMessage("Processing {0}/{1} : {2} ...", count, options.InputFiles.Count, file);

                var tempFile = resultFilename + ".tmp";
                using (var sw = new StreamWriter(tempFile))
                {
                    sw.WriteLine("###ShiftMass={0:0.#}", options.ShiftMass);
                    sw.WriteLine("###ShiftScan={0}", options.ShiftScan);
                    sw.WriteLine();

                    using (var sr = new StreamReader(new FileStream(file, FileMode.Open)))
                    {
                        var iter = new MascotGenericFormatIterator <Peak>(sr);
                        while (iter.HasNext())
                        {
                            if (Progress.IsCancellationPending())
                            {
                                throw new UserTerminatedException();
                            }

                            var pkl = iter.Next();

                            UpdatePrecursor(titleParser, pkl, options.ShiftMass, options.ShiftScan);

                            writer.Write(sw, pkl);
                        }
                    }
                }

                if (File.Exists(resultFilename))
                {
                    File.Delete(resultFilename);
                }

                File.Move(tempFile, resultFilename);

                result.Add(resultFilename);
            }
            Progress.End();

            return(result);
        }
Example #2
0
        public List <PeakList <T> > ReadFromFile(string filename)
        {
            var fi = new FileInfo(filename);

            if (!fi.Exists)
            {
                throw new FileNotFoundException("Cannot find the file " + filename);
            }
            String experimental = FileUtils.ChangeExtension(fi.Name, "");

            var result = new List <PeakList <T> >();
            var sr     = new StreamReader(new FileStream(filename, FileMode.Open));

            try
            {
                var iter = new MascotGenericFormatIterator <T>(sr);

                while (iter.HasNext())
                {
                    if (Progress.IsCancellationPending())
                    {
                        throw new UserTerminatedException();
                    }

                    var pkl = iter.Next();
                    if (pkl.Experimental == null || pkl.Experimental.Length == 0)
                    {
                        pkl.Experimental = experimental;
                    }
                    result.Add(pkl);
                }
            }
            finally
            {
                sr.Close();
            }

            return(result);
        }