<?xml version="1.0" encoding="UTF-8"?>
<maxdQL version="0.1" name="GEOseries2sample" >
	<description>parses output from GEOseries and returns the samples as a comma-separated list of the samples</description>

	<arguments type="user">
		<var 
			name="GEOseriesOutput" 
			comment="the output from GEOseries" 
		/>
		
		
		
	</arguments>

	<pfunction id="seriesTabber" comment="returns the id of the first labelled extract" method="text" >
		<![CDATA[
			 
			 $lines = explode("\n", $GEOseriesOutput);
			 //print_r($lines);die();
			 $outlines = array();
			 $comma = "";
			 foreach ($lines as $line)
			 {
			 	$split = explode (" = ", $line);
			 	
			 	if ($split[0] == "!Series_sample_id") 
			 	{
			 		$outlines[] = $split[1];
			 		
			 		//$chomped = str_replace ("\n", "", $split[1]);
			 		
			 		$rtrimmed = rtrim ($split[1]);
			 		
			 		$string .= $comma . $rtrimmed;
			 		$comma = ","; 
			 	}
			 }
			 
			 if (count($outlines) < 1)
			 {
			 	throw new exception ("no measurements (samples) detected in this series");
			 }
			 
			$output = str_replace("\n", "", $string);
		]]>
	</pfunction>

	

	<query id="1" 
	       name="commaIt" 
	       comment="generates output" 
	       type="export" 
	       format="text" 
	       >
	       <seriesHeader pref="seriesTabber" processResultID="1" >
	       		<var uref="user" name="GEOseriesOutput"  />
	       </seriesHeader>
	</query>
	
</maxdQL>
