#!/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}/bin/find_species.pl") {
	require "$ENV{HOME}/bin/find_species.pl";
}

my $in_file = $ARGV[0];
my $out_file = $ARGV[1];

open(INFILE, "$in_file");
open(OUTFILE, ">$out_file");

my %species_hash;
$species_hash{"Cannabis_sativa.Purple.Kush"} = 1;
$species_hash{"Phyllostachys_heterocycla"} = 1;
$species_hash{"Theobroma_cacao"} = 1;
$species_hash{"Triticum_monococcum.DV92"} = 1;
$species_hash{"Triticum_monococcum.G3116"} = 1;




while(<INFILE>) {
	my $line = $_;
	chomp $line;
	
	my ($clust_id, $bit_score, $file, $score, $gene) = split(/\t/, $line);
	my $species = find_species($file);
	if(defined($species_hash{$species})) {
			my $new_gene = find_gene($gene, $species);
			print OUTFILE "$clust_id\t$bit_score\t$file\t$score\t$new_gene\n";
	}else{
			print OUTFILE "$clust_id\t$bit_score\t$file\t$score\t$gene\n";
	}
}
close(INFILE);
close(OUTFILE);
	
