use strict;
use SeedEnv;

use Data::Dumper;

use SAPserver;
use ANNOserver;

my $sap = SAPserver->new();
my $anno = ANNOserver->new();

if (@ARGV != 2)
{
    die "Usage: compare_functions fasta-file function-file\n";
}

my $fasta_file = shift @ARGV;
my $function_file = shift @ARGV;

open(FUN, "<", $function_file) or die "Cannot open function file $function_file: $!";

my %old_functions;
while (<FUN>)
{
    chomp;
    my($id, $function) = split(/\t/);
    $old_functions{$id} = $function;
}
close(FUN);
      
my $resultHandle = $anno->assign_function_to_prot(-input => $fasta_file,
						  -kmer => 8,
						  -scoreThreshold => 3,
						  -hitThreshold => 5,
						  -seqHitThreshold => 3);

while (my $result = $resultHandle->get_next())
{
    my($id, $function, $otu, $score, $non_overlap_count, $overlap_count, $details) = @$result;
    
    my $old_function = $old_functions{$id};
    
    if ($old_function ne $function)
    {
	print "$id\n";
	print "\t$old_function\n";
	print "\t$function\n";
    }
}

exit 0;
