#!/usr/bin/perl -w
#Author: Feng Cheng
use warnings;
use strict;

my ($apep,$bpep,$dirw) = ($ARGV[0],$ARGV[1],$ARGV[2]);
$apep =~ /([^\/]+)$/;
$apep = $1;
$bpep =~ /([^\/]+)$/;
$bpep = $1;
my ($ablast,$bblast,$ablastb) = ($apep."_2_".$apep.".out",$bpep."_2_".$bpep.".out",$apep."_2_".$bpep.".out");
my ($in1,$in2,$in3) = ("$dirw/$ablast","$dirw/$bblast","$dirw/$ablastb");
#print "$in1\n$in2\n$in3\n";

open(FR,$in1);
my $out = "$dirw/temp/a2a.all";
open(FW,">$out");
while(defined($_=<FR>)) {
  /^([^\t]+\t[^\t]+\t)/;
  print FW $1;
  /\t([^\t]+)\t\s*[^\s]+\n/;
  print FW "$1\n";
}
close(FR);
close(FW);

open(FR,$in2);
$out = "$dirw/temp/b2b.all";
open(FW,">$out");
while(defined($_=<FR>)) {
  /^([^\t]+\t[^\t]+\t)/;
  print FW $1;
  /\t([^\t]+)\t\s*[^\s]+\n/;
  print FW "$1\n";
}
close(FR);
close(FW);

open(FR,$in3);
$out = "$dirw/temp/a2b.all";
open(FW,">$out");
while(defined($_=<FR>)) {
  /^([^\t]+\t[^\t]+\t)/;    # it's up to the gene name in fasta file
  print FW $1;
  /\t([^\t]+)\t\s*[^\s]+\n/;
  print FW "$1\n";
}
close(FR);
close(FW);

