Exemplo n.º 1
0
 //  <match key="334452a46ee53694350e274530ae4b47" id1="334452a46ee53694" id2="350e274530ae4b47" name1="Ken Lassesen" name2="Ethelyn Hallberg" cm="26" fragments="2" />
 private void ImportMatch()
 {
     var matches = dom.SelectNodes("//match");
     foreach (XmlNode node in matches)
     {
         var id0 = node.Attributes["id1"].Value;
         var id1 = node.Attributes["id2"].Value;
         var person0 = Repository.FindPerson(id0);
         var person1 = Repository.FindPerson(id1);
         var geneticDistance = 0F;
         if(float.TryParse(node.Attributes["cm"].Value, out geneticDistance))
         {
             var match = new Match {ChromosomeText = "0", Id0 = person0.Id, Id1=person1.Id, GeneticDistance = geneticDistance,MeAnd23 = true};
             match.Save();
         }
     }
 }
Exemplo n.º 2
0
        private void ParseTable(Personv2 p0, string table)
        {
            if (!table.Contains("Chromosome") || !table.Contains("Genetic distance"))
                return;
            string[] nameSep = { " vs. " };
            string[] cmSep = { " cM" };
            table = table.Replace("&nbsp;", "");
            var dom = new System.Xml.XmlDocument();
            try
            {
                dom.LoadXml(table);
            }
            catch (Exception exc)
            {
                MessageBox.Show(this, exc.Message + "\r\n" + table, "Parsing HTML error");
            }
            var rows = dom.SelectNodes("//tr");
            if (rows != null)
                foreach (XmlNode row in rows)
                {

                    if (row.ChildNodes.Count == 6 && !String.IsNullOrWhiteSpace(row.ChildNodes[0].InnerText))
                    {
                        var names = row.ChildNodes[0].InnerText.Split(nameSep, StringSplitOptions.RemoveEmptyEntries);
                        if (names.Length > 1)
                            try
                            {
                                var name = names[1].Trim();
                                var p1 = Repository.FindOrCreatePerson(name, name);
                                if (p1 == null)
                                {
                                    MessageBox.Show(this, name + " was not found -- please refetch you people",
                                                    "23AndMe.com updated sharing");
                                }
                                var chrom = row.ChildNodes[1].InnerText;
                                var startAt = int.Parse(row.ChildNodes[2].InnerText);
                                var endAt = int.Parse(row.ChildNodes[3].InnerText);
                                var cM =
                                    float.Parse(
                                        row.ChildNodes[4].InnerText.Split(cmSep, StringSplitOptions.RemoveEmptyEntries)[0]);
                                var snps = int.Parse(row.ChildNodes[5].InnerText);
                                var match = new Match
                                                {
                                                    ChromosomeText = chrom,
                                                    EndPoint = endAt,
                                                    StartPoint = startAt,
                                                    GeneticDistance = cM,
                                                    Id1 = p1.Id,
                                                    Id0 = p0.Id,
                                                    SNPs = snps,
                                                    MeAnd23 = true
                                                };

                                match.Save();
                            }
                            catch (Exception exc)
                            {
                                MessageBox.Show(this, exc.Message, "Unexpected Error");
                            }
                    }
                }
            Repository.Write();
        }
Exemplo n.º 3
0
 private void GetNumbers(Personv2 p0, string url, string[] idList)
 {
     try
     {
         Console.WriteLine(url);
         webBrowser1.Stop();
         _browserDone = false;
         webBrowser1.AllowNavigation = true;
         webBrowser1.Navigate(url);
         while (webBrowser1.IsBusy || !_browserDone)
         {
             System.Threading.Thread.Sleep(100);
             Application.DoEvents();
             if (!isRunning) return;
         }
         var waiting = true;
         while (waiting)
         {
             var dom = webBrowser1.Document.DomDocument as IHTMLDocument2;
             if (!isRunning) return;
             List<mshtml.IHTMLTable> allLi = dom
                 .all.OfType<mshtml.IHTMLTable>()
                 .ToList();
             if (allLi.Count > 0)
             {
                 foreach (IHTMLTable li in allLi)
                 {
                     var el = (IHTMLElement)li;
                     ParseTable(p0, el.outerHTML);
                 }
                 waiting = false;
             }
             else
             {
                 for (var i = 0; i < 100000; i++)
                 {
                     Application.DoEvents();
                 }
             }
         }
     }
     catch (Exception exc)
     {
         MessageBox.Show(this, exc.Message, "Unexpected Error");
     }
     // For items with no data, create a NoMatch Record
     foreach (string meId in idList)
     {
         if (!string.IsNullOrWhiteSpace(meId))
         {
             var p1 = Repository.FindPerson(meId);
             if (p1 != null)
             {
                 if (!Repository.Match23AndMe(p0, p1))
                 {
                     var dummy = new Match { Id0 = p0.Id, Id1 = p1.Id, Chromosome = -1, GeneticDistance = 0, MeAnd23 = true };
                     dummy.Save();
                 }
             }
         }
     }
 }
        void ProcessChromosomeBrowser()
        {
            string[] commaSep = { "," };
            for (var i = 1; i < data.Length; i++)
            {
                try
                {
                    var cols = data[i].Split(commaSep, StringSplitOptions.None);
                    var name0 = cols[0].Replace("\"", "").Trim();
                    var name1 = cols[1].Replace("\"", "").Trim();
                    var id0 = Repository.FindOrCreatePerson(name0,name0);
                    id0.FamilyTreeId = name0;
                    if(!id0.IsSaved) id0.Save();
                    var id1 = Repository.FindOrCreatePerson(name1,name1);
                    id1.FamilyTreeId = name1;
                    if (!id1.IsSaved) id1.Save();
                    var result = new Match { Id0 = id0.Id, Id1 = id1.Id };
                    if (cols[2].Equals("X"))
                    {
                        result.Chromosome = 27;
                    }
                    else if (cols[2].Equals("Y"))
                    {
                        result.Chromosome = 28;
                    }
                    else
                    {
                        result.Chromosome = int.Parse(cols[2]);
                    }
                    result.StartPoint = int.Parse(cols[3]);
                    result.EndPoint = int.Parse(cols[4]);
                    result.GeneticDistance = float.Parse(cols[5]);
                    result.SNPs = int.Parse(cols[6]);
                    result.FamilyTreeDna = true;

                    result.Save();
                }
                catch
                    (Exception
                        exc)
                {
                    MessageBox.Show(exc.Message, "Unexpected Error");
                }

            }
        }