示例#1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Loading kit names ...");
            string curr_dir = "";



            //debug
            //curr_dir = @"D:\Genetics\Ancient-DNA\";

            if (!File.Exists(curr_dir + "atree.txt"))
            {
                Console.WriteLine("atree.txt does not exist!");
                return;
            }

            string[] lines = null;
            string[] data  = null;
            if (File.Exists(curr_dir + @"ref\kit-names.txt"))
            {
                lines = File.ReadAllLines(curr_dir + @"ref\kit-names.txt");
                foreach (string line in lines)
                {
                    if (line.Trim() == "")
                    {
                        continue;
                    }
                    data = line.Split(new char[] { ',' });
                    kitmap.Add(data[0], data[1]);
                }
            }
            //


            lines = File.ReadAllLines(curr_dir + "atree.txt");
            data  = null;

            List <CommonAncestor> tree = new List <CommonAncestor>();

            foreach (string line in lines)
            {
                data = line.Split(new char[] { ',' });
                CommonAncestor ancestor = new CommonAncestor();
                ancestor.name     = data[0];
                ancestor.id       = data[1];
                ancestor.kits     = new List <string>(data[1].Split(new char[] { '-' }));
                ancestor.segments = new List <Segment>();
                foreach (string segstr in data[2].Split(new char[] { '_' }))
                {
                    ancestor.segments.Add(new Segment(segstr.Split(new char[] { ':' })));
                }
                ancestor.descendents = new List <CommonAncestor>();

                addToTree(tree, ancestor);
            }
            string ca_xml = "<CA NAME='ADAM-EVE'>" + drawTree(tree) + "\r\n</CA>";

            File.WriteAllText("atree.xml", ca_xml);
            Console.WriteLine("atree.xml successfully written.");
        }
 private static void addToTree(List <CommonAncestor> tree, CommonAncestor ancestor)
 {
     foreach (CommonAncestor par in tree)
     {
         if (AncestorKitsPresent(par, ancestor))
         {
             addToTree(par.descendents, ancestor);
             return;
         }
     }
     tree.Add(ancestor);
 }
        private static bool AncestorKitsPresent(CommonAncestor par,
                                                CommonAncestor ancestor)
        {
            List <string> pkits = par.kits;
            List <string> akits = ancestor.kits;

            foreach (string kit in akits)
            {
                if (!pkits.Contains(kit))
                {
                    return(false);
                }
            }
            return(true);
        }
        public static void doGenXML()
        {
            Program.addLog("Loading kit names ...");
            string curr_dir = "";



            //debug
            //curr_dir = @"D:\Genetics\Ancient-DNA\";

            if (!File.Exists(curr_dir + "atree.txt"))
            {
                Program.addLog("atree.txt does not exist!");
                return;
            }

            string[] lines = null;
            string[] data  = null;
            //


            lines = File.ReadAllLines(curr_dir + "atree.txt");
            data  = null;

            List <CommonAncestor> tree = new List <CommonAncestor>();

            foreach (string line in lines)
            {
                data = line.Split(new char[] { ',' });
                CommonAncestor ancestor = new CommonAncestor();
                ancestor.name     = data[0];
                ancestor.id       = data[1];
                ancestor.kits     = new List <string>(data[1].Split(new char[] { '-' }));
                ancestor.segments = new List <Segment>();
                foreach (string segstr in data[2].Split(new char[] { '_' }))
                {
                    ancestor.segments.Add(new Segment(segstr.Split(new char[] { ':' })));
                }
                ancestor.descendents = new List <CommonAncestor>();

                addToTree(tree, ancestor);
            }
            string ca_xml = "<CA NAME='ADAM-EVE'>" + drawTree(tree) + "\r\n</CA>";

            File.WriteAllText("atree.xml", ca_xml);
            Program.addLog("atree.xml successfully written.");
        }