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
36 if ($t[0] =~ /^(\S+)_(\d+)_(\d+)_/) {
37 if ($1 ne $chr) { # different chr
41 if (($t[1]&0x40) && !($t[1]&0x10)) { # F3, forward
42 $is_correct = 0 if (abs($2 - $left) > $gap);
43 } elsif (($t[1]&0x40) && ($t[1]&0x10)) { # F3, reverse
44 $is_correct = 0 if (abs($3 - $rght) > $gap);
45 } elsif (($t[1]&0x80) && !($t[1]&0x10)) { # R3, forward
46 $is_correct = 0 if (abs($3 - $left) > $gap);
47 } else { # R3, reverse
48 $is_correct = 0 if (abs($2 - $rght) > $gap);
51 if ($t[1] & 0x10) { # reverse
52 $is_correct = 0 if (abs($3 - $rght) > $gap); # in case of indels that are close to the end of a reads
54 $is_correct = 0 if (abs($2 - $left) > $gap);
59 warn("[wgsim_eval] read '$t[0]' was not generated by wgsim?\n");
63 ++$c1[$q] unless ($is_correct);
64 print STDERR $line if (($flag&1) && !$is_correct && $q > 0);
67 my ($cc0, $cc1) = (0, 0);
68 for (my $i = $max_q; $i >= 0; --$i) {
69 $c0[$i] = 0 unless (defined $c0[$i]);
70 $c1[$i] = 0 unless (defined $c1[$i]);
71 $cc0 += $c0[$i]; $cc1 += $c1[$i];
72 printf("%.2dx %12d / %-12d %12d %.3e\n", $i, $c1[$i], $c0[$i], $cc0, $cc1/$cc0);