#!/usr/bin/perl -w 
# usage : perl sm_vcf_explore.pl 
#smaman - 06/05/2013

use strict; 
use File::Basename; 

my $input_vcf          = $ARGV[0]; 
my $output_vcf         = $ARGV[1];  
my $output_report      = $ARGV[2]; 

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


#Nombre de variants contenus dans le VCF
$cmd2 = "grep -vc '^#' $input_vcf > ${ALL}_comptage.txt";
system $cmd2;


#Trie du vcf par qualite decroissante
$cmd1 = "sort -k6nr,6nr $input_vcf > ${ALL}_sort.vcf";
system $cmd1;

#Recuperation du fichier dans Galaxy
if (! -e "${ALL}_sort.vcf"){print STDERR "Pas de fichier vcf trie produit \n";}
else {$cmd = "(mv ${ALL}_sort.vcf $output_vcf) >& ./cp_vcf_explore_1.log 2>&1";
system $cmd;}


if (! -e "${ALL}_comptage.txt"){print STDERR "Pas de comptage produit \n";}
else {$cmd = "(mv ${ALL}_comptage.txt $output_report) >& ./cp_vcf_explore_2.log 2>&1";
system $cmd;}

