#!/usr/bin/perl
# sort infscan output according to score
use strict;
my %data;
while ( defined ( my $line = <> ) ) {
	chomp;
	my ($seqid,$pos,$score,@rest) = split /\t+/ , $line;
	$data{$seqid}{$pos}{score} = $score;
	$data{$seqid}{$pos}{line} = $line;
}
# loop through all sequence ids encounted from first column in
# input - read from <> above (key in %data)
foreach my $seqid (keys %data) {
	# sort the data hash for this seqid, according to the highest score
	# using $a and $b, which are the compared key (Perl sets these variables )
	# @A contains the list of positions, sorted by their score
	my @A = sort {$data{$seqid}{$b}{score} <=> $data{$seqid}{$a}{score} } keys %{$data{$seqid}};
	print $data{$seqid}{$A[0]}{line};
}
