Ejemplo n.º 1
0
        public void TestRead()
        {
            var mods = MaxQuantModificationList.ReadFromFile(TestContext.CurrentContext.TestDirectory + "/../../../data/maxquant_modifications.xml");

            Assert.AreEqual(550, mods.Count);
            Assert.AreEqual("Acetyl (K)", mods[0].FullName);
            Assert.AreEqual("(ac)", mods[0].ShortName);
            Assert.AreEqual("C2H2O", mods[0].Composition.ToString());
            Assert.AreEqual("Cysteinyl - carbamidomethyl", mods[549].FullName);
            Assert.AreEqual("(cy)", mods[549].ShortName);
            Assert.AreEqual("CH2OS", mods[549].Composition.ToString());
        }
        public List <IIdentifiedSpectrum> ExtractPeptides(Dictionary <string, MaxQuantModificationItem> shortModMap, string peptideFile)
        {
            var mods = MaxQuantModificationList.ReadFromFile(_option.MaxQuantModificationXml);

            var sites   = new AnnotationFormat().ReadFromFile(_option.MaxQuantSiteFile);
            var msmsIds = new HashSet <string>(from s in sites
                                               let msmsids = s.Annotations["MS/MS IDs"] as string
                                                             let msmsIdList = msmsids.Split(';')
                                                                              from msmsId in msmsIdList
                                                                              select msmsId);
            var format   = new AnnotationFormat();
            var msmsList = format.ReadFromFile(_option.MaxQuantMSMSFile);

            msmsList.RemoveAll(l => !msmsIds.Contains(l.Annotations["id"].ToString()));

            using (var sw = new StreamWriter(peptideFile))
            {
                sw.WriteLine("FileScan\tSequence\tMH+\tDiff(MH+)\tCharge\tScore\tReference\tModification\tRetentionTime");
                foreach (var msms in msmsList)
                {
                    string modification;
                    string modifiedSequence;

                    ParseModification(msms, shortModMap, mods, out modification, out modifiedSequence);

                    var mh      = double.Parse(msms.Annotations["Mass"].ToString()) + Atom.H.MonoMass;
                    var diffStr = msms.Annotations["Mass Error [ppm]"].ToString();
                    var diffmh  = diffStr.Equals("NaN") ? 0 : PrecursorUtils.ppm2mz(mh, double.Parse(diffStr));

                    sw.WriteLine("{0},{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}",
                                 msms.Annotations["Raw file"],
                                 msms.Annotations["Scan number"],
                                 modifiedSequence,
                                 mh,
                                 diffmh,
                                 msms.Annotations["Charge"],
                                 msms.Annotations["Score"],
                                 msms.Annotations["Proteins"].ToString().Replace(";", "/"),
                                 modification,
                                 msms.Annotations["Retention time"]);
                }
            }

            return(new MascotPeptideTextFormat().ReadFromFile(peptideFile));
        }
Ejemplo n.º 3
0
        public static MaxQuantModificationList ReadFromFile(string fileName)
        {
            var result = new MaxQuantModificationList();

            var doc   = XDocument.Load(fileName);
            var items = (from mod in doc.Descendants("modification")
                         let fullName = mod.Attribute("title").Value
                                        let shortName = "(" + fullName.Substring(0, 2).ToLower() + ")"
                                                        select new MaxQuantModificationItem()
            {
                FullName = fullName,
                ShortName = shortName,
                Composition = new AtomComposition(mod.Attribute("composition").Value.Replace(" ", "").Replace("(", "").Replace(")", ""))
            }).ToList();

            result.AddRange(items);
            return(result);
        }
        private void ParseModification(Annotation msms, Dictionary <string, MaxQuantModificationItem> modCharMap, MaxQuantModificationList mods, out string modification, out string modifiedSequence)
        {
            var seq = msms.Annotations["Modified sequence"].ToString();

            seq = ReplaceModificationStringToChar(seq, modCharMap);
            seq = seq.Replace("_", "");

            Match m = modReg.Match(seq);

            if (m.Success)
            {
                var modMap = (from mo in msms.Annotations["Modifications"].ToString().Split(',')
                              let mof = Regex.Replace(mo, "^\\d+\\s+", "")
                                        let shortName = "(" + mof.Substring(0, 2).ToLower() + ")"
                                                        select new { FullName = mof, ShortName = shortName }).ToDictionary(l => l.ShortName, l => l.FullName);

                while (m.Success)
                {
                    string mod = m.Groups[1].Value;
                    if (!modCharMap.ContainsKey(mod))
                    {
                        var fullName = modMap[mod];
                        modCharMap[mod]        = mods.Find(l => l.FullName.Equals(fullName));
                        modCharMap[mod].Symbol = ModificationConsts.MODIFICATION_CHAR.Substring(modCharMap.Count + 1, 1);
                    }
                    m = m.NextMatch();
                }

                seq = ReplaceModificationStringToChar(seq, modCharMap);
            }

            modifiedSequence = seq;
            modification     = msms.Annotations["Modifications"].ToString();
        }