codingMapperVector =
{
{                 4,                 9,                 7,                10,                17,                15,                12,                16,                 0,                19,                 6,                13,                11,                 8,                 2,                 3,                 1,                18,                14,                 5}
};

function checkPair (c1,c2)
{
	if (c1!=c2)
	{
		c1 = _Genetic_Code[c1];
		c2 = _Genetic_Code[c2];
		if (c1 == 10 || c2 == 10)
		{
			return 0;
		}
		
		if (c1>=10)
		{
			c1 = c1-1;
		}
		if (c2>=10)
		{
			c2 = c2-1;
		}
		
		c1 = codingMapperVector[c1];
		c2 = codingMapperVector[c2];
		
		allowedMoves[c1][c2] = 1;
		allowedMoves[c2][c1] = 1;
	}
	return 0;
}

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

#include "chooseGeneticCode.def";

allowedMoves = {20,20};

for (h=0; h<64; h=h+1)
{
	if (_Genetic_Code[h] != 10)
	{
		pos12 = h-h%4;
		pos13 = h-4*(h%16$4);
		pos23 = h-16*(h$16);
		
		checkPair (h,pos12);
		checkPair (h,pos12+1);
		checkPair (h,pos12+2);
		checkPair (h,pos12+3);
		checkPair (h,pos13);
		checkPair (h,pos13+4);
		checkPair (h,pos13+8);
		checkPair (h,pos13+12);
		checkPair (h,pos23);
		checkPair (h,pos23+16);
		checkPair (h,pos23+32);
		checkPair (h,pos23+48);
	}
}

#include "modelParameters2.mdl";

aaNames = {{"Alanine",
"Cysteine",
"Aspartic_Acid",
"Glutamic_Acid",
"Phenylalanine",
"Glycine",
"Histidine",
"Isoleucine",
"Lysine",
"Leucine",
"Methionine",
"Asparagine",
"Proline",
"Glutamine",
"Arginine",
"Serine",
"Threonine",
"Valine",
"Tryptophan",
"Tyrosine"}};


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 (categoriesUsed)
	{
		for (k=0; k<19; k=k+1)
		{
			for (k2 = k+1; k2 < 20; k2=k2+1)
			{
				if (allowedMoves[k][k2])
				{
					subString = aaNames[k]+aaNames[k2];
				}
				else
				{
					subString = "MultiStep";
				}
				ExecuteCommands("global "+subString +"=1; ModelMatrixName[k][k2]:= c*t*"+subString+
								";ModelMatrixName[k2][k]:= c*t*"+subString+";");
			}
		}       
	}
	else
	{
		for (k=0; k<19; k=k+1)
		{
			for (k2 = k+1; k2 < 20; k2=k2+1)
			{
				if (allowedMoves[k][k2])
				{
					subString = aaNames[k]+aaNames[k2];
				}
				else
				{
					subString = "MultiStep";
				}
				ExecuteCommands("global "+subString +"=1; ModelMatrixName[k][k2]:= t*"+subString+
								";ModelMatrixName[k2][k]:= t*"+subString+";");
			}
		}       
	}
	
	subString = aaNames[7]+aaNames[9];
	ExecuteCommands(subString +":=1;");
	return 1;
}



redREVMatrix = 0;

HarvestFrequencies (vectorOfFrequencies,filteredData,1,1,0);

MULTIPLY_BY_FREQS = PopulateModelMatrix ("redREVMatrix",vectorOfFrequencies);

Model redREVModel = (redREVMatrix, vectorOfFrequencies, MULTIPLY_BY_FREQS);

FREQUENCY_SENSITIVE = 1;
