#!/usr/bin/perl

use strict;
use warnings;

if(-e "$ENV{HOME}/scripts/jaiswallab/interactome_scripts/find_species.pl") {
	require "$ENV{HOME}/scripts/jaiswallab/interactome_scripts/find_species.pl";
}elsif(-e "$ENV{HOME}/jaiswallab_svn/interactome_scripts/find_species.pl") {
	require "$ENV{HOME}/jaiswallab_svn/interactome_scripts/find_species.pl";
}

my @files;

if($#ARGV != 1) {
	print "Usage: fasta_header_fix.pl input_file output_file\n";
	exit;
}

my $input_file = $ARGV[0];
my $output_file = $ARGV[1];
	
open(INFILE, $input_file)  || die "Error: File $input_file can not be opened";
open(OUTFILE, ">$output_file") || die "Error: File $output_file can not be opened";
	
my $species = find_species($input_file);

while(<INFILE>) {
	my $line = $_;
	chomp $line;
	if ($line =~ /^>/) {
		my $gene = find_gene($line,$species);
		$line = ">" . "$gene";
	}
	print OUTFILE "$line\n";
}

close(INFILE);
close(OUTFILE);
