## translate cancer datasets ids
## Jan 20th, 2004
## kenji@vettatech.com

print "Opening dictionary $ARGV[0] to translate $ARGV[1]\n";

my %dic;

open(IN,$ARGV[0]);
while($line = <IN>){
	chomp($line);
	($affy,$refseq) = split(/\t/,$line);
	
	$dic{$affy} = $refseq;
}
close(IN);

$t=0;
$l=0;

open(IN2,$ARGV[1]);

open(OUT,">$ARGV[1].translated");
while($line = <IN2>){
	chomp($line);
	$l++;
	my @cols = split(/\t/,$line);	

	for($i = 0 ; $i < $#cols ; $i++){
		if ($i == 0){
			$id = $cols[$i];
			$transl = $dic{$id};
			if ($transl){
				print OUT $dic{$id}."\t";
				$t++;
			}else{
				print OUT $cols[$i]."\t";
			}
		}else{
			print OUT $cols[$i]."\t";
		}
	}
	
	print OUT $cols[$#cols]."\n";
}
close(IN2);

close(OUT);

print "$t/$l translations performed for $ARGV[1]\n";