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

use Digest::MD5 qw(md5 md5_hex md5_base64);
use MIME::Parser;
use MIME::Entity;
use MIME::Body;
use Getopt::Long;


use lib qw(Core);
use lib qw(Classes);
use ImagesManager;
use ResultsManager;
use ResultsTargetManager;
use ResultsUploadManager;

use Logger;

my $SCRIPTNAME = 'upload_results.pl';

#my $logger = new Logger();

my $directory = "";
my @FILES_LIST = ();
my $count_files = 0;


my $results_manager = new ResultsManager();
my $results_target_manager = new ResultsTargetManager();
my $resultsupload_manager = new ResultsUploadManager();

my $TARGET = "T0398-D1";
my $protein_pdb = '/data/CASP9/TARGETS/'.$TARGET.'.pdb';
my $output_small_str_image_png = '/data/CASP9/PLOTS/STR/'.$TARGET.'.small.png'; #structure image
my $images_manager = new ImagesManager();


my $target_list = 'conf/QA_targets_list_3';

open (TL, $target_list) || die "Cannot open input file $target_list: $!";
while(my $target = <TL>) {
	chomp($target);
	if ($target =~ /^#/){next;}

	$TARGET = $target;

	##############QA PREDICTIONS 
	$directory = "/data/CASP9/predictions/qa_predictions_cleaned/$TARGET";
	@FILES_LIST = ();
	if(open(FILE_list_of_results, "/bin/ls " . $directory. "/* |")) {
		@FILES_LIST = <FILE_list_of_results>;
		close (FILE_list_of_results);
	}
	$count_files = 0;
	foreach my $line (@FILES_LIST) {
		$count_files ++;	
		$line =~ /$directory\/(.*)/;
		my $file_name = $1;
		$resultsupload_manager->upload_qa($file_name, $directory);
		print "File #" . $count_files . "\n";
	}
}


exit(0);
