]> git.donarmstrong.com Git - samtools.git/blob - misc/indel_filter.pl
fixed a bug in generating tag AM
[samtools.git] / misc / indel_filter.pl
1 #!/usr/bin/perl -w
2
3 # Contact: lh3
4
5 use strict;
6 use warnings;
7 use Getopt::Std;
8
9 my %opts = (D=>100, m=>10, r=>undef);
10 getopts('D:m:r', \%opts);
11
12 die(qq/
13 Usage:   indel_filter.pl [options] <in.indel>\n
14 Options: -D INT    maximum read depth [$opts{D}]
15          -m INT    minimum distance between two adjacent indels [$opts{m}]
16 \n/) if (@ARGV == 0 && -t STDIN);
17
18 my (@arr1, @arr2);
19 my ($curr, $last) = (\@arr1, \@arr2);
20 my $is_ref = defined($opts{r})? 1 : 0;
21 while (<>) {
22   my @t = split;
23   next if ($t[2] ne '*');
24   if (!$is_ref) {
25         next if ($t[3] eq '*/*');
26         next if ($t[5] == 0);
27   }
28   next if ($t[8] + $t[9] + $t[10] + $t[11] > $opts{D});
29   @$curr = ($t[0], $t[1], $t[5], $_);
30   my $do_swap = 1;
31   if (defined $last->[0]) {
32         if ($curr->[0] eq $last->[0] && $last->[1] + $opts{m} > $curr->[1]) {
33           $do_swap = 0 if ($last->[2] > $curr->[2]);
34         } else { # then print
35           print $last->[3];
36         }
37   }
38   if ($do_swap) {
39         my $tmp = $curr; $curr = $last; $last = $tmp;
40   }
41 }
42 print $last->[3] if (defined $last->[0]);