#!/usr/bin/perl -w

=pod

=head1  NAME
search_names.pl comptage.csv biomart.csv
 
=head1  SYNOPSIS

Produire un fichier de correspondance entre le nom du gene (Associated Gene Name) et sa description Ensembl afin d'optimiser l'annotation.

=head1  OPTIONS

=head1 DESCRIPTION


=head1 DATE

30/09/2013

=head1 AUTHORS

Sarah Maman 

=cut

use strict;
use warnings;

my $countfile   = $ARGV[0];
#my $countfile  = "TEST_COMPTAGE.csv";
my $biomartfile = $ARGV[1];
#my $biomartfile= "TEST_BIOMART.txt";
my %countfile = ();

open (COUNT,$countfile) or die "Can't open $countfile \n";

while (my $line =<COUNT>){
	chomp $line;
	next if ($line =~ /^$/) ;
	my @F =split(/\t/,$line);
	$countfile{ uc($F[0]) } = undef;
}
close COUNT;

open (BIOMART,$biomartfile) or die "Can't open $biomartfile \n";
open (RENAME, ">", "TEST_TABLEAU_CORRESPONDANCE.csv") or die "Can't open TEST_TABLEAU_CORRESPONDANCE.csv";

while (my $l=<BIOMART>){
	chomp $l;
	my @F=split(/\t/,$l);
	my $gene_name = uc($F[3]);
	if (exists($countfile{$gene_name})){
	   printf RENAME "$gene_name\t$F[2]\n";
	}
}

close RENAME;
close BIOMART;
print "OK / le fichier de correspondance TEST_TABLEAU_CORRESPONDANCE.csv est disponible.\n";
