Esempio n. 1
0
        public CharacterParser AddCharacterForTitle(TitleParser title, bool adult = false)
        {
            CharacterParser chr = CharacterManager.instance.GetNewCharacter();
            chr.GiveTitle(title);
            if (title.Rank > 0)
                characters.Add(chr);

            return chr;
        }
Esempio n. 2
0
        public CharacterParser AddCharacterForTitle(TitleParser title, String culture, String religion)
        {
            CharacterParser chr = CharacterManager.instance.CreateNewCharacter(culture, religion, Rand.Next(8) == 0);
            chr.GiveTitle(title);
            if (title.Rank > 0)
                characters.Add(chr);

            return chr;
        }
Esempio n. 3
0
        public void test_line_matches_valid_title()
        {
            // Arrange
            var parser = new TitleParser(titleInfoFunc);

            // Act
            bool result = parser.IsPublisher("Blah");

            //Assert
            Assert.False(result);
        }
Esempio n. 4
0
        public void test_line_matches_known_publisher()
        {
            // Arrange
            var parser = new TitleParser(titleInfoFunc);

            // Act
            bool result = parser.IsPublisher("MARVEL");

            //Assert
            Assert.True(result);
        }
Esempio n. 5
0
        public CharacterParser AddCharacterForTitle(TitleParser title, String culture, String religion)
        {
            CharacterParser chr = CharacterManager.instance.CreateNewCharacter(culture, religion, Rand.Next(8) == 0);

            chr.GiveTitle(title);
            if (title.Rank > 0)
            {
                characters.Add(chr);
            }

            return(chr);
        }
Esempio n. 6
0
        public CharacterParser AddCharacterForTitle(TitleParser title, bool adult = false)
        {
            CharacterParser chr = CharacterManager.instance.GetNewCharacter();

            chr.GiveTitle(title);
            if (title.Rank > 0)
            {
                characters.Add(chr);
            }

            return(chr);
        }
Esempio n. 7
0
    public void TestCmpd2()
    {
      ParserItem item = new ParserItem();
      ParserFormat format = new ParserFormat();
      format.FormatName = "TurboRAW2MGF, Cmpd";
      format.Add(new ParserItem("rawFile", ""));
      format.Add(new ParserItem("scanNumber", @"Cmpd\s*(\d+)\s*,"));

      TitleParser parser = new TitleParser(format);
      SequestFilename sf = parser.GetValue("Cmpd 2345, xxxxx");
      Assert.AreEqual(2345, sf.FirstScan);
      Assert.AreEqual(2345, sf.LastScan);
    }
Esempio n. 8
0
        public void test_matchremove_matches_cleans_and_returns_true()
        {
            // Arrange
            var parser = new TitleParser(titleInfoFunc);
            var title = "Test String";

            // Act
            bool result = parser.MatchRemove(ref title, " String");

            //Assert
            Assert.True(result);
            Assert.Equal(title, "Test");
        }
Esempio n. 9
0
        public void test_matchremove_nomatch_nochange_and_returns_false()
        {
            // Arrange
            var parser = new TitleParser(titleInfoFunc);
            var title = "Test String";

            // Act
            bool result = parser.MatchRemove(ref title, "nomatch");

            //Assert
            Assert.False(result);
            Assert.Equal(title, "Test String");
        }
Esempio n. 10
0
    public void TestDta()
    {
      ParserItem item = new ParserItem();
      ParserFormat format = new ParserFormat();
      format.FormatName = "TurboRAW2MGF, DTA Format";
      format.Add(new ParserItem("rawFile", @"(.+)\.\d+\.\d+\.\d\.(?:dta|DTA)"));
      format.Add(new ParserItem("scanNumber", @".+\.(\d+)\.(\d+)\.\d\.(?:dta|DTA)"));

      TitleParser parser = new TitleParser(format);
      SequestFilename sf = parser.GetValue("TEST.2345.2346.1.dta");
      Assert.AreEqual("TEST", sf.Experimental);
      Assert.AreEqual(2345, sf.FirstScan);
      Assert.AreEqual(2346, sf.LastScan);
    }
