public void processFile(string input_file)
        {
            SortedDictionary <int, string>[][] chr_v4 = null;

            string[] files = Directory.GetFiles(data_files_folder);
            int      total = files.Length;

            Program.addLog("Input file : " + input_file);

            DateTime start = DateTime.Now;
            int      count = 0;

            start = DateTime.Now;
            ParallelOptions options = new ParallelOptions();

            options.MaxDegreeOfParallelism = Environment.ProcessorCount;
            chr_v4 = new CompareUtil().NormalizeData(input_file);
            Object lockobj = new Object();

            Parallel.For(0, files.Length, options, i =>
            {
                count++;
                try
                {
                    lock (lockobj)
                    {
                        if (Path.GetFileNameWithoutExtension(files[i]) != Path.GetFileNameWithoutExtension(input_file))
                        {
                            if (!(File.Exists(out_folder + Path.GetFileNameWithoutExtension(input_file) + "-" + Path.GetFileNameWithoutExtension(files[i])) ||
                                  File.Exists(out_folder + Path.GetFileNameWithoutExtension(files[i]) + "-" + Path.GetFileNameWithoutExtension(input_file))))
                            {
                                CompareTask task = new CompareTask(data_files_folder, out_folder, snp_threshold, base_pairs_threshold, files[i], chr_v4, input_file);
                                task.doCompare();
                            }
                        }
                    }
                }
                catch (Exception) { }
                Program.addLog(count + " / " + total + ", Remaining: " + (int)(((DateTime.Now.Subtract(start).TotalSeconds / count) * (total - count)) / 60) + " mins.    ");
            });
        }
Exemplo n.º 2
0
        public void doCompare()
        {
            //Console.WriteLine("Comparing .." + Path.GetFileName(fv3));

            ArrayList output_text = new ArrayList();

            StringBuilder sb_result = new StringBuilder();
            ArrayList     chr_rm    = new ArrayList();

            output_text.Clear();
            SortedDictionary <int, string>[][] chr_v3 = new CompareUtil().NormalizeData(fv3);
            chr_rm.Clear();
            for (int i = 0; i < 23; i++)
            {
                if (chr_v3[0][i] == null || chr_v4[0][i] == null)
                {
                    continue;
                }
                chr_rm.Clear();
                foreach (int position in chr_v3[0][i].Keys)
                {
                    if (!chr_v4[0][i].ContainsKey(position)) //these SNPs are not tested.. on the other match
                    {
                        chr_rm.Add(position);
                    }
                }
                //foreach (int position in chr_rm)
                //    chr_v4[0][i].Add(position, chr_v3[0][i][position]);
                foreach (int position in chr_rm)
                {
                    chr_v4[0][i].Add(position, "--");
                }
            }
            //

            int           segment_start         = 0;
            int           segment_end           = 0;
            double        total_mb              = 0;
            int           snp_count             = 0;
            string        genotype_v3           = null;
            string        genotype_v4           = null;
            List <int>    keys                  = null;
            string        rsid                  = null;
            List <string> shared                = new List <string>();
            int           last_success_position = 0;
            string        file                  = null;

            for (int i = 0; i < 23; i++)
            {
                if (chr_v3[0][i] == null || chr_v4[0][i] == null)
                {
                    continue;
                }
                //
                snp_count             = 0;
                keys                  = chr_v3[0][i].Keys.ToList();
                segment_start         = -1;
                last_success_position = 0;
                shared.Clear();
                string shared_gt = null;
                int    prev_pos  = 0;
                foreach (int position in keys)
                {
                    if (chr_v3[0][i] == null || chr_v4[0][i] == null) // doesn't exist in file.
                    {
                        continue;
                    }
                    genotype_v3 = chr_v3[0][i][position];
                    genotype_v4 = chr_v4[0][i][position];
                    rsid        = chr_v3[1][i][position];

                    if ((shared_gt = new CompareUtil().getShared(genotype_v3, genotype_v4)) != null && position - prev_pos < 50000)
                    {
                        // each position recorded is a snp

                        if (segment_start == -1)
                        {
                            segment_start = position;
                            shared.Clear();
                        }
                        snp_count++;
                        if (i + 1 == 23)
                        {
                            shared.Add(rsid + "\tX\t" + position + "\t" + shared_gt);
                        }
                        else
                        {
                            shared.Add(rsid + "\t" + (i + 1).ToString() + "\t" + position + "\t" + shared_gt);
                        }
                        last_success_position = position;
                    }
                    else
                    {
                        if (segment_start != -1)
                        {
                            segment_end = last_success_position;
                            total_mb    = segment_end - segment_start;
                            if (snp_count > snp_threshold && total_mb > base_pairs_threshold)
                            {
                                file = Path.GetFileNameWithoutExtension(input_file) + "-" + Path.GetFileNameWithoutExtension(fv3);
                                string file_alt = Path.GetFileNameWithoutExtension(fv3) + "-" + Path.GetFileNameWithoutExtension(input_file);
                                File.AppendAllLines(out_folder + file, shared);
                                shared.Clear();
                            }
                        }
                        segment_start = -1;
                        snp_count     = 0;
                    }
                    prev_pos = position;
                }
                ///
                if (segment_start != -1)
                {
                    segment_end = last_success_position;
                    total_mb    = keys[keys.Count - 1] - segment_start;
                    if (snp_count > snp_threshold && total_mb > base_pairs_threshold)
                    {
                        file = Path.GetFileNameWithoutExtension(input_file) + "-" + Path.GetFileNameWithoutExtension(fv3);
                        string file_alt = Path.GetFileNameWithoutExtension(fv3) + "-" + Path.GetFileNameWithoutExtension(input_file);
                        File.AppendAllLines(out_folder + file, shared);
                        shared.Clear();
                    }
                }
                snp_count = 0;

                ///
            }
        }