Пример #1
0
        // bin\bgzip.exe bam_chrY.vcf
        // bin\tabix.exe bam_chrY.vcf.gz
        // bin\bcftools.exe query -f '%POS\t[%TGT]\n' -r chrY:3131128-3131246 bam_chrY.vcf.gz > DYS393.txt

        static void Main(string[] args)
        {
            StringBuilder report = new StringBuilder();

            if (args.Length != 3)
            {
                Console.WriteLine("*** This program is not designed to work independently. Use it at your own risk ***");
                Console.WriteLine("ystrfinder.exe <ref> <in_vcf_bgz> <out_report_html>");
                return;
            }

            string yref_file   = args[0]; //"ystr_info.txt";
            string intput_file = args[1]; // @"C:\Genetics\Y-STR Kit\bam_chrY.vcf.gz";
            string out_file    = args[2];

            if (!File.Exists(yref_file) || !File.Exists(intput_file))
            {
                Console.WriteLine("input/ref does not exist!");
                return;
            }

            YSTRLib ylib = new YSTRLib(intput_file);

            string[] lines         = File.ReadAllLines(yref_file);
            string[] data          = null;
            string   ystr          = null;
            long     begin_pos     = 0;
            long     end_pos       = 0;
            string   regex_motif   = null;
            string   filter_motif  = null;
            string   replace_regex = null;

            String rpt_table_overview = Y_STR_Finder.Properties.Resources.ystr_overview;

            report.Append("<html><head><title>Y-STR Kit Report</title></head><body style='font-family:Calibri; Color:black; font-style:normal'><h1>Y-STR Kit Report</h1>");
            report.Append("@TABLE@");
            foreach (string line in lines)
            {
                if (line.StartsWith("#") || line.Trim() == "")
                {
                    continue;
                }

                data = line.Split(new char[] { '\t' });

                if (data[0].StartsWith("TITLE"))
                {
                    report.Append("<h2>" + data[1] + "</h2>");
                    continue;
                }

                ystr = data[0];

                begin_pos     = long.Parse(data[1]);
                end_pos       = long.Parse(data[2]);
                regex_motif   = data[3];
                filter_motif  = data[4];
                replace_regex = data[5];

                YStrResult result = ylib.getYSTR(begin_pos, end_pos, regex_motif, filter_motif, replace_regex);
                //Console.WriteLine(ystr + " = " + result.value+"\t["+result.reliability+"]");
                report.Append("<a name='" + ystr + "'></a>");
                report.Append("<h3>" + ystr + " = " + result.value + "</h3>");
                report.Append("<i>Location: ChrY:" + begin_pos + "-" + end_pos + "</i><br>");
                report.Append("<div style='width:600px; padding:10px;word-wrap: break-word;color:#909090;font-family: monospace;'>" + result.html_seq + "</div>");
                report.Append("<i>Reliability is " + result.reliability + "%</i><br><br>");

                rpt_table_overview = rpt_table_overview.Replace("@" + ystr + "@", result.value.ToString());

                if (result.reliability == 100)
                {
                    rpt_table_overview = rpt_table_overview.Replace("@" + ystr + "_COLOR@", "green");
                }
                else
                {
                    rpt_table_overview = rpt_table_overview.Replace("@" + ystr + "_COLOR@", "red");
                }

                //Console.WriteLine(result.raw_seq);
                //Console.WriteLine();
            }



            report.Append("<i>Report generated by <a href='http://www.y-str.org/'>Y-STR Kit</a>.</i>");
            report.Append("</body></html>");

            string final_report = report.ToString();

            final_report = final_report.Replace("@TABLE@", rpt_table_overview);

            File.WriteAllText(out_file, final_report);
        }
Пример #2
0
        private YStrResult getYSTR(string bcfout_file, string motif_regex, string filter_regex, string replace_regex, long pos_start, long pos_end)
        {
            YStrResult result = new YStrResult();

            try
            {
                string[] data   = null;
                long     pos    = 0;
                string   allele = "";

                Dictionary <long, string> sequence = new Dictionary <long, string>();
                string tmp = "";
                foreach (string line in File.ReadLines(bcfout_file))
                {
                    data   = line.Split(new char[] { '\t' });
                    pos    = long.Parse(data[0]);
                    allele = data[1].Split(new char[] { '/' })[0].Trim();

                    if (sequence.ContainsKey(pos))
                    {
                        tmp = sequence[pos];
                        if (tmp.Length < allele.Length)
                        {
                            sequence.Remove(pos);
                            sequence.Add(pos, allele);
                        }
                    }
                    else
                    {
                        sequence.Add(pos, allele);
                    }
                }

                long m_max = sequence.Keys.Max();
                long m_min = sequence.Keys.Min();

                StringBuilder sb = new StringBuilder();
                for (long i = m_min; i <= m_max; i++)
                {
                    if (sequence.ContainsKey(i))
                    {
                        sb.Append(sequence[i]);
                    }
                    else
                    {
                        sb.Append("N");
                    }
                }

                result.reliability = 100;

                if (m_max - m_min != pos_end - pos_start)
                {
                    result.reliability = (int)((m_max - m_min) * 100 / (pos_end - pos_start));
                }

                string seq = sb.ToString();

                if (seq.Contains("N"))
                {
                    result.reliability = (int)(((seq.Count() - seq.Count(x => x == 'N')) * result.reliability) / (m_max - m_min));
                }

                result.raw_seq = seq;

                string html_seq = seq;

                for (long i = pos_start; i < m_min; i++)
                {
                    html_seq = "N" + html_seq;
                }
                for (long i = m_max; i <= pos_end; i++)
                {
                    html_seq = html_seq + "N";
                }

                if (replace_regex == "CONCAT")
                {
                    MatchCollection mc = Regex.Matches(seq, filter_regex);
                    seq = "";
                    foreach (Match m in mc)
                    {
                        seq     += m.Value;
                        html_seq = html_seq.Replace(m.Value, Regex.Replace(m.Value, "(" + motif_regex + ")", "<span style='border-color:lightblue;border-style: solid; border-width: 1px;background: -webkit-linear-gradient(left top, white , lightblue); background: -o-linear-gradient(bottom right, white, lightblue); background: -moz-linear-gradient(bottom right, white, lightblue); background: linear-gradient(to bottom right, white , lightblue);color:blue'>$1</span>"));
                    }
                }
                else
                {
                    html_seq = html_seq.Replace(seq, Regex.Replace(seq, "(" + motif_regex + ")", "<span style='border-color:lightblue;border-style: solid; border-width: 1px;background: -webkit-linear-gradient(left top, white , lightblue); background: -o-linear-gradient(bottom right, white, lightblue); background: -moz-linear-gradient(bottom right, white, lightblue); background: linear-gradient(to bottom right, white , lightblue);color:blue'>$1</span>"));
                    seq      = Regex.Replace(seq, filter_regex, replace_regex);
                }

                result.html_seq = html_seq.Replace("N", "<span style='color:#a0a0a0;'>&middot;</span>");

                //Console.WriteLine(">> "+seq + "\r\n");
                MatchCollection matches = Regex.Matches(seq, motif_regex);
                result.value = matches.Count;
            }
            catch (Exception)
            {
                result.value = 0;
            }
            return(result);
        }