16 die("Usage: wgsim_eval.pl [-p] <in.sam>\n") if (@ARGV == 0 && -t STDIN);
22 my ($q, $is_correct, $chr, $left, $rght) = (int($t[4]/10), 1, $t[2], $t[3], $t[3]);
23 $max_q = $q if ($q > $max_q);
25 $_ = $t[5]; s/(\d+)[MDN]/$rght+=$1,'x'/eg;
27 # correct for soft clipping
28 $left -= $1 if (/^(\d+)S/);
29 $rght += $1 if (/(\d+)S$/);
31 next if (($t[1]&0x4) || $chr eq '*');
32 # parse read name and check
34 if ($t[0] =~ /^(\S+)_(\d+)_(\d+)_[0-9a-f]+(\/[12])?$/) {
35 if ($1 ne $chr) { # different chr
37 } elsif ($2 < $3) { # should always be true if reads are generated from wgsim
38 if ($t[1] & 0x10) { # reverse
39 $is_correct = 0 if (abs($3 - $rght) > 5); # in case of indels that are close to the end of a reads
41 $is_correct = 0 if (abs($2 - $left) > 5);
44 die("[wgsim_eval] bug in wgsim?\n");
47 die("[wgsim_eval] read '$t[0]' was not generated by wgsim?\n");
49 ++$c1[$q] unless ($is_correct);
50 print $line if (defined($opts{p}) && !$is_correct);
53 my ($cc0, $cc1) = (0, 0);
54 for (my $i = $max_q; $i >= 0; --$i) {
55 $c0[$i] = 0 unless (defined $c0[$i]);
56 $c1[$i] = 0 unless (defined $c1[$i]);
57 $cc0 += $c0[$i]; $cc1 += $c1[$i];
58 printf("%.2dx %12d / %-12d %12d %.3e\n", $i, $c1[$i], $c0[$i], $cc0, $cc1/$cc0);