Beispiel #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            label2.Text    = GGKUtilLib.getKitName(kit);
            txtSNPs.Text   = GGKUtilLib.queryValue("kit_ysnps", new string[] { "ysnps" }, "where kit_no='" + kit + "'");
            GGKUtilLib.setStatus("Plotting on ISOGG Y-Tree ...");
            //
            XDocument doc = XDocument.Parse(Genetic_Genealogy_Kit.Properties.Resources.ytree);

            TreeNode root = new TreeNode("Adam");

            treeView1.Nodes.Add(root);

            foreach (XElement el in doc.Root.Elements())
            {
                buildTree(root, el);
            }
            root.Expand();
            //
            snp_on_tree.AddRange(Genetic_Genealogy_Kit.Properties.Resources.snps_on_tree.Split(new char[] { ',' }));

            my_snp    = txtSNPs.Text;
            snp_array = filterSNPsOnTree(my_snp);

            timer2.Enabled = true;
        }
 private void MainFrm_Load(object sender, EventArgs e)
 {
     label2.Text    = kit + " - " + GGKUtilLib.getKitName(kit);
     this.Text      = "Mitocondrial Phylogeny - (" + kit + ")" + GGKUtilLib.getKitName(kit);
     xml_phylogeny  = Genetic_Genealogy_Kit.Properties.Resources.mtDNAPhylogeny;
     timer1.Enabled = true;
 }
Beispiel #3
0
        private void btnChild_Click(object sender, EventArgs e)
        {
            SelectKitFrm open = new SelectKitFrm(SelectKitFrm.SELECT_KIT);

            open.ShowDialog(this);
            child_kit     = open.getSelectedKit();
            btnChild.Text = GGKUtilLib.getKitName(child_kit);
            if ((father_kit != "Unknown" || mother_kit != "Unknown") && child_kit != "Unknown")
            {
                btnPhasing.Enabled = true;
            }
        }
 public OneToOneCmpFrm(string kit1, string kit2)
 {
     InitializeComponent();
     //
     this.kit1  = kit1;
     this.kit2  = kit2;
     this.name1 = GGKUtilLib.getKitName(kit1);
     this.name2 = GGKUtilLib.getKitName(kit2);
     dgvMatching.Columns[3].HeaderText = name1;
     dgvMatching.Columns[4].HeaderText = name2;
     GGKUtilLib.setStatus("Comparing kits " + kit1 + " and " + kit2 + " ...");
     bwCompare.RunWorkerAsync();
 }
Beispiel #5
0
        private void MitoMapFrm_Load(object sender, EventArgs e)
        {
            string       csv    = Genetic_Genealogy_Kit.Properties.Resources.mtdna_map;
            StreamReader reader = new StreamReader(new MemoryStream(Encoding.ASCII.GetBytes(csv)));
            string       line   = null;

            string[] data   = null;
            Series   series = series = mtdna_chart.Series[0];

            //Map Locus	 Starting	 Ending	bp Length	 Shorthand	 Description
            dgvmtdna.Rows.Clear();
            while ((line = reader.ReadLine()) != null)
            {
                data = line.Split(new char[] { ',' });
                DataPoint dp = new DataPoint();
                dp.IsVisibleInLegend = false;
                dp.Label             = data[0];
                dp.YValues           = new double[] { int.Parse(data[3]) };
                dp.CustomProperties  = "PieLineColor=Black, PieLabelStyle=Outside, Exploded=True";
                series.Points.Add(dp);
                //
                dgvmtdna.Rows.Add(new object[] { data[0], data[1], data[2], data[3], data[4], data[5] });
            }
            reader.Close();
            //
            RSRS = GGKUtilLib.getRSRS();
            for (int i = 0; i < RSRS.Length; i++)
            {
                nucleotides.Add(i + 1, new string[] { (i + 1).ToString(), RSRS[i].ToString(), RSRS[i].ToString() });
            }

            mutations = GGKUtilLib.queryValue("kit_mtdna", new string[] { "mutations" }, "where kit_no='" + kit + "'");
            dgvNucleotides.Columns[2].HeaderText = GGKUtilLib.getKitName(kit) + " (" + kit + ")";

            dgvmtdna.Columns[3].Visible = false;

            loadKitMutations();
        }
