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

my $map_file = $ARGV[0]; #GBWI::GRMZ mapping file

# cyc pathway dump file (generated w/ brie:/usr/local/gramene/gramene-lib/scripts/pathway/format-pathway-data.pl (see README for conventional usage))
my $dump_file = $ARGV[1]; 
my %map_hash;

open(MAP_FILE,$map_file) or die("could not open $map_file");
while (<MAP_FILE>)
{
    my $line = $_;
    chomp $line;
    my @line_ary = split('\t',$line);
    my $key = $line_ary[0];
    $key =~ s/\s+$//;
    my $val = $line_ary[1];
    $val =~ s/^\s+//;
    
    $map_hash{$key} = $val;
}
close(MAP_FILE);

open(DUMP_FILE,$dump_file) or die("could not open $dump_file");
while (<DUMP_FILE>)
{
    my $line = $_;
    chomp $line;
    my @line_ary = split('\t',$line);
    
    if ($map_hash{$line_ary[0]}) {
        print $map_hash{$line_ary[0]} . "\t" . $line_ary[1] . "\t" . $line_ary[2] . "\t" 
            . $line_ary[3] . "\t" . $line_ary[4] . "\t" . $line_ary[5] . "\t" . $line_ary[6] . "\n";
    }
}
close(DUMP_FILE);