Esempio n. 11
0
        public static void NetSpider(string url)
        {
            //要爬取url
            Http.Get(url).OnSuccess((webheader, stream, response) =>
            {
                //1,获取文本内容
                var result = StreamDecoder.DecodeData(stream, response).ToLower();

                //2,存取关注数据 title..
                HtmlDocument htmldoc = new HtmlDocument();

                htmldoc.LoadHtml(result);

                var title  = new TitleParser(htmldoc).DoParser();
                dic[title] = url;
                Console.WriteLine(title + ":" + url);
                var urls = new UrlParser(htmldoc).DoParser();
                if (urls == null)
                {
                    return;
                }
                Queue <string> queue = new Queue <string>(urls);

                foreach (var item in queue)
                {
                    if (response.ResponseUri.Host != host)
                    {
                        return;
                    }
                    if (item.StartsWith("http"))
                    {
                        NetSpider(item.Trim());
                    }
                    else
                    {
                        string temp = "http://" + response.ResponseUri.Host + "/" + item.Trim();
                        NetSpider(temp);
                    }
                }

                //获取新的url地址
                //过滤url地址
                //将新的url地址加入到队列中
                //循环操作
            }).OnFail(action => {
                //状态码处理
            }).Go();
        }
Esempio n. 12
0
 public void GiveTitleAsHolder(TitleParser title)
 {
     title.CurrentHolder = this;
 }
Esempio n. 13
0
 private void RemoveTitle(TitleParser title)
 {
     Titles.Remove(title);
     title.Holder = null;
 }
Esempio n. 14
0
 public ScheduleParser(ISession session, TitleParser parser)
 {
     this.session = session;
     this.parser = parser;
 }