Beispiel #6
0
        private void bwPhaseVisualizer_DoWork(object sender, DoWorkEventArgs e)
        {
            DataTable dt_existing = GGKUtilLib.QueryDB("select segment_image,segment_xml from cmp_phased where phased_kit='" + phased_kit + "' and match_kit='" + unphased_kit + "' and chromosome='" + chromosome + "' and start_position=" + start_position + " and end_position=" + end_position);

            if (dt_existing.Rows.Count > 0)
            {
                object[] o   = dt_existing.Rows[0].ItemArray;
                string   xml = o[1].ToString();
                dt = new DataTable();
                MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(xml));
                dt.ReadXml(ms);


                this.Invoke(new MethodInvoker(delegate
                {
                    dgvSegment.DataSource = dt;

                    dgvSegment.Columns[0].HeaderText = "Position";
                    dgvSegment.Columns[1].HeaderText = GGKUtilLib.sqlSafe(GGKUtilLib.getKitName(unphased_kit));
                    dgvSegment.Columns[2].HeaderText = GGKUtilLib.sqlSafe(GGKUtilLib.getKitName(phased_kit)) + " (Paternal)";
                    dgvSegment.Columns[3].HeaderText = GGKUtilLib.sqlSafe(GGKUtilLib.getKitName(phased_kit)) + " (Maternal)";

                    dgvSegment.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                    dgvSegment.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                    dgvSegment.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                    dgvSegment.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

                    dgvSegment.Columns[0].ReadOnly = true;
                    dgvSegment.Columns[1].ReadOnly = true;
                    dgvSegment.Columns[2].ReadOnly = true;
                    dgvSegment.Columns[3].ReadOnly = true;
                }));

                byte[] image_array = (byte[])o[0];
                Image  img         = GGKUtilLib.byteArrayToImage(image_array);
                this.Invoke(new MethodInvoker(delegate
                {
                    original        = new Bitmap(img, 600, 150);
                    pbSegment.Image = original;
                }));
            }
            else
            {
                dt = GGKUtilLib.QueryDB("select a.position,a.genotype,p.paternal_genotype,p.maternal_genotype from kit_autosomal a,kit_phased p where a.kit_no='" + unphased_kit + "' and a.position>" + start_position + " and a.position<" + end_position + " and a.chromosome='" + chromosome + "' and p.rsid=a.rsid and p.kit_no='" + phased_kit + "' order by a.position");
                if (dt.Rows.Count > 0)
                {
                    if (this.IsHandleCreated)
                    {
                        this.Invoke(new MethodInvoker(delegate
                        {
                            dgvSegment.DataSource = dt;

                            dgvSegment.Columns[0].HeaderText = "Position";
                            dgvSegment.Columns[1].HeaderText = GGKUtilLib.sqlSafe(GGKUtilLib.getKitName(unphased_kit));
                            dgvSegment.Columns[2].HeaderText = GGKUtilLib.sqlSafe(GGKUtilLib.getKitName(phased_kit)) + " (Paternal)";
                            dgvSegment.Columns[3].HeaderText = GGKUtilLib.sqlSafe(GGKUtilLib.getKitName(phased_kit)) + " (Maternal)";

                            dgvSegment.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                            dgvSegment.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                            dgvSegment.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                            dgvSegment.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

                            dgvSegment.Columns[0].ReadOnly = true;
                            dgvSegment.Columns[1].ReadOnly = true;
                            dgvSegment.Columns[2].ReadOnly = true;
                            dgvSegment.Columns[3].ReadOnly = true;
                        }));
                        Image img = GGKUtilLib.getPhasedSegmentImage(dt, chromosome);
                        this.Invoke(new MethodInvoker(delegate
                        {
                            original        = img;
                            pbSegment.Image = img;
                        }));
                    }

                    dt.TableName = "cmp_phased";
                    StringBuilder sb = new StringBuilder();
                    StringWriter  w  = new StringWriter(sb);
                    dt.WriteXml(w, XmlWriteMode.WriteSchema);
                    string segment_xml = sb.ToString();

                    SQLiteConnection conn = GGKUtilLib.getDBConnection();
                    SQLiteCommand    cmd  = new SQLiteCommand("INSERT INTO cmp_phased(phased_kit,match_kit,chromosome,start_position,end_position,segment_image,segment_xml) VALUES (@phased_kit,@match_kit,@chromosome,@start_position,@end_position,@segment_image,@segment_xml)", conn);
                    cmd.Parameters.AddWithValue("@phased_kit", phased_kit);
                    cmd.Parameters.AddWithValue("@match_kit", unphased_kit);
                    cmd.Parameters.AddWithValue("@chromosome", chromosome);
                    cmd.Parameters.AddWithValue("@start_position", start_position);
                    cmd.Parameters.AddWithValue("@end_position", end_position);
                    byte[] image_bytes = GGKUtilLib.imageToByteArray(original);
                    cmd.Parameters.Add("@segment_image", DbType.Binary, image_bytes.Length).Value = image_bytes;
                    cmd.Parameters.AddWithValue("@segment_xml", segment_xml);
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
            }
        }
        private void AdmixtureFrm_Load(object sender, EventArgs e)
        {
            kitLbl.Text = kit + " (" + GGKUtilLib.getKitName(kit) + ")";
            DataTable dt    = GGKUtilLib.QueryDB("select name,at_total,at_longest,x,y FROM (select b.name,a.at_total,a.at_longest,b.x,b.y from cmp_status a,kit_master b where a.kit1='" + kit + "' and a.kit2=b.kit_no and a.kit2 like 'HGDP%' and a.status_autosomal=1 and a.at_longest<3 and a.at_total!=0 UNION select b.name,a.at_total,a.at_longest,b.x,b.y from cmp_status a,kit_master b where a.kit2='" + kit + "' and a.kit1=b.kit_no and a.kit1 like 'HGDP%' and a.status_autosomal=1 and a.at_longest<3 and a.at_total!=0) ORDER BY at_total DESC");
            double    total = 0.0;

            foreach (DataRow row in dt.Rows)
            {
                total += double.Parse(row.ItemArray[1].ToString());
            }

            DataTable adx_table = new DataTable();

            adx_table.Columns.Add("Population");
            adx_table.Columns.Add("Location");
            adx_table.Columns.Add("Total Shared (cM)");
            adx_table.Columns.Add("Longest (cM)");
            adx_table.Columns.Add("Percentage");
            adx_table.Columns.Add("X");
            adx_table.Columns.Add("Y");

            string population = null;
            string location   = null;
            double at_total   = 0.0;
            string at_longest = null;
            double percentage = 0.0;

            string[] data = null;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                data       = dt.Rows[i].ItemArray[0].ToString().Replace("_", " ").Split(new char[] { ',' });
                population = data[0];
                location   = data[1];
                at_total   = double.Parse(dt.Rows[i].ItemArray[1].ToString());
                at_longest = dt.Rows[i].ItemArray[2].ToString();
                percentage = (at_total * 100 / total);

                adx_table.Rows.Add(new object[] { population, location, at_total, at_longest, percentage.ToString("#0.00"), dt.Rows[i].ItemArray[3], dt.Rows[i].ItemArray[4] });

                chart1.Series[0].Points.AddXY(population + ", " + location + " (" + percentage.ToString("#0.00") + "%)", new object[] { percentage });
            }

            foreach (DataPoint p in chart1.Series[0].Points)
            {
                p.IsVisibleInLegend = false;
            }
            dgv_Admixture.Columns.Clear();
            dgv_Admixture.DataSource = adx_table;

            dgv_Admixture.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgv_Admixture.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgv_Admixture.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgv_Admixture.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgv_Admixture.Columns[4].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dgv_Admixture.Columns[5].Visible      = false;
            dgv_Admixture.Columns[6].Visible      = false;

            int      percent = 0;
            int      x       = 0;
            int      y       = 0;
            Image    img     = pbWorldMap.Image;
            Graphics g       = Graphics.FromImage(img);

            plotted.Clear();
            foreach (DataRow row in adx_table.Rows)
            {
                percent = (int)double.Parse(row.ItemArray[4].ToString());
                x       = int.Parse(row.ItemArray[5].ToString());
                y       = int.Parse(row.ItemArray[6].ToString());
                if (!plotted.Contains(x + ":" + y))
                {
                    if (percent > 50) // plotting 100% is too big and ugly.
                    {
                        percent = 50;
                    }
                    setHeatMap(g, percent, x, y);
                    plotted.Add(x + ":" + y);
                }
            }
            g.Save();

            pbWorldMap.Image = img;
        }
