@Jesvin Tente com isso. Espero que seja útil.
#!/usr/local/perl
use strict;
use warnings;
use Data::Dumper;
open( IN, "<gene_sorted.txt" );
open(OUT, ">genes_out.txt");
my $prev_scaffold = "";
my $prev_strand = "";
my @data;
while (<IN>) {
$_ =~ s/\n|\r//g;
my @tmp = split( /\t/, $_ );
if ( $prev_scaffold . "#" . $prev_strand ne $tmp[0] . "#" . $tmp[6] ) {
$prev_scaffold = $tmp[0];
$prev_strand = $tmp[6];
check( \@data );
undef @data;
push( @data, $_ );
}
else
{
push( @data, $_ );
}
}
close IN;
check( \@data );
sub check {
my $prev_start = 0;
my $prev_end = 0;
my @array = @{ $_[0] };
foreach (@array) {
#print $_."\n";
(
my $scaffold,
my $source,
my $annotation,
my $start,
my $end,
my $score,
my $strand,
my $column,
my $id
) = split( /\t/, $_ );
if ( $start > $prev_start && $end > $prev_end ) {
$prev_start = $start;
$prev_end = $end;
#print $start. " > " . $end . "\n";
print OUT $_."\n";
}
}
}