public Raw2MgfProcessor(MultipleRaw2MgfOptions options) : base(options) { this.options = options; this.Writer = options.GetMGFWriter(); this.swMap = new Dictionary <string, StreamWriter>(); this.outputFiles = new List <string>(); }
public MascotGenericFormatWriter <Peak> GetMGFWriter() { var result = new MascotGenericFormatWriter <Peak>() { TitleFormat = MascotTitleFactory.FindTitleOrDefault(MascotTitleName) }; result.Comments.Clear(); result.Comments.Add("Converter=" + ConverterName); result.Comments.Add("ConverterVersion=" + ConverterVersion); result.Comments.Add("DefaultCharges=" + DefaultCharges.ToString()); result.Comments.Add("ProductIonPPM=" + ProductIonPPM.ToString()); result.DefaultCharges = this.DefaultCharges.DefaultCharges; return(result); }
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 targetFile) { var hMap = ReadPeakMap(option.HeaderFile, option.HeaderParser); var pMap = ReadPeakMap(option.PeakFile, option.PeakParser); var mgfFormat = new MascotGenericFormatWriter <Peak>(); foreach (var key in pMap.Keys) { if (hMap.ContainsKey(key)) { pMap[key].PrecursorMZ = hMap[key].PrecursorMZ; pMap[key].PrecursorCharge = hMap[key].PrecursorCharge; } } var result = pMap.Values.ToList(); //foreach (var key in hMap.Keys) //{ // if (!pMap.ContainsKey(key)) // { // result.Add(pMap[key]); // } //} foreach (var v in result) { v.Annotations.Remove(MascotGenericFormatConstants.TITLE_TAG); } result.Sort((m1, m2) => m1.FirstScan - m2.FirstScan); option.Writer.WriteToFile(targetFile, result); return(new string[] { targetFile }); }
public override IEnumerable <string> Process(string fileName) { var result = new FileInfo(targetDir + "\\" + Path.ChangeExtension(new FileInfo(fileName).Name, ".mgf")).FullName; int charge = 1; PeakList <Peak> ms1 = new PeakList <Peak>(); //读取ms1 List <string> comments = new List <string>(); comments.Add("COM=" + software); using (StreamReader sr = new StreamReader(fileName)) { string line; while ((line = sr.ReadLine()) != null) { if (line.StartsWith("COM=")) { comments.Add(line); continue; } if (line.StartsWith("BEGIN IONS")) { break; } comments.Add(line); var parts = line.Split('\t'); if (parts.Length == 2) { try { ms1.Add(new Peak(double.Parse(parts[0]), double.Parse(parts[1]))); } catch (Exception) { } } } } MascotGenericFormatReader <Peak> reader = new MascotGenericFormatReader <Peak>(); var pkls = reader.ReadFromFile(fileName); foreach (var pkl in pkls) { var mzTolerance = PrecursorUtils.ppm2mz(pkl.PrecursorMZ, precursorTolerance); var peak = ms1.FindPeak(pkl.PrecursorMZ, mzTolerance).FindMaxIntensityPeak(); if (peak == null) { pkl.PrecursorIntensity = ms1.Min(m => m.Intensity); } else { pkl.PrecursorIntensity = peak.Intensity; } } pkls.Sort((m1, m2) => m2.PrecursorIntensity.CompareTo(m1.PrecursorIntensity)); for (int i = 0; i < pkls.Count; i++) { var line = pkls[i].Annotations[MascotGenericFormatConstants.TITLE_TAG] as string; var m = reg.Match(line); string experimental; if (m.Success) { experimental = m.Groups[1].Value; var m2 = nameReg.Match(experimental); if (m2.Success) { if (m2.Groups[2].Value.Length == 1) { experimental = m2.Groups[1].Value + "0" + m2.Groups[2].Value; } } } else { experimental = pkls[i].Experimental; } pkls[i].Annotations[MascotGenericFormatConstants.TITLE_TAG] = string.Format("{0}.{1}.{2:0}.{3}.dta", experimental, i + 1, pkls[i].PrecursorIntensity, charge); } var writer = new MascotGenericFormatWriter <Peak>(); writer.Comments.AddRange(comments); writer.WriteToFile(result, pkls); return(new string[] { result }); }