#!/usr/bin/perl -w

use strict;

my $especie= $ARGV[0];
my $i = 0;

while (<STDIN>) {

    /(\w+)\s+(\w+)/;

    my $id=$1;
    my $seq=$2;

    open(FH," >temp.tbl");
    print FH "$id\t$seq";
    close (FH);

    `TblToFasta temp.tbl > temp.fa`;
    `blastall -p blastp -i temp.fa -d $especie -o temp.out -e 0.0001`;

    my $homologo = 1;
    open (OUT,"< temp.out");
    while (<OUT>)
    {
	if (/No hits found/) {
	    $homologo = 0;
	}
    
    }
   
    if ($homologo == 1) {

	print "$id hay homologo\n";

    }
   else { print "$id No hay homologos\n";

   }

   $i = $i + 1;

   if ($i % 100 == 0) {
	print STDERR "llevo $i\n";
   }
}
