Exemple #1
0
        public static List <string> SetPhylogeneticWeights()
        {
            var skippedPositions = new List <string>();
            //StreamReader value = new StreamReader(fileName);
            var    value = new StringReader(FlucRates15.FileAsString);
            string line  = value.ReadLine();

            while (line != null)
            {
                string[] tokens             = line.Split('\t');
                string   polyString         = tokens[0];
                double   phyloGeneticWeight = Convert.ToDouble(tokens[1]);
                if (!polyString.Contains("X"))
                {
                    Polymorphism poly = new Polymorphism(polyString);
                    Polymorphism.changePhyloGeneticWeight(poly, phyloGeneticWeight);
                }
                else
                {
                    //Console.WriteLine("Skipping: " + polyString);
                    skippedPositions.Add(polyString);
                }
                line = value.ReadLine();
            }
            return(skippedPositions);
        }
 public bool contains(Polymorphism polyToCheck)
 {
     for (int i = 0; i < this.starts.Count; i++)
     {
         if (((int)((int?)this.starts[i]) <= polyToCheck.Position) && ((int)((int?)this.ends[i]) >= polyToCheck.Position))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #3
0
        public void changePoly(Haplogroup hg, Polymorphism polyOld, Polymorphism polyNew)
        {
            var e = getPolysOfHg(hg);

            foreach (XmlNode ce in e)
            {
                if (ce.InnerText.Equals(polyOld.ToString()))
                {
                    ce.InnerText = polyNew.ToString();
                    return;
                }
            }
            throw new HaploGrepException("Polymorphism does not exit");
        }
        public void removeExpectedPoly(Polymorphism currentPoly)
        {
            Polymorphism found = null;

            foreach (Polymorphism poly in this.allCheckedPolys)
            {
                if ((poly.Position == currentPoly.Position) && (poly.Mutation == currentPoly.Mutation))
                {
                    this.expectedWeightPolys -= this.allCheckedPolys[this.allCheckedPolys.IndexOf(poly)].getMutationRate();
                    found = poly;
                    Polymorphism newPoly = new Polymorphism(currentPoly);
                    newPoly.BackMutation = false;
                    this.correctedBackmutations.Add(new Polymorphism(newPoly));
                }
            }
            this.allCheckedPolys.Remove(found);
        }
Exemple #5
0
        private List <Polymorphism> parseSample(List <string> sample, int callMethod)
        {
            //List of e.g. G2a3	16183C	16189C	16193.1C	16223T	16278T	16362C	73G	260A	263G	309.1C	315.1C	489C	4833G	10400T	13563G	14569A	523d	524d
            List <Polymorphism> filteredSample = new List <Polymorphism>();

            sample = sample.Select(x => x.Trim()).ToList();
            foreach (string currentPolyOrig in sample)
            {
                string currentPoly = currentPolyOrig;
                if ((!currentPoly.Contains("5899.1d!")) && (!currentPoly.Contains("65.1T(T)")))
                {
                    currentPoly = currentPoly.Replace("(", "");
                    currentPoly = currentPoly.Replace(")", "");
                    if (currentPoly.Contains("."))
                    {
                        if (callMethod == 0)
                        {
                            //309.1C
                            if (currentPoly.Contains(".1") && dotRegex.IsMatch(currentPoly))
                            {
                                string[] split    = currentPoly.Split('.');
                                string   position = split[0];        //st1.nextToken();
                                string   ins      = split[1].Trim(); // st1.nextToken().Trim();
                                int      nextPos  = 2;
                                //WTF? We are searching for another deletion at same location??
                                // Okay, really really really effing goofy here, explained by Sebastian below.
                                //If you enter it as 1235.1A, 1235.2A, 1235.3T in the hsd file,
                                //Haplogrep transforms it to 1235.AAT.  including insertions in the current algorithm.
                                string samePos = position + ".";
                                foreach (string currentPoly2 in sample)
                                {
                                    if ((!currentPoly2.Equals(currentPoly)) && (currentPoly2.StartsWith(samePos)))
                                    {
                                        split = currentPoly2.Split('.');
                                        string position2 = split[0];
                                        string newIns    = split[1].Trim();
                                        //Pattern p = Pattern.compile("\\d+");
                                        //Matcher m = p.matcher(ins);
                                        //m.find();
                                        //int tmp = Convert.ToInt32(ins.Substring(m.start(), m.end() - (m.start())));
                                        Match m   = Regex.Match(newIns, "\\d+");
                                        int   tmp = Convert.ToInt32(m.Value);
                                        if (nextPos != tmp)
                                        {
                                            throw new HaploGrepException(currentPoly2);
                                        }
                                        nextPos++;
                                        ins += newIns.Replace(m.Value, "");
                                    }
                                }
                                filteredSample.Add(new Polymorphism(position + "." + ins));
                            }
                            //Seems this will never be called as call method always 0
                            else if (Regex.IsMatch(currentPoly, "\\d+\\.1[a-zA-Z]{2,}"))
                            {
                                Polymorphism newPoly = new Polymorphism(currentPoly);
                                filteredSample.Add(newPoly);
                            }
                        }
                        else
                        {
                            Polymorphism newPoly = new Polymorphism(currentPoly);
                            filteredSample.Add(newPoly);
                        }
                    }
                    else if (currentPoly.Contains("-"))
                    {
                        string[] st1 = currentPoly.Split('-');
                        //StringTokenizer st1 = new StringTokenizer(currentPoly, "-");
                        string token         = st1[0]; // st1.nextToken();
                        int    startPosition = (int)Convert.ToInt32(token);
                        token = st1[1];                // st1.nextToken();
                        int endPosition = (int)Convert.ToInt32(token.Substring(0, token.Length - 1));
                        for (int i = startPosition; i <= endPosition; i++)
                        {
                            filteredSample.Add(new Polymorphism(i, Mutations.DEL));
                            startPosition++;
                        }
                    }
                    else
                    {
                        Polymorphism newPoly = new Polymorphism(currentPoly);
                        filteredSample.Add(newPoly);
                    }
                }
            }
            return(filteredSample);
        }
Exemple #6
0
 public bool contains(Polymorphism polyToCheck)
 {
     return(this.sample.Contains(polyToCheck));
 }
 public virtual void addCorrectedBackmutation(Polymorphism poly)
 {
     this.correctedBackmutation.Add(poly);
 }
 public virtual void removeCorrectPoly(Polymorphism currentPoly)
 {
     this.foundPolys.Remove(currentPoly);
 }
 public virtual void removeExpectedPoly(Polymorphism currentPoly)
 {
     this.expectedPolys.Remove(currentPoly);
 }
 public virtual void addNotInRangePoly(Polymorphism currentPoly)
 {
     this.notInRangePolys.Add(currentPoly);
 }
 public virtual void addCorrectPoly(Polymorphism currentPoly)
 {
     this.foundPolys.Add(currentPoly);
 }
 public virtual void addExpectedPoly(Polymorphism currentPoly)
 {
     this.expectedPolys.Add(currentPoly);
 }
 public void removeMissingOutOfRangePoly(Polymorphism correctPoly)
 {
     this.missingWeightPolys -= correctPoly.getMutationRate();
     this.missingPolysOutOfRange.Add(correctPoly);
 }
 public void addExpectedPoly(Polymorphism correctPoly)
 {
     this.expectedWeightPolys += correctPoly.getMutationRate();
     this.allCheckedPolys.Add(correctPoly);
 }
 public void addCorrectPoly(Polymorphism correctPoly)
 {
     this.correctWeightPolys += correctPoly.getMutationRate();
     this.correctPolys.Add(correctPoly);
     this.unusedPolys.Remove(correctPoly);
 }
        /// <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);
            }
        }