#!/usr/bin/perl -w
#
# author: axel wintsche
# mail: wint(spider monkey)bioinf(dot)uni-leipzig(dot)de

use strict;

$#ARGV == 1 or die "usage:\nspecname.pl <countfile> <mappingfile>\n";
# countfie has two cols: "two char code", "# of occurences/genes";
# mappingfile has three cols: "two char code", "ncbi id", "taxonomic name";


##-----------------------------------------------------------
#	create hash "two char code" -> "ncbi-id\ttaxonomic name"
#
my %map;

open(MAP,"<$ARGV[1]") or die;

foreach(<MAP>) {
	chomp $_;
	my @temp = split(/\t/, $_);
	$map{$temp[0]} = "$temp[1]\t$temp[2]";
}
close(MAP);

open(SPEC, "<$ARGV[0]") or die;

foreach(<SPEC>){

	chomp($_);

	my @line = split(/\t+/, $_);
	#my @ncbi_data = split( /\t/, $map{$line[0]} );

	if( exists $map{$line[0]} ) {
		print "$map{$line[0]}\t$line[1]\n";
	}
	else { print STDERR "$line[0]\n"; }

}

close(SPEC);
