Esempio n. 1
0
        /// <summary>
        /// Recursive function to search the XML tree and create a result at each node
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="results"></param>
        /// <param name="sample"></param>
        /// <param name="parentResult"></param>
        private void searchPhylotree(XmlNode parent, List <SearchResult> results, TestSample sample, SearchResult parentResult)
        {
            var children = parent.SelectNodes("haplogroup");

            foreach (XmlNode currentElement in children)
            {
                //string,string,parent result
                SearchResult  newResult = new SearchResult(currentElement.Attributes.GetNamedItem("name").Value, parentResult);
                var           details   = currentElement.SelectSingleNode("details");
                var           polys     = details.SelectNodes("poly");
                PhyloTreeNode newNode   = new PhyloTreeNode(new Haplogroup(currentElement.Attributes.GetNamedItem("name").Value));
                foreach (XmlNode currentPolyElement in polys)
                {
                    if (currentPolyElement.InnerText.Contains("X"))
                    {
                        //System.Console.WriteLine("Skipping: " + currentPolyElement.InnerText);
                        continue;
                    }
                    Polymorphism currentPoly = new Polymorphism(currentPolyElement.InnerText);
                    if (sample.SampleRanges.contains(currentPoly))
                    {
                        if (currentPoly.BackMutation)
                        {
                            newResult.removeExpectedPoly(currentPoly);
                            newResult.removeCorrectPoly(currentPoly);
                            newNode.removeExpectedPoly(currentPoly);
                            newNode.removeCorrectPoly(currentPoly);
                            newNode.addExpectedPoly(currentPoly);
                            Polymorphism newPoly = new Polymorphism(currentPoly);
                            newPoly.BackMutation = false;
                            if (!newResult.Sample.contains(newPoly))
                            {
                                newNode.addCorrectPoly(currentPoly);
                            }
                        }
                        else if (newResult.Sample.contains(currentPoly))
                        {
                            newResult.addExpectedPoly(currentPoly);
                            newResult.addCorrectPoly(currentPoly);
                            newNode.addExpectedPoly(currentPoly);
                            newNode.addCorrectPoly(currentPoly);
                        }
                        else
                        {
                            if (currentPoly.BackMutation)
                            {
                                newResult.removeMissingOutOfRangePoly(currentPoly);
                            }
                            newResult.addExpectedPoly(currentPoly);
                            newNode.addExpectedPoly(currentPoly);
                        }
                    }
                    else
                    {
                        newResult.addMissingOutOfRangePoly(currentPoly);
                        newNode.addNotInRangePoly(currentPoly);
                    }
                }
                newResult.UnusedNotInRange = sample.PolyNotinRange;
                results.Add(newResult);
                newResult.extendPath(newNode);
                searchPhylotree(currentElement, results, sample, newResult);
            }
        }