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

use lib qw(Core);
use lib qw(Classes);
use Getopt::Long;
use Digest::MD5 qw(md5 md5_hex md5_base64);
use POSIX qw(strftime);

use Configuration;
use LocalConfiguration;
use Logger;

use Common;
use PDBUtils;

my $SCRIPTNAME = 'generate_exper_seq_files.pl';

use Common;

use TargetSequencesManager;

my $targetsequence_id = "";

my $isparams = GetOptions(
	"id|sequence_id=s" => \$targetsequence_id
);


my $targetSequencesManager = new TargetSequencesManager();
my %sequence_info = $targetSequencesManager->sequence($targetsequence_id);


if(open(LOG, sprintf(">> %s", sprintf("%s.log", $SCRIPTNAME)))) {

	my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);        
	my $date = sprintf("%s\/%s\/%s %s:%s:%s",($mon+1), $mday, $year, $hour, $min, $sec);	

	print(LOG $date);
	print(LOG '/n'); 


	my $FILES_DIR_NEW = "exper_seq";    

	

	my $sequence = sprintf(">tsid\_%s %s, %s, %s residues\n%s\n\n\n", $targetsequence_id, $sequence_info{PROTEIN_NAME}, $sequence_info{ORGANISM_NAME}, $sequence_info{NUMBER_OF_AA}, $sequence_info{SEQUENCE});
		

	my $out_path = sprintf(">%s/tsid_%s.seq.txt", $FILES_DIR_NEW , $targetsequence_id);
	print(LOG $out_path); 	
	print(LOG '/n'); 
	open(FILE_OUT, $out_path);
	print FILE_OUT sprintf("%s", $sequence);
	close(FILE_OUT);
	
	my $target_template = sprintf("REMARK Template for target %s\n", $targetsequence_id);
	$target_template .= generate_target_template_from_sequence($sequence_info{SEQUENCE});
	$out_path = sprintf(">%s/tsid_%s.pdb.txt", $FILES_DIR_NEW , $targetsequence_id);
	
	print(LOG $out_path);	
	print(LOG '/n'); 
	open(FILE_OUT, $out_path);
	print FILE_OUT sprintf("%s", $target_template);
	close(FILE_OUT);

	close(LOG);
}	


#print "Content-Type: text/html; charset=ISO-8859-1\n\n";
#print $out_path;

