public override IEnumerable <string> Process(string fileName) { double offsetPPM; if (!FindOffset(fileName, out offsetPPM)) { return(new string[] { }); } string resultFilename = new FileInfo(targetDir + "\\" + new FileInfo(fileName).Name).FullName; var writer = new MascotGenericFormatWriter <Peak>(); using (StreamReader sr = new StreamReader(new FileStream(fileName, FileMode.Open))) { var iter = new MascotGenericFormatIterator <Peak>(sr); using (StreamWriter sw = new StreamWriter(resultFilename)) { while (iter.HasNext()) { if (Progress.IsCancellationPending()) { throw new UserTerminatedException(); } if (IsLoopStopped) { return(new string[] { }); } var pkl = iter.Next(); pkl.PrecursorMZ = pkl.PrecursorMZ + PrecursorUtils.ppm2mz(pkl.PrecursorMZ, offsetPPM); writer.Write(sw, pkl); } } } return(new List <string>(new[] { resultFilename })); }
public override IEnumerable <string> Process(string mgfFilename) { String mgfName = Path.GetFileNameWithoutExtension(mgfFilename); using (var sw = new StreamWriter(targetFile)) { sw.WriteLine("H\tCreationDate\t{0:yyyyMMdd}", DateTime.Now); sw.WriteLine("H\tExtractor\tProteomicsTools"); using (var sr = new StreamReader(mgfFilename)) { bool bProcessing = sr.BaseStream.Length > 0; var reader = new MascotGenericFormatIterator <Peak>(sr); this.scanIndex = 0; if (bProcessing) { Progress.SetMessage("Converting " + mgfFilename + " ..."); Progress.SetRange(0, sr.BaseStream.Length); } Progress.SetPosition(0); while (reader.HasNext()) { if (Progress.IsCancellationPending()) { throw new UserTerminatedException(); } PeakList <Peak> pkl = reader.Next(); if (bProcessing) { Progress.SetPosition(sr.BaseStream.Position); } int[] charges; if (0 != pkl.PrecursorCharge) { charges = new[] { pkl.PrecursorCharge }; } else if (IsWiff(pkl)) { charges = new[] { 1 }; } else { charges = new[] { 2, 3 }; } var sf = GetFilename(pkl, mgfName); sw.WriteLine("S\t{0}\t{1}\t{2}", sf.FirstScan, sf.LastScan, pkl.PrecursorMZ); foreach (var charge in charges) { sw.WriteLine("Z\t{0}\t{1:0.#####}", charge, PrecursorUtils.MzToMH(pkl.PrecursorMZ, charge, true)); } foreach (var peak in pkl) { sw.WriteLine("{0:0.#####}\t{1:0.#}", peak.Mz, peak.Intensity); } } Progress.SetMessage("Converting " + mgfFilename + " finished."); } } return(new[] { this.targetFile }); }