use strict;
use Bio::Seq;
use Bio::SeqIO;
use Bio::AlignIO;

open(OUT,">99.02orth.txt");
my @spes=("bsn5","ro","tu","w23");

my %orth;
foreach my $tspe(@spes){
	my %orth1;
	open(TEM1,"99.01".$tspe."_168.txt");	
	while(my $line=<TEM1>){
		chomp $line;
		my @data=split("\t",$line);
		if(!exists $orth1{$data[0]}){
			 $orth1{$data[0]}=$data[1];#CAX52679	ADM36091	37.50	32	20	0	4	35	125	156	3.3	23.1		
		}
	}
	my %orth2;	
	open(TEM2,"99.01168_".$tspe.".txt");
	while(my $line=<TEM2>){
		chomp $line;
		my @data=split("\t",$line);
		if(!exists $orth2{$data[0]}){
			$orth2{$data[0]}=$data[1];#ADM36091	CAB11808	99.27	275	2	0	1	275	1	275	2e-160	 558				
		}
	}	
	foreach my $tgene (keys %orth1){
		if($tgene eq "CAX52679" and $tspe eq "w23"){
			1;
		}
		if($orth2{$orth1{$tgene}} eq $tgene){
			$orth{$tgene}->{$tspe}=$orth1{$tgene};
		}
	}
}


foreach my $tgene (keys %orth){
	print OUT $tgene;	
	foreach my $tspe(@spes){
		print OUT "\t".$orth{$tgene}->{$tspe};	
	}
	print OUT "\n";
}