Beispiel #8
0
        private void bwPhaseVisualizer_DoWork(object sender, DoWorkEventArgs e)
        {
            DataTable dt2            = GGKUtilLib.QueryDB("select distinct kit_no from kit_phased");
            string    phased_kit     = null;
            string    unphased_kit   = null;
            string    chromosome     = null;
            string    start_position = null;
            string    end_position   = null;
            int       percent        = 0;

            foreach (DataRow row in dt2.Rows)
            {
                if (bwPhaseVisualizer.CancellationPending)
                {
                    break;
                }
                phased_kit = row.ItemArray[0].ToString();
                percent    = dt2.Rows.IndexOf(row) * 100 / dt2.Rows.Count;
                bwPhaseVisualizer.ReportProgress(percent, "Phased Segments for kit #" + phased_kit + " (" + GGKUtilLib.getKitName(phased_kit) + ") - Processing ...");

                DataTable dt3 = GGKUtilLib.QueryDB("select unphased_kit,chromosome,start_position,end_position FROM (select kit1'unphased_kit',chromosome,start_position,end_position from cmp_autosomal where kit2='" + phased_kit + "' UNION select kit2'unphased_kit',chromosome,start_position,end_position from cmp_autosomal where kit1='" + phased_kit + "') order by cast(chromosome as integer),start_position");

                foreach (DataRow row3 in dt3.Rows)
                {
                    if (bwPhaseVisualizer.CancellationPending)
                    {
                        break;
                    }
                    unphased_kit   = row3.ItemArray[0].ToString();
                    chromosome     = row3.ItemArray[1].ToString();
                    start_position = row3.ItemArray[2].ToString();
                    end_position   = row3.ItemArray[3].ToString();

                    DataTable exists = GGKUtilLib.QueryDB("select * from cmp_phased where phased_kit='" + phased_kit + "' and match_kit='" + unphased_kit + "' and chromosome='" + chromosome + "' and start_position=" + start_position + " and end_position=" + end_position);

                    if (exists.Rows.Count > 0)
                    {
                        //already exists...
                        if (!redo_visual)
                        {
                            bwPhaseVisualizer.ReportProgress(percent, "Segment [" + GGKUtilLib.getKitName(phased_kit) + ":" + GGKUtilLib.getKitName(unphased_kit) + "] Chr " + chromosome + ": " + start_position + "-" + end_position + ", Already Processed. Skipping ...");
                            continue;
                        }
                        else
                        {
                            GGKUtilLib.UpdateDB("DELETE from cmp_phased where phased_kit='" + phased_kit + "'");
                        }
                    }

                    bwPhaseVisualizer.ReportProgress(percent, "Segment [" + GGKUtilLib.getKitName(phased_kit) + ":" + GGKUtilLib.getKitName(unphased_kit) + "] Chr " + chromosome + ": " + start_position + "-" + end_position + ", Processing ...");


                    DataTable dt = GGKUtilLib.QueryDB("select a.position,a.genotype,p.paternal_genotype,p.maternal_genotype from kit_autosomal a,kit_phased p where a.kit_no='" + unphased_kit + "' and a.position>" + start_position + " and a.position<" + end_position + " and a.chromosome='" + chromosome + "' and p.rsid=a.rsid and p.kit_no='" + phased_kit + "' order by a.position");
                    if (dt.Rows.Count > 0)
                    {
                        if (bwPhaseVisualizer.CancellationPending)
                        {
                            break;
                        }

                        Image img = GGKUtilLib.getPhasedSegmentImage(dt, chromosome);

                        dt.TableName = "cmp_phased";
                        StringBuilder sb = new StringBuilder();
                        StringWriter  w  = new StringWriter(sb);
                        dt.WriteXml(w, XmlWriteMode.WriteSchema);
                        string segment_xml = sb.ToString();

                        SQLiteConnection conn = GGKUtilLib.getDBConnection();
                        SQLiteCommand    cmd  = new SQLiteCommand("INSERT INTO cmp_phased(phased_kit,match_kit,chromosome,start_position,end_position,segment_image,segment_xml) VALUES (@phased_kit,@match_kit,@chromosome,@start_position,@end_position,@segment_image,@segment_xml)", conn);
                        cmd.Parameters.AddWithValue("@phased_kit", phased_kit);
                        cmd.Parameters.AddWithValue("@match_kit", unphased_kit);
                        cmd.Parameters.AddWithValue("@chromosome", chromosome);
                        cmd.Parameters.AddWithValue("@start_position", start_position);
                        cmd.Parameters.AddWithValue("@end_position", end_position);
                        byte[] image_bytes = GGKUtilLib.imageToByteArray(img);
                        cmd.Parameters.Add("@segment_image", DbType.Binary, image_bytes.Length).Value = image_bytes;
                        cmd.Parameters.AddWithValue("@segment_xml", segment_xml);
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
                }
            }
        }
Beispiel #9
0
        private void bwROH_DoWork(object sender, DoWorkEventArgs e)
        {
            DataTable dt  = GGKUtilLib.QueryDB("select kit_no,roh_status from kit_master where reference=0 and disabled=0");
            string    kit = null;
            string    roh = null;

            foreach (DataRow row in dt.Rows)
            {
                if (bwROH.CancellationPending)
                {
                    break;
                }
                kit = row.ItemArray[0].ToString();
                roh = row.ItemArray[1].ToString();
                if (roh == "0")
                {
                    bwROH.ReportProgress(dt.Rows.IndexOf(row) * 100 / dt.Rows.Count, "Runs of Homozygosity for kit #" + kit + " (" + GGKUtilLib.getKitName(kit) + ") - Processing ...");
                    GGKUtilLib.ROH(kit);
                }
                else if (roh == "1")
                {
                    bwROH.ReportProgress(dt.Rows.IndexOf(row) * 100 / dt.Rows.Count, "Runs of Homozygosity for kit #" + kit + " (" + GGKUtilLib.getKitName(kit) + ") - Already Exists. Skipping..");
                }
            }
        }
Beispiel #10
0
 public MitoMapFrm(string kit)
 {
     InitializeComponent();
     this.kit    = kit;
     label1.Text = " " + kit + " (" + GGKUtilLib.getKitName(kit) + ")";
 }
        public void markOnTree()
        {
            match_map.Clear();
            foreach (TreeNode node in mutations_map.Keys)
            {
                node.ForeColor = Color.Black;
            }
            treeView1.CollapseAll();
            TreeNode name_maxpath = null;

            string my_marker = txtSNPs.Text;

            //dirty but ok for now
            my_marker = my_marker.Replace(",", " ").Replace("\t", " ").Replace("\r", " ").Replace("\n", " ");
            RegexOptions options = RegexOptions.None;
            Regex        regex   = new Regex(@"[ ]{2,}", options);

            my_marker = regex.Replace(my_marker, @" ");
            my_marker = my_marker.Replace(" ", ",");
            string[] marker_array = my_marker.Split(",".ToCharArray());
            string   marker_names = "";
            string   m_name       = "";

            string[]  marker_names_on_hg = null;
            ArrayList list = new ArrayList();

            foreach (TreeNode key in mutations_map.Keys)
            {
                marker_names       = (string)mutations_map[key];
                marker_names_on_hg = marker_names.Split(",".ToCharArray());
                foreach (string marker_name in marker_names_on_hg)
                {
                    m_name = marker_name.Replace("(", "").Replace(")", "").Replace("!", "");

                    foreach (string marker in marker_array)
                    {
                        // if on ignore list, just ignore
                        //foreach (string ignore in ignore_list)
                        //{
                        //    if (marker.IndexOf(ignore) != -1)
                        //        continue;
                        //}

                        //if (m_name.Trim() == marker.Trim())
                        if (marker.Trim().IndexOf(m_name.Trim()) != -1 || m_name.Trim() == marker.Trim())
                        {
                            //if (key.GetNodeCount(true) == 0)
                            if (!list.Contains(key))
                            {
                                list.Add(key);
                            }
                            if (!match_map.ContainsKey(key))
                            {
                                match_map.Add(key, m_name);
                            }
                            key.ForeColor = Color.White;
                            key.BackColor = Color.DarkGreen;
                            key.EnsureVisible();
                            //break;
                        }
                    }
                }
            }

            //
            // go through all terminals with matches and count the number of matching parents. now, that's the score.
            SortedList <int, ArrayList> best_score = new SortedList <int, ArrayList>();
            int       pm    = 0;
            ArrayList alist = new ArrayList();

            foreach (TreeNode key in list)
            {
                pm = getParentMatches(key);
                if (best_score.ContainsKey(pm))
                {
                    alist = best_score[pm];
                }
                else
                {
                    alist = new ArrayList();
                }
                alist.Add(key);
                best_score.Remove(pm);
                best_score.Add(pm, alist);
            }

            var desc = best_score.Reverse();
            //
            //int count = 1;
            ArrayList mlist        = null;
            bool      found_first  = false;
            bool      found_second = false;

            report.Clear();
            //
            report.Append("<html><head><title>mtDNA Report for " + GGKUtilLib.getKitName(kit) + " (" + kit + ")</title></head><body>");
            report.Append("<h1>mtDNA Report for " + GGKUtilLib.getKitName(kit) + " (" + kit + ")</h2>");
            report.Append("<b>User Entered Markers: </b>" + my_marker);

            sorted_report_array.Clear();
            sorted_hg_readjustment.Clear();
            foreach (var item in desc)
            {
                KeyValuePair <int, ArrayList> kvp = item;
                //
                mlist = (ArrayList)kvp.Value;
                string str = "";
                if (!found_first)
                {
                    foreach (TreeNode tn in mlist)
                    {
                        if (isMatchingAll(tn, marker_array))
                        {
                            name_maxpath = tn;
                            str          = str + " " + tn.Text;
                            found_first  = true;
                        }
                    }
                    lblyhg.Text = str.Trim().Replace(" ", ", ");
                    if (found_first)
                    {
                        continue;
                    }
                }
                else if (!found_second)
                {
                    foreach (TreeNode tn in mlist)
                    {
                        if (isMatchingAll(tn, marker_array))
                        {
                            //name_maxpath = tn;
                            str          = str + " " + tn.Text;
                            found_second = true;
                        }
                    }
                    lblSb.Text = str.Trim().Replace(" ", ", ");
                    if (found_second)
                    {
                        break;
                    }
                }
                //
                //if (count == 1)
                //{
                //    mlist = (ArrayList)kvp.Value;
                //    string str = "";
                //    foreach (TreeNode tn in mlist)
                //    {
                //        if (isMatchingAll(tn, marker_array))
                //        {
                //            name_maxpath = tn;
                //            str = str + " " + tn.Text;
                //        }
                //    }
                //    lblyhg.Text = str.Trim().Replace(" ", ", ");
                //}
                //else if (count == 2)
                //{
                //    mlist = (ArrayList)kvp.Value;
                //    string str = "";
                //    foreach (TreeNode tn in mlist)
                //    {
                //        if (isMatchingAll(tn, marker_array))
                //        {
                //            str = str + " " + tn.Text;
                //        }
                //    }
                //    lblSb.Text = str.Trim().Replace(" ",", ");
                //}
                //else if(count>2)
                //    break;
                //count++;
            }

            // --  final readjustment .. it's dirty
            found_first  = false;
            found_second = false;
            string    mstr   = "";
            ArrayList m_list = null;

            foreach (KeyValuePair <int, ArrayList> hg in sorted_hg_readjustment)
            {
                m_list = hg.Value;
                foreach (TreeNode mhg in m_list)
                {
                    mstr = mstr + " " + mhg.Text;
                }

                if (!found_first)
                {
                    name_maxpath = (TreeNode)m_list[0];
                    lblyhg.Text  = mstr.Trim().Replace(" ", ", ");
                    found_first  = true;
                    mstr         = "";
                }
                else if (!found_second)
                {
                    lblSb.Text = mstr.Trim().Replace(" ", ", ");
                    break;
                }
            }
            //


            foreach (TreeNode node in mutations_map.Keys)
            {
                if (node.BackColor != Color.DarkGreen)
                {
                    node.ForeColor = Color.LightGray;
                }
            }
            if (name_maxpath != null)
            {
                //name_maxpath.NodeFont = new Font("Microsoft Sans Serif", 7.8f, FontStyle.Underline);
                name_maxpath.EnsureVisible();
                //lblyhg.Text = name_maxpath.Text;
                //name_maxpath
                treeView1.SelectedNode = name_maxpath;
            }

            //TreeNode parent=name_maxpath;
            //mtchart.Series.Clear();
            //while(parent.Text!="Eve")
            //{
            //    Series series = mtchart.Series.Add(parent.Text);

            //    int count = mutations_map[parent].ToString().Split(new char[]{','}).Length;
            //    series.ChartType = SeriesChartType.StackedBar;
            //    series.LabelToolTip = parent.Text+" ("+count.ToString() + " mutations)";
            //    series.Points.AddY(count);
            //    parent = parent.Parent;
            //}
        }
Beispiel #12
0
 private void ROHFrm_Load(object sender, EventArgs e)
 {
     GGKUtilLib.setStatus("Calculating ROH ...");
     this.Text = "Runs of Homozygosity - " + kit + " (" + GGKUtilLib.getKitName(kit) + ")";
     bwROH.RunWorkerAsync(kit);
 }
Beispiel #13
0
        private void bwSave_DoWork(object sender, DoWorkEventArgs e)
        {
            save_success = false;
            Object[] args   = (Object[])e.Argument;
            string   kit_no = args[0].ToString();
            string   name   = args[1].ToString();
            DataGridViewRowCollection rows = (DataGridViewRowCollection)args[2];
            string ysnps_list = args[3].ToString();
            string mutations  = args[4].ToString();

            DataGridViewRowCollection[] dgvy_rows = (DataGridViewRowCollection[])args[5];
            string sex   = args[6].ToString();
            string fasta = args[7].ToString();

            SQLiteConnection cnn = GGKUtilLib.getDBConnection();

            try
            {
                SQLiteCommand upCmd = null;
                //kit master
                string kit_name = GGKUtilLib.getKitName(kit_no);
                if (kit_name == "Unknown")
                {
                    // new kit
                    upCmd = new SQLiteCommand(@"INSERT OR REPLACE INTO kit_master(kit_no, name, sex)values(@kit_no,@name,@sex)", cnn);
                    upCmd.Parameters.AddWithValue("@kit_no", kit_no);
                    upCmd.Parameters.AddWithValue("@name", name);
                    upCmd.Parameters.AddWithValue("@sex", sex[0].ToString());
                    upCmd.ExecuteNonQuery();
                }
                else
                {
                    // kit exists
                    upCmd = new SQLiteCommand(@"UPDATE kit_master SET name=@name, sex=@sex WHERE kit_no=@kit_no", cnn);
                    upCmd.Parameters.AddWithValue("@name", name);
                    upCmd.Parameters.AddWithValue("@sex", sex[0].ToString());
                    upCmd.Parameters.AddWithValue("@kit_no", kit_no);
                    upCmd.ExecuteNonQuery();
                }
                upCmd.Dispose();
                bwSave.ReportProgress(35, "Saving Autosomal data ...");


                upCmd = new SQLiteCommand(@"DELETE from kit_autosomal where kit_no=@kit_no", cnn);
                upCmd.Parameters.AddWithValue("@kit_no", kit_no);
                upCmd.ExecuteNonQuery();

                //kit autosomal
                upCmd = new SQLiteCommand(@"INSERT OR REPLACE INTO kit_autosomal(kit_no, rsid,chromosome,position,genotype)values(@kit_no,@rsid,@chromosome,@position,@genotype)", cnn);

                using (var transaction = cnn.BeginTransaction())
                {
                    bool incomplete = false;
                    foreach (DataGridViewRow row in rows)
                    {
                        if (row.IsNewRow)
                        {
                            continue;
                        }
                        incomplete = false;
                        for (int c = 0; c < row.Cells.Count; c++)
                        {
                            if (row.Cells[c].Value == null)
                            {
                                incomplete = true;
                                break;
                            }
                            else if (row.Cells[c].Value.ToString().Trim() == "")
                            {
                                incomplete = true;
                                break;
                            }
                        }

                        if (incomplete)
                        {
                            continue;
                        }

                        upCmd.Parameters.AddWithValue("@kit_no", kit_no);
                        upCmd.Parameters.AddWithValue("@rsid", row.Cells[0].Value.ToString());
                        upCmd.Parameters.AddWithValue("@chromosome", row.Cells[1].Value.ToString());
                        upCmd.Parameters.AddWithValue("@position", row.Cells[2].Value.ToString());
                        upCmd.Parameters.AddWithValue("@genotype", row.Cells[3].Value.ToString());
                        upCmd.ExecuteNonQuery();
                    }
                    transaction.Commit();
                }

                upCmd.Dispose();


                bwSave.ReportProgress(75, "Saving Y-SNPs ...");


                if (ysnps_list.Trim() != "")
                {
                    //kit ysnps
                    upCmd = new SQLiteCommand(@"INSERT OR REPLACE INTO kit_ysnps(kit_no, ysnps) values (@kit_no,@ysnps)", cnn);
                    upCmd.Parameters.AddWithValue("@kit_no", kit_no);
                    upCmd.Parameters.AddWithValue("@ysnps", ysnps_list);
                    upCmd.ExecuteNonQuery();
                    upCmd.Dispose();
                }


                //kit ystr
                bwSave.ReportProgress(80, "Saving Y-STR Values ...");

                upCmd = new SQLiteCommand(@"DELETE from kit_ystr where kit_no=@kit_no", cnn);
                upCmd.Parameters.AddWithValue("@kit_no", kit_no);
                upCmd.ExecuteNonQuery();

                upCmd = new SQLiteCommand(@"INSERT OR REPLACE INTO kit_ystr(kit_no, marker, value)values(@kit_no,@marker,@value)", cnn);
                using (var transaction = cnn.BeginTransaction())
                {
                    foreach (DataGridViewRowCollection row_collection in dgvy_rows)
                    {
                        foreach (DataGridViewRow row in row_collection)
                        {
                            if (row.IsNewRow)
                            {
                                continue;
                            }
                            if (row.Cells[1].Value.ToString().Trim() == "")
                            {
                                continue;
                            }
                            upCmd.Parameters.AddWithValue("@kit_no", kit_no);
                            upCmd.Parameters.AddWithValue("@marker", row.Cells[0].Value.ToString());
                            upCmd.Parameters.AddWithValue("@value", row.Cells[1].Value.ToString());
                            upCmd.ExecuteNonQuery();
                        }
                    }
                    transaction.Commit();
                }
                upCmd.Dispose();

                //kit mtdna
                if (mutations.Trim() != "" || fasta.Trim() != "")
                {
                    bwSave.ReportProgress(90, "Saving mtDNA mutations ...");
                    upCmd = new SQLiteCommand(@"INSERT OR REPLACE INTO kit_mtdna(kit_no, mutations,fasta)values(@kit_no,@mutations,@fasta)", cnn);
                    upCmd.Parameters.AddWithValue("@kit_no", kit_no);
                    upCmd.Parameters.AddWithValue("@mutations", mutations);
                    upCmd.Parameters.AddWithValue("@fasta", fasta);
                    upCmd.ExecuteNonQuery();
                }
                bwSave.ReportProgress(100, "Saved");
                save_success = true;
            }
            catch (Exception err)
            {
                bwSave.ReportProgress(-1, "Not Saved. Tech Details: " + err.Message);
                MessageBox.Show("Not Saved. Techical Details: " + err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            cnn.Dispose();
        }