public void TestReadFromITMS()
 {
   var reader = new MascotGenericFormatReader<Peak>();
   List<PeakList<Peak>> pls = reader.ReadFromFile(@"../../../data/DHBS0001_4FR_R01.mgf");
   Assert.AreEqual(2439, pls.Count);
   Assert.AreEqual(1242.05, pls[pls.Count - 1].PrecursorMZ);
   Assert.AreEqual(4629, pls[pls.Count - 1].PrecursorIntensity);
   Assert.AreEqual(0, pls[pls.Count - 1].PrecursorCharge);
 }
 public void TestReadFromMaldiTof()
 {
   var reader = new MascotGenericFormatReader<Peak>();
   List<PeakList<Peak>> pls = reader.ReadFromFile(@"../../../data/pps_192 LC_1141485233.txt");
   Assert.AreEqual(81, pls.Count);
   Assert.AreEqual(2869.9788, pls[pls.Count - 1].PrecursorMZ);
   Assert.AreEqual(0.0, pls[pls.Count - 1].PrecursorIntensity);
   Assert.AreEqual(1, pls[pls.Count - 1].PrecursorCharge);
 }
        private static Dictionary <string, PeakList <Peak> > ReadPeakMap(string file, ITitleParser parser)
        {
            var reader = new MascotGenericFormatReader <Peak>();
            List <PeakList <Peak> > hList = reader.ReadFromFile(file);

            return(hList.ToDictionary(m =>
            {
                var filename = parser.GetValue(m.Annotations[MascotGenericFormatConstants.TITLE_TAG] as string);
                if (string.IsNullOrEmpty(m.Experimental))
                {
                    m.Experimental = filename.Experimental;
                }
                if (m.FirstScan == 0)
                {
                    m.FirstScan = filename.FirstScan;
                }
                if (filename.Charge > 0)
                {
                    m.PrecursorCharge = filename.Charge;
                }
                return filename.FirstScan.ToString();
            }));
        }
Beispiel #4
0
        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 });
        }