Exemple #1
0
        protected Dictionary <string, string> ParseSection(StreamReader sr, string sectionName, string lineRegexStr, bool required = true)
        {
            string line;

            SectionClass sc = new SectionClass(sectionName);

            while ((line = sr.ReadLine()) != null)
            {
                if (sc.IsStartLine(line))
                {
                    break;
                }
            }

            if (line == null)
            {
                if (required)
                {
                    throw new Exception("Cannot find " + sectionName + " information when parsing dat file.");
                }
                else
                {
                    return(new Dictionary <string, string>());
                }
            }

            Regex lineRegex = null;

            if (lineRegexStr != null && lineRegexStr.Length > 0)
            {
                lineRegex = new Regex(lineRegexStr);
            }

            var result = new Dictionary <string, string>();

            while ((line = sr.ReadLine()) != null)
            {
                if (IsSectionEnd(line))
                {
                    break;
                }

                if (line.Trim().Length == 0)
                {
                    continue;
                }

                if (lineRegex == null || lineRegex.Match(line).Success)
                {
                    Match m = this.keyValueRegex.Match(line);
                    if (m.Success)
                    {
                        result[m.Groups[1].Value] = m.Groups[2].Value.Trim();
                    }
                }
            }
            return(result);
        }
Exemple #2
0
        protected Protease ParseEnzyme(StreamReader sr)
        {
            SectionClass sc = new SectionClass("enzyme");
            string       line;

            //find enzyme section
            while ((line = sr.ReadLine()) != null)
            {
                if (sc.IsStartLine(line))
                {
                    break;
                }
            }

            string name         = "";
            string cleavage     = "";
            string uncleavage   = "";
            bool   cterm        = false;
            bool   semiSpecific = false;

            while ((line = sr.ReadLine()) != null)
            {
                if (IsSectionEnd(line))
                {
                    break;
                }

                if (line.StartsWith("Title"))
                {
                    name = line.Substring(line.IndexOf(':') + 1);
                }
                else if (line.StartsWith("Cleavage"))
                {
                    cleavage = line.Substring(line.IndexOf(':') + 1);
                }
                else if (line.StartsWith("Restrict"))
                {
                    uncleavage = line.Substring(line.IndexOf(':') + 1);
                }
                else if (line.StartsWith("Cterm"))
                {
                    cterm = true;
                }
                else if (line.StartsWith("SemiSpecific"))
                {
                    semiSpecific = true;
                }
            }

            return(new Protease(name, cterm, cleavage, uncleavage)
            {
                IsSemiSpecific = semiSpecific
            });
        }
Exemple #3
0
        protected Dictionary <int, MascotQueryItem> ParseQueryItems(StreamReader sr, int queryCount, string prefix = "")
        {
            string line;

            SectionClass sc = new SectionClass(prefix + "summary");

            while ((line = sr.ReadLine()) != null)
            {
                if (sc.IsStartLine(line))
                {
                    break;
                }
            }

            var result = new Dictionary <int, MascotQueryItem>();

            while ((line = sr.ReadLine()) != null)
            {
                if (IsSectionEnd(line))
                {
                    break;
                }

                if (line.StartsWith("qmass"))
                {
                    Match m = queryIdRegex.Match(line);

                    var item = new MascotQueryItem();

                    item.QueryId          = Convert.ToInt32(m.Groups[1].Value);
                    item.ExperimentalMass = MyConvert.ToDouble(m.Groups[2].Value);

                    line = sr.ReadLine();
                    Match precursor = this.precursorRegex.Match(line);
                    if (precursor.Success)
                    {
                        item.Observed = MyConvert.ToDouble(precursor.Groups[1].Value);
                        item.Charge   = int.Parse(precursor.Groups[2].Value);
                    }
                    else
                    {
                        var pmr = this.precursorMrRegex.Match(line);
                        item.Observed = MyConvert.ToDouble(pmr.Groups[1].Value);
                        item.Charge   = 0;
                    }

                    line = sr.ReadLine();
                    if (line.StartsWith("qintensity"))
                    {
                        item.Intensity = MyConvert.ToDouble(GetValue(line));
                        line           = sr.ReadLine();
                    }

                    if (line.StartsWith("qmatch"))
                    {
                        item.MatchCount = Convert.ToInt32(GetValue(line));
                        line            = sr.ReadLine();
                    }

                    if (line.StartsWith("qplughole"))
                    {
                        item.HomologyScore = Convert.ToDouble(GetValue(line));
                    }

                    result[item.QueryId] = item;
                }
            }

            return(result);
        }
Exemple #4
0
        public void TestSectionClass()
        {
            SectionClass sc = new SectionClass("parameters");

            Assert.IsTrue(sc.IsStartLine("Content-Type: application/x-Mascot; name=\"parameters\""));
        }