#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
# Filter out the exact/direct overlaps from tab seperated alignment file. (lastz format=general- ready)
# Do not inclide header in lastz outfile
# USAGE: perl filterOverlaps.pl infile > outfile
open my $fh, '<', $ARGV[0];
my @terms;
while (<$fh>) {
chomp;
push @terms, [split /\t/];
}
my $biggest = 0;
my $id = '';
for my $term (sort sorter @terms) {
$biggest = 0 if $id ne $term->[0];
if ($term->[2] > $biggest) {
say join "\t", @$term;
$biggest = $term->[2];
}
$id = $term->[0];
}
sub sorter {
$a->[0] cmp $b->[0] ||
$a->[1] <=> $b->[1]
|| $b->[2] <=> $a->[2]
}