Ejemplo n.º 1
0
 private static string Dump(Haplogroup group, bool dumpSnps)
 {
     var d = dumpSnps;
     return StringTree.Create(
         group,
         x => !d || !x.Mutations.Any() ?
             x.Name :
             string.Format(
                 "{0} ({1})",
                 x.Name,
                 x.Mutations.Select(y => y.Snp).Join(", ")),
         x => x.Children);
 }
Ejemplo n.º 2
0
 private static Haplogroup FindHaplogroup(string name, Haplogroup group)
 {
     if (group.Name == name)
     {
         return group;
     }
     else if (group.Children.Any())
     {
         return group.Children
             .Select(x => FindHaplogroup(name, x))
             .FirstOrDefault(x => x != null);
     }
     else
     {
         return null;
     }
 }
Ejemplo n.º 3
0
 private static Haplogroup RemoveFiller(Haplogroup group)
 {
     return Visitor.Where(
         group,
         x =>  !x.Name.StartsWith("FILLER_"),
         (parent, child) =>
         {
             parent.Children.Add(child);
             child.Parent = parent;
         },
         (parent, child) => parent.Children.Remove(child),
         x => x.Children);
 }
Ejemplo n.º 4
0
        private static Haplogroup ParseTree(string filename)
        {
            var flatTree = ParseFlatTree(filename);
            var stack = new Stack<Haplogroup>();

            stack.Push(new Haplogroup() { Name = flatTree.First().Key });

            Action<string> add = x =>
            {
                var g = new Haplogroup()
                {
                    Name = x,
                    Parent = stack.Peek(),
                };
                stack.Peek().Children.Add(g);
                stack.Push(g);
            };

            var depth = 0;
            var filler = 0;

            foreach (var node in flatTree.Skip(1))
            {
                if (node.Value == depth)
                {
                    stack.Pop();
                    add(node.Key);
                }
                //else if (node.Value == depth + 1)
                else if (node.Value > depth)

                {
                    var delta = node.Value - depth;
                    depth += delta;

                    foreach (var f in Enumerable.Range(0, delta - 1))
                    {
                        add("FILLER_" + filler++);
                    }

                    add(node.Key);
                }
                //else if (node.Value > depth)
                //{
                //    Console.WriteLine();
                //}
                else
                {
                    var delta = depth - node.Value;
                    depth -= delta;

                    for (var i = 0; i < delta + 1; i++)
                    {
                        stack.Pop();
                    }

                    add(node.Key);
                }
            }

            return stack.Last();
        }