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

my $path_pat = $ARGV[0];
my $path_mat = $ARGV[1];

my $pat_prefix = "";
if($path_pat =~ /(.+)\.fa/){
    $pat_prefix = $1;
}
my $mat_prefix = "";
if($path_mat =~ /(.+)\.fa/){
    $mat_prefix = $1;
}

open(IN, $path_pat);
while(<IN>){
    my $line = $_;
    chomp($line);
    if($line =~ />(.+)$/){
	my $candidate = $1;
#	    print ">" . $path_pat . "_" . $candidate . "\n";
	    print ">" . $pat_prefix . "_" . $candidate . "\n";
    }
    else{
	print $line . "\n";
    }
}
close(IN);

open(IN, $path_mat);
while(<IN>){
    my $line = $_;
    chomp($line);
    if($line =~ />(.+)$/){
	my $candidate = $1;
#	    print ">" . $path_mat . "_" . $candidate . "\n";
	    print ">" . $mat_prefix . "_" . $candidate . "\n";
    }
    else{
	print $line . "\n";
    }
}
close(IN);
