#ifndef SPARTA_H
#define SPARTA_H

#include <iostream>
#include <fstream>
#include <math.h>
#include <string.h>

#ifdef WIN32
#include <direct.h>
#else
#include <dirent.h>
#include <sys/stat.h>
#endif

#include "GDB.h"
#include "PDB.h"

#define MAX          9999.000

using namespace std;
using std::string;
typedef vector<string> StringList;


class SPARTA
{
	string SPARTA_DIR, PRED_DIR, TAB_DIR, SHIFT_DIR, PDB_DIR, EXCLUDED;

	string slash_char;

	char buf[30], lbuf[100];

	string inName; // input PDB coordinates file name
	PDB inPDB;
	GDB inTab; //inTab, input talble file from PDB coordinates file

	string sumName; // output summary name

	float** U_ANGLES;
	float** U_RING_SHIFTS;
	string** U_NAME ;
	float *U_HN_HB, *U_HA_HB, *U_CO_HB;// *HB_SHIFT_HN;

	string tripFileName;
	GDB TRIPLET_Tab; //triplet table file

	string weightFileName; // file name for wieght talble of score function
	GDB WEIGHT_Tab; // talble for weights of score function

	string homoFileName; // file name for sequence homology talble
	GDB HOMO_Tab; // homology talble

	string rcFileName; //file name for random coil chemical shift talble
	GDB RC_Tab; // random coil chemical shift talble

	string adjFileName; //file name for the adjustment of random coil chemical shift talble
	GDB ADJ_Tab; // "Random Coil Adjustment Table"

	string prevFileName; // file name for the table of "Random Coil Adjustments for Previous Residue Type"
	GDB PREV_Tab; // talble for "Random Coil Adjustments for Previous Residue Type"

	string nextFileName; // file name for the table of "Random Coil Adjustments for Next Residue Type"
	GDB NEXT_Tab; // talble for "Random Coil Adjustments for Next Residue Type"

	string fitFileName; // file name for the table of "fitting parameters"
	GDB FIT_Tab; // talble for "fitting parameters"

	string refCSFileName;

	int firstRes, lastRes; // First/last RESID to use for prediction

	int r1,rN; // first and last RESID in seqList

	float tVal; // Max similarity score threshold, not used in the program

	map<int, string> residList; // one-letter amino acid residue list from input PDB coordinates file
	string sequence; // one-letter amino acid residue list from input PDB coordinates file in the format of one string

	map<int, string> aN, aN_ALL; // Backbone atom list used by program "N HA C CA CB H"

	int matchCount; //Max Match Count per query triplet
	
	string pdbListName; //table file name for names of candidate proteins

public:
	vector<string> argList; // list for all vilid arguments
	
	SPARTA();
	SPARTA(const string& fileName);

	void printSyntax();

	void init();
	void runPredict();

	void compareRef(GDB &Pred_Sum);

	void getResInfo(); //Get the list of useful shifts from a given residue. get 2nd chemical shift and apply correction
	
	void Compile();
	void Compile(const string &name);

	// get random coil chemical shift for atom 'aName' of residue 'resName'
	float getRC(const string& resName, const string& aName);
	float getRCadj(const string& resName, const string& aName);
	float getPrevRCadj(const string& prev_rName, const string& aName);
	float getNextRCadj(const string& next_rName, const string& aName);
	float getWeight(const string& Name, const string& aName);

	//preset the args form command line
	void setArgs(map<string, string> args);

	void mkdir_pred(const string& d);// create a directory for prediction results
	int MKDIR(const char *dirName);
	bool isDirExists(const string &Dir) ;


	float getDiff( float ang1, float ang2); // calculate the different between two angles
	float getAVG(vector<float> &v1);
	float getSTD(vector<float> &v1);
	float getRMS(vector<float> &v1, vector<float> &v2);
	
	char * ftoa( float n, char *buff, char f='g', int prec=6 );
	char * itoa( int n, char *buff, int base=10 );
};


#endif
