selLabelMatrix = {{"Codon","&alpha;","&beta;<sup>-</sup>","Pr[&beta;=&beta;<sup>-</sup>]","&beta;<sup>+</sup>","Pr[&beta;=&beta;<sup>+</sup>]","p-value","q-value"}};

MEME_ResultTable = {};
MEME_ResultTable ["Codon"] 		 = "INTEGER"; 
MEME_ResultTable ["beta1"]       = "REAL"; // 1
MEME_ResultTable ["p1"]    	 	 = "REAL"; // 2
MEME_ResultTable ["beta2"]   	 = "REAL"; // 3
MEME_ResultTable ["p2"]   	 	 = "REAL"; // 4
MEME_ResultTable ["alpha"]    	 = "REAL"; // 5
MEME_ResultTable ["LRT"]    	 = "REAL"; // 6
MEME_ResultTable ["pvalue"]      = "REAL"; // 7
MEME_ResultTable ["logl"]     	 = "REAL"; // 8
MEME_ResultTable ["qvalue"]      = "REAL"; // 9

MEME_tree_result_ordering = {{"Tree","Codon","Branch","PP","EBF","Syn","NonSyn"}};

MEME_TreesTable = {};
MEME_TreesTable [MEME_tree_result_ordering[0]] 		 = "INTEGER"; 
MEME_TreesTable [MEME_tree_result_ordering[1]]       = "INTEGER"; // 1
MEME_TreesTable [MEME_tree_result_ordering[2]]    	 = "REAL"; // 2
MEME_TreesTable [MEME_tree_result_ordering[3]]   	 = "REAL"; // 3
MEME_TreesTable [MEME_tree_result_ordering[4]]   	 = "REAL"; // 4
MEME_TreesTable [MEME_tree_result_ordering[5]]       = "REAL";
MEME_TreesTable [MEME_tree_result_ordering[6]]       = "REAL";

/*___________________________________________________________________________________________________________*/

function    ListOfSitesWithMappingData (DB_ID) {
    _codonList = _ExecuteSQL (DB_ID, "SELECT distinct(codon) as codon FROM MEME_MAPPINGS");
    _codonAVL = {};
    for (_recID = 0; _recID < Abs(_codonList); _recID += 1) {
        _codonAVL [(_codonList[_recID])] = 1;
    }
    return _codonAVL;
}

/*___________________________________________________________________________________________________________*/

function	PrintASCIITable (dataMatrix, titleMatrix, doSLACMaps, mappingInfo)
{
    haz_mapping = (Type (mappingInfo) == "AssociativeList");
	outString="";
	outString*8192;
	if (Rows(dataMatrix))
	{
		outString*"<DIV CLASS='RepClassSM'>\n<TABLE BORDER = '0'><TR CLASS='TRReport' style = 'font-size:small'>";
		nc = Columns(titleMatrix);
		
		for (counter1=0; counter1<nc; counter1 += 1)
		{
			outString*"<td>";
			outString*titleMatrix[counter1];
			outString*"</td>\n";
		}
		
		
		
		if (haz_mapping) {
			outString*"<td>Branch-site information</td>";		    
		}
		if (doSLACMaps) {
			outString*"<td>Additional Information</td>";
		}
		
		outString*"</tr>\n";
		
		for (counter1=0; counter1<Rows(dataMatrix); counter1 += 1)
		{
			if (counter1%2) {
				outString*"\n<tr CLASS='TRReport2' style = 'font-size:x-small'>";
			}
			else {
				outString*"\n<tr CLASS='TRReport1' style = 'font-size:x-small'>";
			}
			
			for (counter2 = 0; counter2 < nc; counter2 = counter2+1) {
				outString*"\n<td>";
				outString*Format(dataMatrix[counter1][counter2],-1,-1);
				outString*"\n</td>\n";
			}

            if (haz_mapping) {
				codonIndex = dataMatrix[counter1][0];
                if (mappingInfo[codonIndex]) {
                    outString*("<TD style = 'font-size: 10px;'><a href='"+BASE_CGI_URL_STRING+"wrapHyPhyBF.pl?file=meme_plotter&arguments="+filePrefix+"-"+codonIndex+"-0&mode=0'>[Display]</a></TD>");
                } else {
                    outString*("<TD>N/A</TD>");
                }
            }
            
			if (doSLACMaps)
			{
				codonIndex = dataMatrix[counter1][0]-1;
				outString*("<TD style = 'font-size: 10px;'><a href='"+BASE_CGI_URL_STRING+"siteMap.pl?file="+filePrefix+"&site="+codonIndex+"&mode=0'>[Codons]</a>"+
						   "<a href='"+BASE_CGI_URL_STRING+"siteMap.pl?file="+filePrefix+"&site="+codonIndex+"&mode=1'>[AA]</a>"+
								 "<a href='"+BASE_CGI_URL_STRING+"siteMap.pl?file="+filePrefix+"&site="+codonIndex+"&mode=2'>[Counts]</a>"+
								 "</TD>");
			}
			outString*"</tr>\n";
		}
		outString*"</TABLE></DIV>\n";	
	}
	outString*0;
	return outString;
}