Esempio n. 15
0
        public List <IIdentifiedSpectrum> ReadFromFile(string fileName)
        {
            XElement root = XElement.Load(fileName);
            var      name = root.FindElement("AnalysisSoftwareList").
                            FindElement("AnalysisSoftware").
                            FindElement("SoftwareName").
                            FindElement("cvParam").Attribute("name").Value;

            var defaultExp = Path.GetFileNameWithoutExtension(fileName);

            foreach (var ext in extensions)
            {
                if (defaultExp.ToLower().EndsWith(ext))
                {
                    defaultExp = defaultExp.Substring(0, defaultExp.Length - ext.Length);
                }
            }

            //parsing identification protocol first
            var protocols = root.FindElement("AnalysisProtocolCollection");
            var sip       = protocols.FindElement("SpectrumIdentificationProtocol");
            var modMap    = ParseSearchModificationMap(sip.FindElement("ModificationParams"));
            var proteases = ParseEnzymes(sip.FindElement("Enzymes"));
            var protease  = proteases.FirstOrDefault();

            //parsing sequence collection, including protein<->peptide map
            var seqs       = root.FindElement("SequenceCollection");
            var proteinMap = (from ele in seqs.FindElements("DBSequence")
                              let id = ele.Attribute("id").Value
                                       let accession = ParseAccession(ele.Attribute("accession").Value)
                                                       let db = ele.Attribute("searchDatabase_ref").Value
                                                                select new { Id = id, Accession = accession, DB = db }).ToDictionary(m => m.Id);

            var peptideMap = (from ele in seqs.FindElements("Peptide")
                              let id = ele.Attribute("id").Value
                                       let seq = ele.FindElement("PeptideSequence").Value
                                                 let mods = (from modEle in ele.FindElements("Modification")
                                                             let mod = ParseModification(modEle, modMap)
                                                                       where mod != null
                                                                       orderby mod.Location descending
                                                                       select mod).ToArray()
                                                            let numMiss = protease == null ? 0 : protease.GetMissCleavageSiteCount(seq)
                                                                          select new MzIdentPeptideItem()
            {
                Id = id,
                PureSequence = seq,
                Modifications = mods,
                Sequence = GetModifiedSequence(seq, mods),
                NumMissCleavage = numMiss
            }).ToDictionary(m => m.Id);

            var peptideEvidenceMap = (from g in
                                      (from ele in seqs.FindElements("PeptideEvidence")
                                       select new MzIdentPeptideEvidenceItem()
            {
                Id = ele.Attribute("id").Value,
                PeptideRef = ele.Attribute("peptide_ref").Value,
                DbRef = ele.Attribute("dBSequence_ref").Value,
                Pre = ele.Attribute("pre").Value,
                Post = ele.Attribute("post").Value
            }).GroupBy(m => m.Id)
                                      select g.First()).ToDictionary(m => m.Id);

            //now parsing data
            var data = root.FindElement("DataCollection");

            var result       = new List <IIdentifiedSpectrum>();
            var analysisData = data.FindElement("AnalysisData");
            var idList       = analysisData.FindElement("SpectrumIdentificationList");

            foreach (var sir in idList.FindElements("SpectrumIdentificationResult"))
            {
                var items = FilterItems(sir.FindElements("SpectrumIdentificationItem"), peptideMap, peptideEvidenceMap);

                if (items.Count == 0)
                {
                    continue;
                }

                var spectrum = new IdentifiedSpectrum();
                result.Add(spectrum);

                var spectrumId = sir.Attribute("spectrumID").Value;

                var    sirCvParams = GetCvParams(sir);
                string value;
                if (sirCvParams.TryGetValue("MS:1000796", out value))
                {
                    spectrum.Query.FileScan = TitleParser.GetValue(value);
                }
                else
                {
                    if (spectrumId.StartsWith("index=") || spectrumId.StartsWith("scan="))
                    {
                        spectrum.Query.FileScan.Experimental = defaultExp;
                        spectrum.Query.FileScan.FirstScan    = int.Parse(spectrumId.StringAfter("="));
                        spectrum.Query.FileScan.LastScan     = spectrum.Query.FileScan.FirstScan;
                    }
                    else
                    {
                        spectrum.Query.FileScan.Experimental = spectrumId;
                    }
                }

                if (sirCvParams.TryGetValue("MS:1001115", out value))
                {
                    spectrum.Query.FileScan.FirstScan = int.Parse(value);
                }

                if (spectrum.Query.FileScan.FirstScan == 0)
                {
                    throw new Exception(string.Format("Cannot find scan information in file {0}", fileName));
                }

                bool bFirst = true;

                foreach (var sit in items)
                {
                    if (bFirst) //only parse score once
                    {
                        spectrum.Id             = sit.Attribute("id").Value;
                        spectrum.Charge         = int.Parse(sit.Attribute("chargeState").Value);
                        spectrum.TheoreticalMH  = PrecursorUtils.MzToMH(double.Parse(sit.Attribute("calculatedMassToCharge").Value), spectrum.Charge, true);
                        spectrum.ExperimentalMH = PrecursorUtils.MzToMH(double.Parse(sit.Attribute("experimentalMassToCharge").Value), spectrum.Charge, true);

                        var cvParams = GetCvParams(sit);
                        if (cvParams.TryGetValue("MS:1001121", out value))
                        {
                            spectrum.MatchedIonCount = int.Parse(value);
                        }

                        if (cvParams.TryGetValue("MS:1001362", out value))
                        {
                            spectrum.TheoreticalIonCount = int.Parse(value) + spectrum.MatchedIonCount;
                        }

                        ParseScore(spectrum, cvParams);

                        var userParams = GetUserParams(sit);
                        ParseUserParams(spectrum, userParams);

                        bFirst = false;
                    }

                    var peptide = new IdentifiedPeptide(spectrum);
                    var pep_ref = sit.Attribute("peptide_ref").Value;
                    var pep     = peptideMap[pep_ref];
                    spectrum.Modifications = (from m in pep.Modifications
                                              select string.Format("{0}:{1}", m.Location, m.Item.Name)).Reverse().Merge(",");
                    spectrum.NumMissedCleavages = pep.NumMissCleavage;

                    foreach (var per in sit.FindElements("PeptideEvidenceRef"))
                    {
                        var pe_ref = per.Attribute("peptideEvidence_ref").Value;
                        var pe     = peptideEvidenceMap[pe_ref];
                        peptide.Sequence = pe.Pre + "." + pep.Sequence + "." + pe.Post;

                        var protein = proteinMap[pe.DbRef];
                        peptide.AddProtein(protein.Accession);
                    }
                }
            }

            return(result);
        }
