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

my %raKey = (
   "21"=>"uniProtDis",
   "16"=>"uniProtPoly",
);

my $fh;
open ($fh, "<", "listGeneVals.txt") or die "Couldn't open file1, $!\n";
my %in;
while (<$fh>) {
   chomp;
   if (!defined or $_ eq '') { next; }
   my @f = split(/\t/);
   $in{$f[0].$f[1]} = 1;  #acc(spId)    commentType(16, 21)
}
close $fh or die "Couldn't close file1, $!\n";

open ($fh, "<", "listSPconnections.txt") or die "Couldn't open file2, $!\n";
my %uniq;
while (<$fh>) {
   chomp;
   if (!defined or $_ eq '') { next; }
   my @f = split(/\t/);
   #varId  spId    mrna    geneSymbol
   if (exists $in{$f[1].'21'}) { 
      $uniq{"$f[0]\tgeneVarsDis\t$raKey{21}\t$f[1]\t\n"} = 1;
   }
   if (exists $in{$f[1].'16'}) {
      $uniq{"$f[0]\tgeneVarsDis\t$raKey{16}\t$f[1]\t\n"} = 1;
   } 
}
close $fh or die "Couldn't close file2, $!\n";

foreach (keys %uniq) { print; }
