ExecuteAFile ("../Shared/ReadDelimitedFiles.bf");

if (Abs (availableFiles) == 0)
{
	availableFiles          = {};
	availableFiles [0] = {{"PI","Scores_PI.txt",0}};
	availableFiles [1] = {{"NRTI","Scores_NRTI.txt",99}};
	availableFiles [2] = {{"NNRTI","Scores_NNRTI.txt",99}};
}

/*------------------------------------------------------------------------------------*/ 

function ProcessAFile (fileName,gateAt,shifter)
{
	drugOut         = {};
	drugProf        = {};
	drugNames       = {};
	
	fscanf  			(fileName, "Lines", inLines);
	linesRead 			= Columns (inLines);
	drugOut ["Date"]	= inLines[0];
	splitS 				= splitStringByTab(inLines[1]);
	dCount 				= Abs(splitS)-2;
	
	for (k=0; k<dCount; k=k+1)
	{
		drugNames[Abs(drugNames)] = splitS[k+2]; 
	}	
	
	for (l=2; l<linesRead;l=l+1)
	{
		splitS 				= splitStringByTab(inLines[l]);
		site				= shifter+splitS[0];
		residue				= splitS  [1];
		
		if (residue == "insert")
		{
			site    = -site;
			residue = ".";
		}
		
		scoreMatrix 		= {dCount,1};
		mm					= 0;
		for (k=0; k<dCount; k=k+1)
		{
			scoreMatrix[k] = 0+splitS[k+2];
			if (scoreMatrix[k] < gateAt)
			{
				scoreMatrix[k] = 0;
			}
			mm = Max (mm, scoreMatrix[k]);
		}
		
		if (mm > 0)
		{
			if (Abs (drugProf[site]) == 0)
			{
				drugProf[site] = {};
			}
	
			(drugProf[site])[residue] = scoreMatrix;
		}
	}	
		
	drugOut ["Names"]       = drugNames;
	drugOut ["Scores"]      = drugProf;
	
	return drugOut;
}

