<?
include ("network2.php");
include ("connection.php");
include ("frames_header.php");


$clusterid=$_GET["clusterid"];


$species="Ciona intestinalis";
//$dev_stage="Late 32-cell stage";
$dev_stage=$_GET["dev_stage"];

//$anat_name="a6.5 cell pair";
//$anat_name=$_GET["anat_name"];
$anat_id=$_GET["anat_name"];

$requete="SELECT \"NAME\" from \"ANAT_ENTITY\" where \"ANAT_ID\"='$anat_id'";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);
$anat_name=$row["NAME"];



$name="";
$requete="SELECT \"GENE_CLUSTER_NAME\" from \"GENE_CONCEPT_NAME\" where \"GENE_CLUSTER_ID\"='$clusterid'";
$stmt=pg_query($c,$requete);
while ($row=pg_fetch_array($stmt)) if (strlen($name)==0) $name=$row["GENE_CLUSTER_NAME"]; else $name.=" / ".$row["GENE_CLUSTER_NAME"];


if (strlen($name)==0) $name=$clusterid;

if (strlen($dev_stage)>0) $MYDEV="<br> at $dev_stage";
if (strlen($anat_name)>0) $MYANAT="<br> in $anat_name";

print "<center><h2>Gene Regulatory Network for:<br> <font color=\"#D64242\"> $name </font>  $MYDEV $MYANAT</h2></center>";



$h=$_GET["h"];
$w=$h;
$R0=$h/3;
$R1=$R0/10;



if (strlen($dev_stage)!=0)
{
$requete="SELECT \"DEV_STAGE_ID\" from \"DEV_STAGE\" where \"SPECIES\"='$species' and \"NAME\"='$dev_stage'";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);
$dev=$row["DEV_STAGE_ID"];
}
else $dev="";

if ((strlen($anat_name)!=0) && (strlen($dev)!=0))
{
$requete="SELECT \"ANAT_ID\" from \"ANAT_ENTITY\" where \"NAME\"='$anat_name' and \"DEV_STAGE_ID\"='$dev'";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);
$anat=$row["ANAT_ID"];
}
else $anat="";


//$anat="";

/*
$h=7000;
$w=$h;
$R0=$h/3;
$R1=$R0/10;

$h=($R0+$R1)*2.1;
$w=$h;
*/
$hminus=$h-100;
$hplus=$h+100;

print "<br>";
print "<center>";
print "<table style=\"border: 1px dashed black;\" width=\"50%\">";
print "<tr>";
print "<td align=\"center\">";
print "<form name=\"formu\" action=\"view-net.php\" method=\"GET\">";
print "<input type=\"submit\" value=\"Zoom In\">";
print "<input type=\"hidden\" name=\"clusterid\" value=\"$clusterid\">";
print "<input type=\"hidden\" name=\"dev_stage\" value=\"$dev_stage\">";
print "<input type=\"hidden\" name=\"anat_name\" value=\"$anat\">";
print "<input type=\"hidden\" name=\"h\" value=\"$hplus\">";
print "</form>";
print "</td>";

print "<td align=\"center\">";
print "<form name=\"formu\" action=\"view-net.php\" method=\"GET\">";
print "<input type=\"submit\" value=\"Zoom Out\">";
print "<input type=\"hidden\" name=\"clusterid\" value=\"$clusterid\">";
print "<input type=\"hidden\" name=\"dev_stage\" value=\"$dev_stage\">";
print "<input type=\"hidden\" name=\"anat_name\" value=\"$anat\">";
print "<input type=\"hidden\" name=\"h\" value=\"$hminus\">";
print "</form>";
print "</td>";

print "<td align=\"center\">";
print "<form name=\"formu\" action=\"view-net.php\" method=\"GET\">";
print "<input type=\"submit\" value=\"Reset\">";
print "<input type=\"hidden\" name=\"clusterid\" value=\"$clusterid\">";
print "<input type=\"hidden\" name=\"dev_stage\" value=\"$dev_stage\">";
print "<input type=\"hidden\" name=\"anat_name\" value=\"$anat\">";
print "<input type=\"hidden\" name=\"h\" value=\"700\">";
print "</form>";
print "</td>";


print "<td align=\"center\">";
print "<input type=\"submit\" value=\"Close Windows\" onclick=\"self.close();\">";
print "</td>";

print "</tr>";
print "</table>";
print "</center>";
print "<br><br>";

/*
//$h=500;
$h=$_GET["h"];
$w=$h;
$R0=$h/3;
$R1=$R0/10;
*/
/*
$h=($R0+$R1)*2.1;
$w=$h;
*/

$GLOBAL=(array) null;
$GLOBAL=networkGLOB("$clusterid",$h,$w,$R0,$R1,$dev,$anat);

$tmp=(array) null;
for ($i=0;$i<count($GLOBAL)+1;$i++)
{
if (count($GLOBAL[$i])==0) continue;
$tmp[count($tmp)]=$GLOBAL[$i];
}

$GLOBAL=$tmp;

//print_r($GLOBAL);


/*print_r($GLOBAL);
print "<br>";
*/
/*
if (count($GLOBAL)==1) {print "EMPTY NETWORK !";return;}
else print_r($GLOBAL);
*/
print "<MAP NAME=\"mymap0\">";

for ($i=0;$i<count($GLOBAL);$i++)
{

$cur=$GLOBAL[$i];
//if (strlen($cur)==0) {print "EMPTY!";return;}
if (count($cur)==0) {print "<br><br><center><h1>No Gene Regulatory Network are matching your query";return;}

	foreach ($cur as $key => $val)
		{
		
		$gene=$key;
		$requete="SELECT \"GENE_CLUSTER_ID\" from \"GENE_CONCEPT_NAME\" where \"GENE_CLUSTER_NAME\"='$gene'";
		$stmt=pg_query($c,$requete);
		$row=pg_fetch_array($stmt);
		$clustid=$row["GENE_CLUSTER_ID"];
		if (strlen($clustid)==0) $clustid=$gene;


		$coords=$val;
		$tmp=explode("@",$coords);
		$X=round($tmp[0]);
		$Y=round($tmp[1]);

//print $X." ".$Y."<br>";

if ($X>$centreX) $X-=20;
if ($X<$centreX) $X+=50;
if ($Y>$centreY) $Y-=10;
if ($Y<$centreY) $Y+=10;


$len=strlen($gene);
$size=$len*10;

		$X1=$X;
		$Y1=$Y;
		$X2=$X+$size;
		//$X2=$X+$size;
 		$Y2=$Y+50;


		//print "<AREA HREF=\"http://crfb.univ-mrs.fr/aniseed/gene-card.php?clusterid=$clustid\" COORDS=\"3500,5833,3540,5850\" border=\"0\">";
		print "<AREA HREF=\"view-net.php?clusterid=$clustid&dev_stage=$dev_stage&anat_name=$anat&h=$h\" COORDS=\"$X1,$Y1,$X2,$Y2\" border=\"0\">";

		}

}


print "</MAP>";



print "<center>";
print "<img src=\"imgNet2.php?clustid=$clusterid&h=$h&dev=$dev&anat=$anat\" USEMAP=\"#mymap0\" BORDER=\"0\" ><br>";
print "</center>";













include ("frames_footer.php");
?>