#!/usr/bin/perl -w
# Filter to only select CRITICA hits with the best inits possible for each ORF

(@ARGV==1) || die ("usage: best-inits critica-output\n");

$start=$end=$matrix=0;

while(<>) {
  ($name,$p,$matrix,$start,$end)=split(" ");
  $orfkey=$name." ".$end;
  if  (!defined($bestline{$orfkey})) {
    $bestp{$orfkey}=1.0;
  } 
  if ($p<$bestp{$orfkey}) {
    $bestp{$orfkey}=$p;
    $bestline{$orfkey}=$_;
  }
}

foreach $orfkey (sort(keys %bestline)) {
  print $bestline{$orfkey};
}
