/* This file defines the transition matrix for the equal input model for amino-acids.
   The file should be used as follows:
   
   1) Read Data File and create datafilter filteredData
   2) #include this file (or use SelectTemplateModel(filteredData);)
   3) Define the tree
   4) Proceed with the likelihood function using 'vectorOfFrequencies' as the vector to pass to the constructor.
   
   This model has the following signature:
   	#Short:EqualInput#
   	#Desc:Dayfoff model for amino-acids#
   	#Dimension:20#
    #DataType:aminoacid#
   	#FileName:EIAA.mdl#
   
   08/18/1999  by Sergei L. Kosakovsky Pond
*/

NICETY_LEVEL = 2;
aaCodes = {{"A",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"K",
"L",
"M",
"N",
"P",
"Q",
"R",
"S",
"T",
"V",
"W",
"Y"}};


#include "modelParameters2.mdl";

if (!SKIP_MODEL_PARAMETER_LIST)
{
	if (modelType == 1)
	{
		#include "defineGamma.mdl";
	}	
	if (modelType == 2)
	{
		#include "defineHM.mdl";
	}
}

function PopulateModelMatrix (ModelMatrixName&, EFV)
{

	ModelMatrixName = {20,20};
	
	if (modelType==0)
	{
		for (counter1=0; counter1<19;counter1=counter1+1)
		{
			for (counter2=counter1+1; counter2<20; counter2=counter2+1)
			{
				ModelMatrixName[counter1][counter2]:=a;
				ModelMatrixName[counter2][counter1]:=a;			
			}
		}
	}
	else
	{
		for (counter1=0; counter1<19;counter1=counter1+1)
		{
			for (counter2=counter1+1; counter2<20; counter2=counter2+1)
			{
				ModelMatrixName[counter1][counter2]:=c*a;
				ModelMatrixName[counter2][counter1]:=c*a;			
			}
		}
	}
	
	return 0;
}

commandString = "";

for (rI = 0; rI < 20; rI = rI+1)
{
	commandString = commandString + "global P_" + aaCodes[rI] + "=0.05;\n";
}

ExecuteCommands (commandString);

vectorOfFrequencies = {20,1};

commandString = "global EFV_Norm:=P_A";
for (rI = 1; rI < 20; rI = rI+1)
{
	commandString = commandString+"+P_"+aaCodes[rI];
}

ExecuteCommands (commandString+";");
vectorOfFrequencies[0]:=P_A/EFV_Norm;

for (rI = 1; rI < 20; rI = rI+1)
{
	commandString = "vectorOfFrequencies["+rI+"]:=P_"+aaCodes[rI]+"/EFV_Norm;";
	ExecuteCommands (commandString);
}


EEAA = 0;

MULTIPLY_BY_FREQS = PopulateModelMatrix ("EEAA",vectorOfFrequencies);

Model EqualInputModel = (EEAA, vectorOfFrequencies);

FREQUENCY_SENSITIVE = 0;
