<?xml version="1.0" encoding="UTF-8"?>
<maxdQL version="0.1" name="MeasurementDataTabTextFASTESTTransposed" >
	
	<description>Will take a list of Gene names, a list of Measurement names and a list of Column Types and produce a table. All values are coloured in relation to the a reference. In the list of Measurement names, the first Measurement listed is taken to be the reference. Formatted as text.</description>
	
	<unitTest>
		php run.php -file=../../sequences/geneHunterPHP.xml -display=last -profile="The mouse microarray experiment" -GeneNames="Affy:Mouse430_2:1415670_at,Affy:Mouse430_2:1415671_at,Affy:Mouse430_2:1415672_at,Affy:Mouse430_2:1415673_at" -ColumnType="RMA Normalised" -MeasurementIDs="0,1"
	</unitTest>
	
	<xfunction id="getGeneIds" comment="take a list of genes and make a geneids tag from their ids">
		<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
			<xsl:output method="text" encoding="ISO-8859-1" indent="no" omit-xml-declaration="yes" media-type="text/html"/>
			<xsl:strip-space elements="entries Gene"/>
			<xsl:template match="/">
				<xsl:for-each select="entries/browse/Gene"><xsl:value-of select="@ID"/>,</xsl:for-each>
			</xsl:template>
		</xsl:stylesheet>
	</xfunction>
	
	<pfunction id="enumerateParser" comment="take a list of genes and make a geneids tag from their ids" method="text" >
		<![CDATA[
			/*
			* 2 magic variables here: $input and $output
			* $input is the input object that needs parsing
			* it may be of 
			* - type: Array or 
			* - type: DOM
			* $output is the string that will be read by the engine at the end
			*/
			
			foreach ($input as $measurementName => $measurement) {
				$output .= "\n$measurementName";
				foreach ($measurement as $columnName => $column) {
					if ($columnName != "Feature_ID") {
						$output .= "\n$columnName";
						foreach ($column as $key => $value) {
							$output .= "\t$value";
						}
					}
				}
			}
			
			
			//print $output;
			//die();
			
		]]>
	</pfunction>
	
	<arguments type="user" >
		<var name="ColumnTypes" comment="the column names, comma-separated, * for all" />
		<var name="MeasurementNames" comment="the measurement names, * for all. The first Measurement listed is taken to be the reference." />
	</arguments>
	
	
	<query id="1" name="EnumerateGenesForDesiredMeasurements" comment="enumerate some Genes" type="maxdBrowse">

		<types uref="user" name="ColumnTypes"/>
		<names uref="user" name="MeasurementNames"/>
		
		<action>enumerate</action>
		<table>Measurement</table>
		<spots>Feature</spots>
		<format>array</format>
	</query>
	
	<query id="2" name="FormatEnumeration" comment="digests the enumeration" type="export" format="text"  >
		<h1>Results</h1>
		<table pref="enumerateParser" processResultID="1" >
			<var uref="user" name="MeasurementNames" />
		</table>
	</query>
	
</maxdQL>