Esempio n. 16
0
        private string GetTitle()
        {
            var parser = new TitleParser(this.Path);

            return(parser.Get());
        }
Esempio n. 17
0
        public List <IIdentifiedSpectrum> ReadFromFile(string fileName)
        {
            var result = new MascotPeptideTextFormat().ReadFromFile(fileName);

            FilterSpectra(result);

            UpdateModifications(result);

            foreach (var peptide in result)
            {
                peptide.Peptide.AssignProteins((peptide.Annotations[PROTEIN_KEY] as string).Split(';'));
                peptide.Annotations.Remove(PROTEIN_KEY);
                peptide.TheoreticalMass = peptide.ExperimentalMass;
            }

            var i = 0;

            while (i < result.Count - 1)
            {
                var ititle = result[i].Annotations[TITLE_KEY] as string;
                while (i < result.Count - 1)
                {
                    var jtitle = result[i + 1].Annotations[TITLE_KEY] as string;
                    if (!ititle.Equals(jtitle))
                    {
                        i++;
                        break;
                    }

                    for (int l = result[i + 1].Peptides.Count - 1; l >= 0; l--)
                    {
                        result[i].AddPeptide(result[i + 1].Peptides[l]);
                    }

                    result.RemoveAt(i + 1);
                }
            }

            foreach (var peptide in result)
            {
                var title = peptide.Annotations[TITLE_KEY] as string;
                peptide.Annotations.Remove(TITLE_KEY);

                var oldCharge = peptide.Query.FileScan.Charge;
                peptide.Query.FileScan = TitleParser.GetValue(title);

                peptide.Query.FileScan.Charge = oldCharge;
                if (string.IsNullOrEmpty(peptide.Query.FileScan.Experimental))
                {
                    peptide.Query.FileScan.Experimental = Path.GetFileNameWithoutExtension(fileName);
                }
                var rtstr = peptide.Annotations[RT_KEY] as string;
                if (!string.IsNullOrWhiteSpace(rtstr))
                {
                    peptide.Query.FileScan.RetentionTime = double.Parse(rtstr.StringBefore("-"));
                }
                peptide.Annotations.Remove(RT_KEY);
            }

            return(result);
        }
Esempio n. 18
0
        public void test_title_matches_bad_title_df()
        {
            // Arrange
            var parser = new TitleParser(titleInfoFunc);
            const string title = "DF STAR TREK ONGOING #2 2ND PTG (PP #994)";

            // Act
            bool result = parser.IsBadTitle(title);

            //Assert
            Assert.True(result);
        }
Esempio n. 19
0
 public TitleProxy(TitleParser title)
 {
     this.title = title;
 }
Esempio n. 20
0
        //attack / Capture duchies
        public void GiveTitle(TitleParser t)
        {
            if (PrimaryTitle != null && t.Rank > PrimaryTitle.Rank)
            {
                return;
            }

            t.CurrentHolder = null;
            if (Titles.Contains(t))
                return;


            if (t.Holder != null)
            {
                if (t.Holder.PrimaryTitle == t)
                    t.Holder.PrimaryTitle = null;

                t.Holder.Titles.Remove(t);                
            }

            t.Active = true;
            t.Holder = this;
            _primaryTitle = null;
            if ((PrimaryTitle == null || t.Rank > PrimaryTitle.Rank))
            {
                Titles.Insert(0, t);
                PrimaryTitle = t;
            }
            else
            {
                Titles.Add(t);
            }
            foreach (var titleParser in t.SubTitles)
            {
                titleParser.Value.Liege = t;
            }

            if (t.Owns.Count > 0)
            {
                if (this.GetProperty("culture") != null)
                    t.Owns[0].SetProperty("culture", this.GetProperty("culture").Value);
                if (this.GetProperty("religion") != null)
                    t.Owns[0].SetProperty("religion", this.GetProperty("religion").Value);
                t.Owns[0].ProvinceOwner = t;

            }
            SetColorOfChildren(t);

        }
