
open TXT1 , "<./ext_target.taxid" or die "can't open file1:$!";

open TXT2 , "<./ext_target.taxonomy" or die "can't open file2:$!";


$out_file = "./ext_target_taxon.txt";
system "rm $out_file";
open OUT , ">>./$out_file";


$i = 0;
while(<TXT2>)
{

	chomp;
	

	
	if($_=~ /^\S+\s+(\S+)\s+(\S+.*\S+)/)
	{         

		$taxo_2[$i] = $1;

		$taxo_name[$i] = $2;


	}

$i++;

}


while(<TXT1>)
{
	chomp;
    
	if($_=~ /^(\d+)\s+(\d+)\s+\d+/)
	{         

		$gi = $1;
		$taxo_1 = $2;

		$j = 0;
		foreach $taxo (@taxo_2)
		{
			if($taxo_1 eq $taxo)
			{
				print OUT "\>$gi\t$taxo_name[$j]\n";
				last;	
			
			}	
			
			$j++;
		
		}



	}



}


