#!/usr/bin/env perl
use strict;



#############################
# read config file
#############################


use FindBin;
use lib "$FindBin::Bin";
use Ricopili::Utils qw(trans);

my $p2loc = &trans("p2loc");

###############################################


my $version = "1.0.0";
my $progname = $0;


##### help message
my $usage = "
Usage : $progname [options] .bgl

version: $version

  --help         print this help message and exit
  --out STRING   outname (mandatory)
  --vcf STRING   vcf file (mandatory)

  --debug             extended output


 created by Stephan Ripke 2016 at MGH, Boston, MA
 
";



use Getopt::Long;
GetOptions( 
    "help"=> \my $help,
    "vcf=s"=> \my $vcffile,
    "out=s"=> \my $out,
     "debug"=> \my $debug,
    );


die $usage if $help;
die $usage unless ($vcffile);
die $usage unless ($out);


###################################################
###  system call with test if successfull
###################################################
sub mysystem(){
    my ($systemstr)="@_";
    system($systemstr);
    my $status = ($? >> 8);
    die "$systemstr\n->system call failed: $status" if ($status != 0);
}





##########################################
# subroutine to split a plink-output-line with references
##########################################

sub split_line_ref {
    my ($line)=${$_[0]};
    chomp($line);
    $line =~ s/^[\s]+//g;
    my @cols=  split /\s+/, $line;
    \@cols;
}




##########################################
# begin
##########################################


my $sys = "$p2loc/plink --silent --memory 2000 --vcf $vcffile --make-bed --out $out\n";
print ("$sys\n")  if ($debug);
&mysystem ("$sys");

my $sys = "touch $out.fini\n";
&mysystem ("$sys");