Esempio n. 21
0
        public void test_title_matches_limited_title()
        {
            // Arrange
            var parser = new TitleParser(titleInfoFunc);
            const string title = "BOMB QUEEN VII #1 (OF 4) (MR)";

            // Act
            bool continuing = parser.IsContinuingTitle(title);
            bool limited = parser.IsLimitedTitle(title);

            //Assert
            Assert.True(limited);
            Assert.False(continuing);
        }
Esempio n. 22
0
        private void SetColorOfChildren(TitleParser t)
        {
            if (t.Owns.Count > 0)
            {
                t.Owns[0].SetProperty("color", Color);
                t.Owns[0].SetProperty("color2", Color);
            }

            foreach (var titleParser in t.SubTitles)
            {
                if (titleParser.Value.Rank >= PrimaryTitle.Rank)
                {
                    continue;
                }
                SetColorOfChildren(titleParser.Value);
            }
        }
Esempio n. 23
0
        public virtual List <IIdentifiedSpectrum> ReadFromFile(string fileName)
        {
            if (this.TitleParser == null)
            {
                throw new Exception("Title format is not defined for parsing " + fileName);
            }

            List <IIdentifiedSpectrum> result = new List <IIdentifiedSpectrum>();

            XElement root = XElement.Load(fileName);

            var msms_run_summaries = root.FindDescendants("msms_run_summary");

            foreach (var msms_run_summary in msms_run_summaries)
            {
                var search_summary = msms_run_summary.FindFirstDescendant("search_summary");
                var engine         = search_summary.Attribute("search_engine").Value;
                var ismono         = search_summary.Attribute("precursor_mass_type").Value.Equals("monoisotopic");

                var enzyme        = ParseProtease(msms_run_summary.FindFirstDescendant("sample_enzyme"));
                var modifications = ParseModifications(msms_run_summary);

                var spectrumQueries = msms_run_summary.FindDescendants("spectrum_query");

                foreach (var sp in spectrumQueries)
                {
                    IdentifiedSpectrum sph = new IdentifiedSpectrum();

                    sph.IsPrecursorMonoisotopic = ismono;

                    SequestFilename sf;
                    if (sp.Attribute("spectrumNativeID") != null)
                    {
                        sf = TitleParser.GetValue(sp.Attribute("spectrumNativeID").Value);
                    }
                    else
                    {
                        sf = TitleParser.GetValue(sp.Attribute("spectrum").Value);
                    }
                    sph.Query.FileScan.LongFileName = sf.LongFileName;

                    sph.ExperimentalMass = MyConvert.ToDouble(sp.Attribute("precursor_neutral_mass").Value);
                    sph.Query.Charge     = int.Parse(sp.Attribute("assumed_charge").Value);

                    var searchResult = sp.FindFirstDescendant("search_result");
                    var searchHit    = FindSearchHit(searchResult);

                    if (searchHit == null)
                    {
                        continue;
                    }

                    sph.TheoreticalMass = MyConvert.ToDouble(searchHit.Attribute("calc_neutral_pep_mass").Value);
                    sph.MatchedIonCount = int.Parse(searchHit.Attribute("num_matched_ions").Value);
                    sph.Rank            = int.Parse(searchHit.Attribute("hit_rank").Value);
                    var ticAtt = searchHit.Attribute("tot_num_ions");
                    sph.TheoreticalIonCount = ticAtt == null ? 0 : int.Parse(ticAtt.Value);

                    ParseSearchHit(sph, searchHit, modifications);

                    sph.Engine         = engine;
                    sph.DigestProtease = enzyme;

                    result.Add(sph);
                }
            }

            return(result);
        }