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});
26 my ($q, $is_correct, $chr, $left, $rght) = (int($t[4]/10), 1, $t[2], $t[3], $t[3]);
27 $max_q = $q if ($q > $max_q);
29 $_ = $t[5]; s/(\d+)[MDN]/$rght+=$1,'x'/eg;
31 # correct for soft clipping
32 $left -= $1 if (/^(\d+)S/);
33 $rght += $1 if (/(\d+)S$/);
35 next if (($t[1]&0x4) || $chr eq '*');
36 # 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 warn("[wgsim_eval] read '$t[0]' was not generated by wgsim?\n");
64 ++$c1[$q] unless ($is_correct);
65 print STDERR $line if (($flag&1) && !$is_correct && $q > 0);
68 my ($cc0, $cc1) = (0, 0);
69 for (my $i = $max_q; $i >= 0; --$i) {
70 $c0[$i] = 0 unless (defined $c0[$i]);
71 $c1[$i] = 0 unless (defined $c1[$i]);
72 $cc0 += $c0[$i]; $cc1 += $c1[$i];
73 printf("%.2dx %12d / %-12d %12d %.3e\n", $i, $c1[$i], $c0[$i], $cc0, $cc1/$cc0);