#!/usr/bin/perl -w

# usage : perl venn.pl
# Sarah Maman - 1 aout 2012 - Mis en place pour le traitement des mi-RNAs
# Copyright (C) 2012 INRA
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#


use strict;
use File::Basename;


my $output = $ARGV[0];
my $nom1   = $ARGV[1];
my $input1 = $ARGV[2];
my $nom2   = $ARGV[3];
my $input2 = $ARGV[4];
my $nom3   = $ARGV[5];
my $input3 = $ARGV[6];
#pour connaître le path vers le script lists2venn.pl
my $VENN = '/usr/local/bioinfo/src/galaxy-dev/galaxy-dist/tools/sm_miRNA_annotations/lists2venn.pl';
my $cmd = '';
my $input_dir = dirname($input1); 
my $input_basename=basename($input1,'.png'); 
my $input_image="$input_dir/${input_basename}-image"; 

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $ALL =  $mday."-".($mon+1)."_".$hour."h".$min."mn".$sec."sec";


$cmd = "($VENN $nom1 $input1 $nom2 $input2 $nom3 $input3 $ALL) >& ./venn.log 2>&1";
system $cmd;


if (! -e "$ALL.png")
{
print STDERR "Echec lors de la generation de l'image \n";
}
else
{
$cmd = "(cp -a $ALL.png $output) >& ./joincp.log 2>&1";
system $cmd;
}
