#!/usr/bin/perl 

use strict;
use warnings;

###########################################################
#
# The script checkes accepted predictions. Due to the bug 
# the severe verification has been turned off. That's why it 
# was necessary to verify all models once again separately.
#
###########################################################

use lib ("/local/Projects/Perl/casp13/src/Classes");
use lib ("/local/Projects/Perl/casp13/src/Classes/Core");

use PDBUtils;

my $indir ;

my $outdir ;

if(defined $ARGV[0] ){
  $indir = $ARGV[0] ;
  if(! -d $indir){
     print "The directory $indir doesn't exist. he first argument should be the dir with TS predictions.\n";
     exit;
  }
}else{
  print "The first argument should be the dir with TS predictions\n";
  exit;
}
if(defined $ARGV[1] ){
  $outdir = $ARGV[1] ;
  if($indir eq $outdir){
	print ("You should set another output directory. The input and outout directories shouldn't  be the same.\n");
	exit;
  }
  if(! -d $outdir){
     warn "The output directory $outdir doesn't exist. It will be created.\n";
     my $c = `mkdir -p $outdir`;
     if(0 == $c){
	$c = `mkdir -p $outdir/junk`;
	print "Directory $outdir has been created\n";
     }else{
	print "Failed to create directory $outdir \n";
	exit;
     }
  }
}else{
  print "The second argument should be the output dir - another than input dir.\n";
  exit;
}


my @preds = ();
open IN, "ls -1 $indir/* |";
while(<IN>){
  chomp $_;
  my $tmp = substr($_,rindex($_,'/') + 1); # remove dir_path if any
  if($tmp =~ m/TS/){
     
     push(@preds,$tmp);
#     print $tmp."\n";
  }
}
close(IN);

foreach my $pred (@preds){
 clean_model($indir."/".$pred, $outdir."/".$pred, 0, "$outdir/junk");
#last;
}

exit;
