#!/usr/bin/perl -w
use strict;

my $TOTAL_READ_BASEPAIRS = 200;

my $hla_path = $ARGV[0];
my $result_path = $ARGV[1];
my %id_name = ();

open(IN, $hla_path);
while(<IN>){
    my $line = $_;
    chomp($line);
    my @tmp = split(/\s/, $line);
    $id_name{"HLA:" . $tmp[0]} = $tmp[1];
    $id_name{$tmp[0]} = $tmp[1];
}
close(IN);

open(IN, $result_path);
while(<IN>){
    my $line = $_;
    chomp($line);
    my @tmp = split(/\t/, $line);
    if(exists($id_name{$tmp[0]})){

	if($id_name{$tmp[0]} =~ /^A\*/){
	    print $id_name{$tmp[0]};
	    print "\t" . ($tmp[2]*$TOTAL_READ_BASEPAIRS/$tmp[1]);
	    print "\n";
	}
	elsif($id_name{$tmp[0]} =~ /^B\*/){
	    print $id_name{$tmp[0]};
	    print "\t" . ($tmp[2]*$TOTAL_READ_BASEPAIRS/$tmp[1]);
	    print "\n";
	}
	elsif($id_name{$tmp[0]} =~ /^C\*/){
	    print $id_name{$tmp[0]};
	    print "\t" . ($tmp[2]*$TOTAL_READ_BASEPAIRS/$tmp[1]);
	    print "\n";
	}
	elsif($id_name{$tmp[0]} =~ /^DQA1\*/){
	    print $id_name{$tmp[0]};
	    print "\t" . ($tmp[2]*$TOTAL_READ_BASEPAIRS/$tmp[1]);
	    print "\n";
	}
	elsif($id_name{$tmp[0]} =~ /^DQB1\*/){
	    print $id_name{$tmp[0]};
	    print "\t" . ($tmp[2]*$TOTAL_READ_BASEPAIRS/$tmp[1]);
	    print "\n";
	}
	elsif($id_name{$tmp[0]} =~ /^DRB1\*/){
	    print $id_name{$tmp[0]};
	    print "\t" . ($tmp[2]*$TOTAL_READ_BASEPAIRS/$tmp[1]);
	    print "\n";
	}
    }
}
close(IN);
