#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

my $dict_hsa_fh = shift;
my $dict_bac_fh = shift;
my %dict_data   = ();

my $fh = shift;

open D1, "<$dict_hsa_fh" or die "can't open $dict_hsa_fh\n";
while(<D1>){
  chomp;
  my @F=split"\t",$_;

  $dict_data{$F[0]} = $F[1];
}
close D1;

open D2, "<$dict_bac_fh" or die "can't open $dict_bac_fh\n";
while(<D2>){
  chomp;
  my @F=split"\t",$_;

  $dict_data{$F[0]} = $F[1];
}
close D2;

open F, "<$fh" or die "can t open $fh\n";
while(<F>){
  chomp;
  my @F=split"\t",$_;
  if ($F[0] eq "ID" && $F[1] eq "group"){
    print join("\t",@F)."\n";
  }
  else{
    if ($F[0]=~m/\.\d+$/){
      $F[0]=~s/\.\d+$//g;
    }
    if(defined($dict_data{$F[0]} )){
      $F[0] = $dict_data{$F[0]};
    }
    else{
      print STDERR "WANRINGS: no translation for $F[0]\n";
    }
    print join("\t",@F)."\n";
  }
}

