Beispiel #1
0
        private void bwNewKitAutosomalJob_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                DataTable table = new DataTable();
                table.Columns.Add("RSID");
                table.Columns.Add("Chromosome");
                table.Columns.Add("Position");
                table.Columns.Add("Genotype");


                string[] filePaths = (string[])e.Argument;

                foreach (string file_path in filePaths)
                {
                    Object[]      dnaout    = GGKUtilLib.getAutosomalDNAList(file_path);
                    ArrayList     rows      = (ArrayList)dnaout[0];
                    List <string> ysnps_arr = (List <string>)dnaout[1];
                    ArrayList     mtdna_arr = (ArrayList)dnaout[2];
                    bwNewKitAutosomalJob.ReportProgress(-1, rows.Count.ToString() + " SNPs found in " + Path.GetFileName(file_path));
                    int count    = 0;
                    int percent  = 0;
                    int ppercent = 0;

                    foreach (string[] row in rows)
                    {
                        percent = (count * 100) / rows.Count;
                        if (ppercent != percent)
                        {
                            bwNewKitAutosomalJob.ReportProgress(percent, " " + percent.ToString() + "%");
                            ppercent = percent;
                        }

                        table.Rows.Add(row);
                        count++;
                    }

                    //
                    if (ysnps_arr.Count != 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        ysnps_arr = ysnps_arr.Distinct().ToList();
                        foreach (string snp in ysnps_arr)
                        {
                            sb.Append(snp + ", ");
                        }
                        if (ysnps == null)
                        {
                            ysnps = sb.ToString().Trim();
                        }
                        else
                        {
                            ysnps = ysnps + sb.ToString().Trim();
                        }
                        if (ysnps.Length > 0)
                        {
                            ysnps = ysnps.Substring(0, ysnps.Length - 1);
                        }
                    }

                    if (mtdna_arr.Count != 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (string mut in mtdna_arr)
                        {
                            sb.Append(mut + ", ");
                        }

                        if (mtdna == null)
                        {
                            mtdna = sb.ToString().Trim();
                        }
                        else
                        {
                            mtdna = mtdna + sb.ToString().Trim();
                        }
                        if (mtdna.Length > 0)
                        {
                            mtdna = mtdna.Substring(0, mtdna.Length - 1);
                        }
                    }
                }


                this.Invoke(new MethodInvoker(delegate
                {
                    dataGridViewAutosomal.Columns.Clear();
                    dataGridViewAutosomal.DataSource = table;
                    foreach (DataGridViewColumn col in dataGridViewAutosomal.Columns)
                    {
                        col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                    }
                }));
            }
            catch (Exception)
            {
                // something. The most probable cause is user just exited. so, just cancel the job...
            }
        }