15 getopts('pc', \%opts);
16 die("Usage: wgsim_eval.pl [-pc] <in.sam>\n") if (@ARGV == 0 && -t STDIN);
18 my ($max_q, $flag) = (0, 0);
20 $flag |= 1 if (defined $opts{p});
21 $flag |= 2 if (defined $opts{c});
25 my ($q, $is_correct, $chr, $left, $rght) = (int($t[4]/10), 1, $t[2], $t[3], $t[3]);
26 $max_q = $q if ($q > $max_q);
28 $_ = $t[5]; s/(\d+)[MDN]/$rght+=$1,'x'/eg;
30 # correct for soft clipping
31 $left -= $1 if (/^(\d+)S/);
32 $rght += $1 if (/(\d+)S$/);
34 next if (($t[1]&0x4) || $chr eq '*');
35 # parse read name and check
37 if ($t[0] =~ /^(\S+)_(\d+)_(\d+)_/) {
38 if ($1 ne $chr) { # different chr
42 if (($t[1]&0x40) && !($t[1]&0x10)) { # F3, forward
43 $is_correct = 0 if (abs($2 - $left) > $gap);
44 } elsif (($t[1]&0x40) && ($t[1]&0x10)) { # F3, reverse
45 $is_correct = 0 if (abs($3 - $rght) > $gap);
46 } elsif (($t[1]&0x80) && !($t[1]&0x10)) { # R3, forward
47 $is_correct = 0 if (abs($3 - $left) > $gap);
48 } else { # R3, reverse
49 $is_correct = 0 if (abs($2 - $rght) > $gap);
52 if ($t[1] & 0x10) { # reverse
53 $is_correct = 0 if (abs($3 - $rght) > $gap); # in case of indels that are close to the end of a reads
55 $is_correct = 0 if (abs($2 - $left) > $gap);
60 die("[wgsim_eval] read '$t[0]' was not generated by wgsim?\n");
62 ++$c1[$q] unless ($is_correct);
63 print STDERR $line if (($flag&1) && !$is_correct && $q > 0);
66 my ($cc0, $cc1) = (0, 0);
67 for (my $i = $max_q; $i >= 0; --$i) {
68 $c0[$i] = 0 unless (defined $c0[$i]);
69 $c1[$i] = 0 unless (defined $c1[$i]);
70 $cc0 += $c0[$i]; $cc1 += $c1[$i];
71 printf("%.2dx %12d / %-12d %12d %.3e\n", $i, $c1[$i], $c0[$i], $cc0, $cc1/$cc0);