<!-- Display informations of the experiment of intersest -->
<?php
/*
    ANISEED, NISEED System and Database
    Copyright (C) 2007 Olivier Tassy, Fabrice Daian, Patrick Lemaire

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
	//connection
	include("connection.php");
//Title before frames_header
print '<title>ANISEED v3.0 - Insitu </title>';


	//if( (isset($_GET["FHeader"]))and($_GET["FHeader"]!="n") )
	$head="";
	if(isset($_GET["FHeader"]))
	    $head=$_GET["FHeader"];
	
	if( $head!="n" )
	    include("frames_header.php");
	else
		//echo '<body bgcolor="#505F70" text="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">';
		echo '<body bgcolor="#FFFFFF">';
?>

<script language="JavaScript">

	function searchIt(){
		tab=new Array();
		
		count=0;
		for(a=0;a<document.form2.length;++a){
			if(document.form2[a].checked==true){
				obj=document.form2[a];
				tab[obj.name]=obj.value;
				++count;
			}
		}
		
		targ=''; amp=''; reg=''; mut='';
		
		for (key in tab){
				if(tab[key]=="idanat")
					reg=reg+key+':';
					
				if(tab[key]=="amputation")
					amp=amp+key+':';
				
				else if(tab[key]=="target")
					targ=targ+':'+key;
				
				else if(tab[key]=="mutant")
					mut=mut+':'+key;
		}
		
		targ='&target='+targ.substring(1,targ.length);
		reg='&idanat='+reg;
		amp='&amputation='+amp;
		mut='&mutant='+mut.substring(1,mut.length);
		
		phplink='insitu-result.php?BOOLanat=1&BOOLmut=1&BOOLtarg=1&BOOLamp=1'+targ+reg+amp+mut;
		
		if(document.form.species.checked==true){
			phplink+="&species="+document.form.species.value;
			++count;
		}
		if(document.form.stage.checked==true){
			phplink+="&selectediddev="+document.form.stage.value+":";
			++count;
		}
		
		
		for (a=0;a<document.form3.length;a++) {
		 	if ( (document.form3[a].checked)&&(document.form3[a].value=='1') ) {
				phplink+="&xref=1";
		 	}
		 	else if ( (document.form3[a].checked)&&(document.form3[a].value=='2') ) {
				phplink+="&xref=2";
		 	}
			
		}
		
		if(count==0){
			alert("Click on the checkboxes to select the properties you want to search for.");
			return;
		}
		
		//window.document.open(phplink);
		document.location.href=phplink;
	}
	
	
//fonctions pour le zoom des images
	function ZoomIn() {
			for(a=0;a<document.images.length;++a){
				if(document.images[a].name=="thumb")
					document.images[a].width+=20;
			}
	}
	function ZoomOut() {
			for(a=0;a<document.images.length;++a){
				if(document.images[a].name=="thumb")
					document.images[a].width-=20;
			}
	}

//systeme pour afficher en grand le thumbnail selectionne
	function growPics(pic){
		document.images["BIGimage"].src = pic.src;
		document.images["BIGimage"].id = pic.name;
		document.images["BIGimage"].border = 1;
	}
	function growPics2(pic){
		document.images["BIGimage"].src = pic.src;
		document.images["BIGimage"].id = pic.name;
		document.images["BIGimage"].border = 1;
		document.images["BIGimage"].width = 370;
	}
	function getOriginal(lien){
		if(lien.id.length>0)
			//window.open("insitu-original-picture.php?id="+lien.id);
			self.location.href = "insitu-original-picture.php?id="+lien.id;
	}

</script>




<?php
	$id = $_GET["id"];
	//connection
	//include("connection.php");
	print "<br>";
	/////////////////////////////////////////////////////////////////////////////////
	////////////////////////////////////requete//////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////////////
	
	$requete="SELECT A.\"WILD_TYPE\", A.\"DEV_STAGE_ID\", A.\"SPECIES\", A.\"EXP_COMMENTS\", A.\"TIME\", A.\"TEMPERATURE\", A.\"IM_COMMENTS\", B.\"NAME\" AS \"DEV\", C.\"NAME\", C.\"SURNAME\", C.\"MAIL\", C.\"LOGO\", D.\"ENTRY_DATE\" FROM \"IN_SITU\" A, \"DEV_STAGE\" B, \"AUTHOR\" C, \"ENTRY_ORIGIN\" D WHERE (A.\"CHECKED\"='y') AND (A.\"PRIVATE\" ='n') AND (A.\"IN_SITU_ID\"=$id) AND (A.\"DEV_STAGE_ID\"=B.\"DEV_STAGE_ID\") AND (D.\"BIO_ID\"=$id) AND (D.\"AUTHOR_ID\"=C.\"AUTHOR_ID\")";
    $stmtcond = pg_query($c,$requete);
    if (! $rowcond=pg_fetch_array($stmtcond) ){
	    print "<br><br><center><h2><strong>No match</strong></h2></center><br><br>";
		if($_GET["FHeader"]!="n" )
			include("frames_footer.php");
		else
			echo '</body>';
		return;
	}
	//print '<font color="#D64242" size="3"><b><a style="color:#D64242;text-decoration:none;" href="neigh.php?h=1000&ish='.$id.'">I</a>nsitu data</b></font><br>';
	print '<font color="#D64242" size="3"><b>Insitu data</b></font><br>';

?>


		<br>
		<form name="form">
		<?php
		    if(strlen($rowcond["LOGO"])>0) print '&nbsp;&nbsp;<img align="absmiddle" border="0" src="pictures/'.$rowcond["LOGO"].'"><br>';
		?>
<table border="0">
<tr>
<td valign="top">
<font color="#656565" size="-2"><b>Author: </b></font>
</td>
<td valign="top"><strong><a href="mailto:<? echo $rowcond["MAIL"];?>"><font color="#000000" size="-2"><? print $rowcond["SURNAME"]." ".$rowcond["NAME"]; ?></font></a></strong>
</td>
<td valign="top"><font color="#656565" size="-2"><b>Entry date: </b></font><font color="#000000" size="-2"><b><?php print $rowcond["ENTRY_DATE"]; ?></b></font>
</td>
<td>&nbsp;</td>
<!--</tr>-->

<?php 


//Role different pour l'ISH

$rannot="SELECT \"ANNOTATOR_ID\",\"ANNOTATION_DATE\" from \"ENTRY_ORIGIN\" where \"BIO_ID\"='$id'";
$sannot=pg_query($c,$rannot);

//On fait afficher les informations sur l'annotator
$fetch=pg_fetch_array($sannot);
$annotator_id=$fetch["ANNOTATOR_ID"];
if (strlen($annotator_id)>0)
{
$annotation_date=$fetch["ANNOTATION_DATE"];
$rannot="SELECT \"NAME\",\"SURNAME\",\"MAIL\" from \"AUTHOR\" where \"AUTHOR_ID\"='$annotator_id'";
$sannot=pg_query($c,$rannot);
$fetch2=pg_fetch_array($sannot);
//print "<tr>";
print "<td valign=\"top\">";
print "<font color=\"#656565\" size=\"-2\"><b>Annotator: </b></font></td><td valign=\"top\"> <strong> <a href=\"mailto:".$fetch2["MAIL"]."\"><font color=\"#000000\" size=\"-2\">".$fetch2["SURNAME"]." ".$fetch2["NAME"]."</font></a></strong></td><td valign=\"top\"><font color=\"#656565\" size=\"-2\"><b>Annotation date: </b></font><font color=\"#000000\" size=\"-2\"><b>";
if (strlen($annotation_date)>0) print "$annotation_date</b></font>";
else print "<em>Undefined</em></b></font>";
print "</td>";
//print "</tr>";
}
print "<td>&nbsp;</td>";


$rcura="SELECT \"CURATOR_ID\",\"CURATION_DATE\" from \"ENTRY_ORIGIN\" where \"BIO_ID\"='$id'";
$scura=pg_query($c,$rcura);

//On fait afficher les informations pour le curator
$fetch=pg_fetch_array($scura);
$curator_id=$fetch["CURATOR_ID"];
if (strlen($curator_id)>0)
{
$curation_date=$fetch["CURATION_DATE"];
$rcura="SELECT \"NAME\",\"SURNAME\",\"MAIL\" from \"AUTHOR\" where \"AUTHOR_ID\"='$curator_id'";
$scura=pg_query($c,$rcura);
$fetch2=pg_fetch_array($scura);
//print "<tr>";
print "<td valign=\"top\">";
print "<font color=\"#656565\" size=\"-2\"><b>Curator: </b></font></td><td valign=\"top\"> <strong> <a href=\"mailto:".$fetch2["MAIL"]."\"><font color=\"#000000\" size=\"-2\">".$fetch2["SURNAME"]." ".$fetch2["NAME"]."</font></a></strong></td><td valign=\"top\"><font color=\"#656565\" size=\"-2\"><b>Curation date: </b></font><font color=\"#000000\" size=\"-2\"><b>";
if (strlen($curation_date)>0) print "$curation_date</b></font></td></tr>";
else print "<em>Undefined</em></b></font></td></tr>";
}

print "</table>";
?>

		<table border="0" width="100%" cellspacing="0">
          <tr>
            <td><font color="#456898" size="3"><b>Picture description</b></font></td>
		  </tr><tr>
            <td align="right" width="50%"><?php  print "<font color=\"#656565\" size=\"2\"><b>".$rowcond["SPECIES"]."<input name=\"species\" type=\"checkbox\" value=\"".$rowcond["SPECIES"]."\">&nbsp; &nbsp; &nbsp;".$rowcond["DEV"]."<input name=\"stage\" type=\"checkbox\" value=\"".$rowcond["DEV_STAGE_ID"]."\"></b></font>";  ?></td>
		  </tr><tr> 
            <td valign="top"> 
				<table border="0" width="100%" cellspacing="0">
					<tr>
						<td align="left" valign="top">
							
							<?php
							//recherche des images
							$requete="SELECT \"PICTURE_ID\", \"CONTROL\", \"PATH\" FROM \"PICTURE\" WHERE \"IN_SITU_ID\" = $id";
							$stmt = pg_query($c,$requete);
							$booli=0;
							while($row=pg_fetch_array($stmt)){
								$idpicture=$row["PICTURE_ID"];
								print '<table border="0" cellspacing="0" cellpadding="0">';
								/*if(strlen($row["PATH"])>0)
									echo "<tr><td><img src=\"picturesDB/".$row["PATH"]."\" border=\"1\" width=\"180\" name=\"$idpicture\" onClick=\"self.growPics2(this);\"></td></tr> ";*/
								if(strlen($row["PATH"])>0)
								{
								  if (!preg_match("/mix/",$row["PATH"]))
			    						echo "<tr><td><img src=\"picturesDB/".$row["PATH"]."\" border=\"1\" width=\"180\" name=\"$idpicture\" onClick=\"self.growPics2(this);\"></td></tr> ";
								  else 
									{
									if ($booli==0) {$booli++;
									print '<tr><td>&nbsp;</td></tr><tr><td><img src="pictures/button-mix.jpg" border="0" onClick="window.open(\'viewmixes.php?id='.$id.'\')"></td></tr><tr><td>&nbsp;</td></tr>';
									}
									}
								}
								else
								    echo "<tr><td><img src=\"picture.php?id=$idpicture\" border=\"1\" width=\"180\" name=\"$idpicture\" onClick=\"self.growPics(this);\"></td></tr> ";
								if ($row["CONTROL"]=="y"){
								    $query_control_id = "SELECT \"CTRL_ISH_ID\"
									FROM \"PICTURE\" JOIN \"MUTANT\" USING(\"IN_SITU_ID\")
									WHERE \"IN_SITU_ID\"=$id AND \"CONTROL\"='y';";
									$result_control_id = pg_query($c,$query_control_id);
									$array_control_id = pg_fetch_array($result_control_id);
									$control_id = $array_control_id["CTRL_ISH_ID"];
									if(preg_match("/[0-9]+/",$control_id))
									{
										print "<tr><td align=\"center\" valign=\"top\"><H4><a href='http://aniseed-ibdm.univ-mrs.fr/insitu.php?id=$control_id'>Control</a></H4></td></tr><tr><td>&nbsp;</td></tr>";
									}
									else
									{
										print "<tr><td align=\"center\" valign=\"top\"><H4><a href='#'>Control</a></H4></td></tr><tr><td>&nbsp;</td></tr>";
									}

								}
								print '</table>';
							}
							//echo "<img src=\"picture.php?id=$id\">&nbsp;"
							//echo "<a href=\"insitu-original-picture.php?id=$id\">Get the original file</a>" 
							?>
						</td>
						<td width="400" align="center">
							<img border="0" name="BIGimage" src="pictures/clic a picture.gif" onClick="self.getOriginal(this);" id="">
						</td>
					</tr>
				</table>
 
            </td>
          </tr>
		  <tr>
		  	<td align="left" valign="top">
<div style="border-top:1px solid black;padding:5px;"/>
<font color="#456898" size="3"><b>Insitu comments</b></font>
			 <br><?php echo "<font color=\"#000000\" size=\"-1\">".$rowcond["IM_COMMENTS"]."</b></font>"; ?>
		  </tr>
        </table>
		</form>
		
   	  <form name="form2">

<div style="border-top:1px solid black;padding:5px;"/>
<font color="#456898" size="3"><b>Insitu expression profile</b></font>
	  <center>
    <table width="99%" cellpadding="0" cellspacing="0" border="0" style="border:0px solid #456898;padding:10px;">
      <tr align="center" valign="middle"> 
        <td style="border-bottom:1px solid black;padding:2px;"><font color="#456898" size="2"><b>Expression profile</b></font></td>
        <td style="border-bottom:1px solid black;padding:2px;"><font color="#456898" size="2"><b>Clone</strong></td>
        <td style="border-bottom:1px solid black;padding:2px;"><font color="#456898" size="2"><b>Method</strong></td>
        <td style="border-bottom:1px solid black;padding:2px;"><font color="#456898" size="2"><b>Substrate</strong></td>
      </tr>
    <!--  <tr align="center" valign="middle"> 
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>-->
      <?php
	  //creation de l'arbre anatomique minimal
//			$requeteT="SELECT A.TARGET_ID, A.REGION_ID, A.SUBCELL_POS, A.PROBE_ID, A.METHOD, A.INTENSITY, A.SUBSTRATE, B.NAME, B.FULL_NAME, B.TYPE, C.NAME AS ANATNAME, D.NAME AS SONDENAME, D.FULL_NAME AS SONDEFULL_NAME, D.TYPE AS SONDETYPE FROM CIONA_DESIGN.TARGET A, CIONA_DESIGN.MOL_ENTITY B, CIONA_DESIGN.MOL_ENTITY D, CIONA_DESIGN.ANAT_ENTITY C WHERE (A.IN_SITU_ID=$id) AND (A.TARGET_ID=B.MOL_ID) AND (A.REGION_ID=C.ANAT_ID) AND (A.PROBE_ID=D.MOL_ID)";
            $requeteT="SELECT A.\"TARGET_ID\", A.\"SURE\", A.\"PART_OF\", A.\"REGION_ID\", A.\"SUBCELL_POS\", A.\"PROBE_ID\", A.\"METHOD\", A.\"INTENSITY\", A.\"SUBSTRATE\", B.\"NAME\", B.\"FULL_NAME\", B.\"TYPE\" FROM \"TARGET\" A, \"MOL_ENTITY\" B WHERE (A.\"IN_SITU_ID\"=$id) AND (A.\"TARGET_ID\"=B.\"MOL_ID\")";
            
			$stmtT = pg_query($c,$requeteT);
			$compte=-1;
			while($rowT=pg_fetch_array($stmtT)){
			    ++$compte;
				$data[$compte] = $rowT["REGION_ID"];
				
				$row=$rowT["REGION_ID"];
				$data2[$row][0] = $rowT["SURE"];
				$data2[$row][1] = $rowT["SUBCELL_POS"];
				$data2[$row][2] = $rowT["INTENSITY"];
				$data2[$row][3] = $rowT["NAME"]."#";
				$data2[$row][4] = $rowT["METHOD"];
				$data2[$row][5] = $rowT["SUBSTRATE"];
               			$data2[$row][6] = $rowT["TYPE"];
				$data2[$row][7] = $rowT["PART_OF"];
				
				$data2[$row][8] = $rowT["TARGET_ID"];
				
				$mol[$rowT["TARGET_ID"]]=$rowT["NAME"]; //recup du nom et de l'id des mol. pour faire des recherches de similitudes et de divergences /contextes.
				$typemol[$rowT["TARGET_ID"]]=$rowT["TYPE"]; //recup de son type;
			}
/* SIMULATION D'UNE REQUETE SUR HIERARCHIE PAR UNE PROCEDURE DE REQUETES RECURSIVES */

function select_recursif_descendant($conn,$start,$res,$nivo)
{
global $rowcond;
global $data;
global $data2;
global $row;
global $dataline;
global $lines;
global $final;
global $ll;

if ($start!='')
$requete="SELECT * FROM \"ANAT_ENTITY\" WHERE \"DEV_STAGE_ID\"=".$rowcond["DEV_STAGE_ID"]." and \"CHILD_OF\"= $start ";
else 
$requete="SELECT * FROM \"ANAT_ENTITY\" WHERE \"DEV_STAGE_ID\"=".$rowcond["DEV_STAGE_ID"]." and \"CHILD_OF\" is null ";

//print $requete;

$stmt=pg_query($conn,$requete);

if (pg_num_rows($stmt)!=0) $nivo++;//print "Nz";
if (pg_num_rows($stmt)==0) $nivo--;//print "Ze";


while($row2=pg_fetch_array($stmt))
	{
	$dataline="<tr><td>";
	//print $nivo."<br>";
				for($a=0;$a<$nivo-1;++$a){
					if( $nivo>1 )
					    $dataline.='&nbsp;&nbsp;<font color="#999999">|</font>&nbsp;&nbsp;';
				}
				
				if( $row2["TYPE"]=='cell' )
					$dataline.="<img src=\"pictures/cell.gif\">";
				else if( $row2["TYPE"]=='organism' )
					$dataline.="<img src=\"pictures/tetard.gif\">";
				else
					$dataline.="<img src=\"pictures/region.gif\">";
				
				
				if( in_Array($row2["ANAT_ID"],$data) ){ /*MODIF A VERIF ICI sur data ou data2*/
		            $row=$row2["ANAT_ID"];
			
					//intensite du signal -> mot +/- gros
					if($data2[$row][2]=="++"){
					    $dataline.='<font size="+1">';
					}else if($data2[$row][2]=="+++"){
					    $dataline.='<font size="+2">';
					}else{
					    $dataline.='<font>';
			        }
					
					$partof="";
					if($data2[$row][7]=="X") $partof='<font color="#990000">Part of </font>'; else $partof="";
					
					$dataline.=$partof.'<strong><a href="short_hierarchy.php?region='.$row2[ "ANAT_ID"].'&dev='.$rowcond["DEV_STAGE_ID"].'"><font color="#000000" size="-1">'.$row2["NAME"].'</font></a></strong></font><input type="checkbox" name="'.$row2["ANAT_ID"].'"value="idanat">';
					
					//indique une localisation sub cellulaire
					if( strlen($data2[$row][1])>0 ){ $dataline.='<font color="#990000">('.$data2[$row][1].')</font>'; }
					
					//indique si l'annotation est sure ou non
					if($data2[$row][0]=="X") $dataline.='<img src="pictures/not-sure.jpg" title="Not sure">';
			
					$print=1;//ordre d'imprimer les lignes de la hierarchie de cet element
				}else{
					$dataline.='<font color="#656565" size="-1">'.$row2["NAME"].'</font>';
				}
				if( $print==1 ){

				    $aa=split("#",$data2[$row][3]);
					$dataline.= '</td><td align="center">';
					for($a=0;$a<=count(@aa);++$a){
					    if(strlen($aa[$a])>0){
						
							if( $data2[$row][6]=="clone" )
								$dataline.="<a href=\"molecule-clone2.php?name=";
							else if( $data2[$row][6]=="clone_sequence" )
								$dataline.="<a href=\"molecule-clone.php?name=";
							else if( $data2[$row][6]=="gene" )
								$dataline.="<a href=\"molecule-gene.php?name=";
							else if( $data2[$row][6]=="construction" )
								$dataline.="<a href=\"construct-view.php?constructid=";
							else
							    $dataline.='<a href="" name="';

							if( $data2[$row][6]=="construction" ){
								$dataline.=$data2[$row][8];
							} else {
								$dataline.=$aa[$a];
							}
							$dataline.='"><font color="#000000" size="-1">'.$aa[$a].'</font></a><input type="checkbox" name="'.$aa[$a].'"value="target"> ';
						}					}
					$dataline.='</td><td align="center"><font color="#000000" size="-1">'.$data2[$row][4].'</font></td>';
					$dataline.='</td><td align="center"><font color="#000000" size="-1">'.$data2[$row][5].'</font></td>';
				}
				
				$dataline.='</td></tr>';
				$lines[ $nivo-1 ]=$dataline;
				$lines=array_slice($lines,0,$nivo);
				if( $print==1 ){
				    for($f=0; $f<count($lines); ++$f){
					    if(! in_array($lines[$f], $final) )
						    $final[$ll++]=$lines[$f];
                    }
					$print=0;
				}
	$res=select_recursif_descendant($conn,$row2["ANAT_ID"],$res,$nivo);
	}
return $res;
}
/* FIN DE LA SIMULATION */

			$lines=array(); $print=0; $final=array(); $ll=0;
						
			$res=select_recursif_descendant($c,null,$res,$nivo);



            foreach($final as $key=>$value){
			    print $value;
			}
			

?>
  </table>
  </center>


<div style="border-top:1px solid black;padding:5px;"/>
<?php
//recherche des genes correspondants:
	print "<font color=\"#456898\" size=\"3\"><b>Predicted corresponding gene </b></font>";
	print '<table width="99%" border="0" cellspacing="0" cellpadding="0">';
	$abc=0;
	while (list($key, $value) = each($mol)) {
		$count=0;
	      $geneidlist="";
		  if( $typemol[$key]=="clone" ){
			  $requete="SELECT distinct \"ANISEED_CLUSTER_ID\" from \"CLONE_SEQ\" where \"CLONE_NAME\"='$value'";
			  $stmt = pg_query($c,$requete);
			  while($row=pg_fetch_array($stmt)){
			       $geneidlist[$count++]=$row["ANISEED_CLUSTER_ID"]; //+ieur genes poss si les est d'un meme clone correspondent a des modeles differents
			  }

			//KYOTO
			  		$requete="select \"NAME\" from \"MOL_ENTITY\" where \"MOL_ID\"=(SELECT distinct \"ANISEED_KYOTO_CLUSTER_ID\" from \"CLONE_SEQ\" where \"CLONE_NAME\"='$value' and \"ANISEED_KYOTO_CLUSTER_ID\" is not null)";
				    	$resultset=pg_query($c,$requete);
					$row5bis=pg_fetch_array($resultset);
					$requete="select \"MOL_ID\" from \"MOL_ENTITY\" where \"NAME\" like '".$row5bis["NAME"].".%' and \"TYPE\" <> 'abstract'";
					$resultset=pg_query($c,$requete);						  
					while($row5=pg_fetch_array($resultset)){
						   $geneidlist[$count++]=$row5["MOL_ID"];

					  }

					//ENSEMBL
					//$requete="SELECT \"TRANSCRIPT_ID\" from \"TRANSCRIPT\" where \"ABSTRACT_ID\" =(SELECT distinct \"ANISEED_ENSEMBL_CLUSTER_ID\" from \"CLONE_SEQ\" where \"CLONE_NAME\"='$value' and \"ANISEED_ENSEMBL_CLUSTER_ID\" is not null)";//LA VRAI REQUETE
					$requete="SELECT \"TRANSCRIPT_ID\" from \"TRANSCRIPT\" where \"ABSTRACT_ID\" in (SELECT distinct \"ANISEED_ENSEMBL_CLUSTER_ID\" from \"CLONE_SEQ\" where \"CLONE_NAME\"='$value' and \"ANISEED_ENSEMBL_CLUSTER_ID\" is not null) limit 1";//MODIFIE TEMPORAIREMENT
					
					    	$resultset=pg_query($c,$requete);
						//print $requete;
						  
					while($row5=pg_fetch_array($resultset)){
						   $geneidlist[$count++]=$row5["TRANSCRIPT_ID"]; //+ieur genes poss si les est d'un meme clone correspondent a des modeles differents

					  }





		  }
		  else if( $typemol[$key]=="clone_sequence" ){
			  $requete="SELECT \"ANISEED_CLUSTER_ID\" from \"CLONE_SEQ\" where \"CLONE_SEQ_ID\"=$key";
			  $stmt = pg_query($c,$requete);
			  while($row=pg_fetch_array($stmt)){
			       $geneidlist[$count++]=$row["ANISEED_CLUSTER_ID"];
			  }

					//KYOTO
			  		$requete="select \"NAME\" from \"MOL_ENTITY\" where \"MOL_ID\"=(SELECT distinct \"ANISEED_KYOTO_CLUSTER_ID\" from \"CLONE_SEQ\" where \"CLONE_SEQ_ID\"='$key')";
				    	$resultset=pg_query($c,$requete);
					$row5bis=pg_fetch_array($resultset);
					$requete="select \"MOL_ID\" from \"MOL_ENTITY\" where \"NAME\" like '".$row5bis["NAME"].".%' and \"TYPE\" <> 'abstract'";
					$resultset=pg_query($c,$requete);						  
					while($row5=pg_fetch_array($resultset)){
						   $geneidlist[$count++]=$row5["MOL_ID"];

					  }

					//ENSEMBL
					$requete="SELECT \"TRANSCRIPT_ID\" from \"TRANSCRIPT\" where \"ABSTRACT_ID\"=(
						SELECT distinct \"ANISEED_ENSEMBL_CLUSTER_ID\" from \"CLONE_SEQ\" where \"CLONE_SEQ_ID\"='$key')";
					    	$resultset=pg_query($c,$requete);
						
						  
					while($row5=pg_fetch_array($resultset)){
						   $geneidlist[$count++]=$row5["TRANSCRIPT_ID"]; //+ieur genes poss si les est d'un meme clone correspondent a des modeles differents

					  }







		  }
		  else if( $typemol[$key]=="gene" ){
		      $geneidlist[$count++]=$key;
	      }
		  else if( $typemol[$key]=="construction" ){
		      $geneidlist[$count++]=$key;
	      }
		  
		  for($a=0; $a<count($geneidlist); ++$a){
		    if(strlen($geneidlist[$a])>0){
			  ++$abc;
			  $requete="SELECT distinct A.\"NAME\", B.\"SYNO\", B.\"ORIGIN\" from \"GENE\" A, \"SYNO\" B where A.\"GENE_ID\"=B.\"GENE_ID\" and B.\"GENE_ID\"=".$geneidlist[$a]."order by B.\"ORIGIN\" DESC";
			  $stmt = pg_query($c,$requete);;
			  $syno=""; $aaa=0;
			  while($row=pg_fetch_array($stmt)){
			      $genename=$row["NAME"];
			      if($row["SYNO"]==$row["NAME"])
				      continue;
				  if(++$aaa>1)
					  $syno.=' <strong><font color="000000">/</font></strong> ';
				  $syno.=$row["SYNO"];
				  if($row["ORIGIN"]=="user-JGI")
				      $syno.="*";
				  
			  }

//print_r($geneidlist);

			 // print '<tr valign="top"><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
              print "<tr><td><font color=\"#000000\" size=\"-1\"><b>".$value." </b></font></td><td><a href=\"molecule-gene.php?name=".$genename."\"><font color=\"#000000\" size=\"-1\">".$genename."</font></a></td><td width=\"60%\"><font color=\"#000000\" size=\"-1\"><b>".$syno."</b></font></td></tr>";
			}
		  }
	}
	print '</table>';
	if($abc==0)
	    print "None";
	reset($mol);
?>


<div style="border-top:1px solid black;padding:5px;"></div>
<table width="100%" border="0" cellspacing="0">
  <tr>
    <td><font color="#456898" size="3"><b>Experimental conditions</b></font></td>
  </tr>
  
<?php
	$comments=$rowcond["EXP_COMMENTS"];
	echo "<tr><td><font color=\"#000000\" size=\"-1\">$comments</b></font></td></tr>";
	//echo "<tr><td>&nbsp;</td></tr>";
	if(strlen($rowcond["TIME"])>0)
		echo "<tr><td><strong>Staining duration: </strong>".$rowcond["TIME"]." H</td></tr>";
	if(strlen($rowcond["TEMPERATURE"])>0)
		echo "<tr><td><strong>Temperature: </strong>".$rowcond["TEMPERATURE"]." C</td></tr>";
	
?>
</table>

<br>
<?php
if( ($rowcond["WILD_TYPE"]=='n')or($rowcond["WILD_TYPE"]=='N') ){
      ////////////////////////////////
      //TAB des molecules deregulees//
	  ////////////////////////////////
      print '<strong>Deregulated molecules</strong>';
      print '<center><table width="99%" cellpadding="0" cellspacing="0" border="0">  <tr align="center" valign="middle">  <td style="border-bottom:1px solid black;padding:2px;"><font color="#456898" size="2"><b>Name</b></font></td>  <td style="border-bottom:1px solid black;padding:2px;"><font color="#456898" size="2"><b>Regulation type</b></font></td><td style="border-bottom:1px solid black;padding:2px;"><font color="#456898" size="2"><b>Molecular tool</b></font></td><td style="border-bottom:1px solid black;padding:2px;"><font color="#456898" size="2"><b>From stage</b></font></td><td style="border-bottom:1px solid black;padding:2px;"><font color="#456898" size="2"><b>To stage</b></font></td>'; 

//print '</tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';

   	///////////////////////////////////////////
      //$requete="SELECT A.BIO_ID, A.UP_DOWN, A.TO_ID, A.FROM_ID, A.COMMENTS, B.NAME, B.FULL_NAME, C.NAME AS FROMSTAGE, D.NAME AS TOSTAGE FROM CIONA_DESIGN.MUTANT A, CIONA_DESIGN.MOL_ENTITY B, CIONA_DESIGN.DEV_STAGE C, CIONA_DESIGN.DEV_STAGE D WHERE (A.IN_SITU_ID=$id) AND (A.BIO_ID=B.MOL_ID) AND (A.FROM_ID=C.DEV_STAGE_ID) AND (A.TO_ID=D.DEV_STAGE_ID)";
	  //on ne peut pas faire de jointures avec les dev stage id car ces donn�s sont optionnelles
	  $requete="SELECT A.\"INHIBITOR_ID\", A.\"BIO_ID\", A.\"UP_DOWN\", A.\"TO_ID\", A.\"FROM_ID\", B.\"NAME\", B.\"FULL_NAME\", B.\"TYPE\" FROM \"MUTANT\" A, \"MOL_ENTITY\" B WHERE (A.\"IN_SITU_ID\"=$id) AND (A.\"BIO_ID\"=B.\"MOL_ID\") order by A.\"BIO_ID\"";// AND (A.FROM_ID=C.DEV_STAGE_ID)";// AND (A.TO_ID=C.DEV_STAGE_ID)";

	        
	  $stmt = pg_query($c,$requete);
	  $count=0;
  	  while($row=pg_fetch_array($stmt)){
	      ++$count;
	  	  print "<tr align=\"center\" valign=\"middle\" >\n";
		  
		  //elts deregule
		  
			  $name='';
			  if(strlen($row["NAME"])>0)
			  	$name=$row["NAME"];
			  else
			  	$name=$row["FULL_NAME"];
		  
			  print "<td><a href= 'molecule-gene.php?name=".$row["NAME"]."'><font color=\"#000000\" size=\"-1\">".$row["NAME"]."</font></a><input type=\"checkbox\" name=\"".$name."\"value=\"mutant\"></td>\n";
		  
		  //regu type
		  print "<td><font color=\"#000000\" size=\"-1\">".$row["UP_DOWN"]."</font></td>\n";
		  
		  //mol tool
		  if(strlen($row["INHIBITOR_ID"])>0){
			  $re = "SELECT \"NAME\" FROM \"MOLECULAR_TOOL\" WHERE \"MOLECULAR_TOOL_ID\" = ".$row["INHIBITOR_ID"];
			  $st = pg_query($c,$re);
			  $ro=pg_fetch_array($st);
			  print "<td><a href=\"moltool-card.php?id=".$row["INHIBITOR_ID"]."\"><font color=\"#000000\" size=\"-1\">".$ro["NAME"]."</font></a></td>\n";
		  }else{print "<td>&nbsp;</td>";}
		  
		  //from
		  if(strlen($row["FROM_ID"])>0){
			  $re = "SELECT \"NAME\" FROM \"DEV_STAGE\" WHERE \"DEV_STAGE_ID\" = ".$row["FROM_ID"];
			  $st = pg_query($c,$re);
			  $ro=pg_fetch_array($st);			  
			  print "<td><font color=\"#000000\" size=\"-1\">".$ro["NAME"]."</font></td>\n";
		  }else{print "<td>&nbsp;</td>";}
		  
		  //to
		  if(strlen($row["TO_ID"])>0){
			  $re="SELECT \"NAME\" FROM \"DEV_STAGE\" WHERE \"DEV_STAGE_ID\"='".$row["TO_ID"]."'";
			  $st = pg_query($c,$re);
			  $ro=pg_fetch_array($st);
			  print "<td><font color=\"#000000\" size=\"-1\">".$ro["NAME"]."</font></td>\n";
		  }else{print "<td>&nbsp;</td>";}
		  
		  //print "<td>&nbsp;".OCIResult($stmt, "COMMENTS")."</td>\n";
		  
	  	  print "</tr>\n";
		  //print '<tr valign="top"><td><hr size="1"></td><td><hr size="1"></td><td><hr size="1"></td><td><hr size="1"></td><td><hr size="1"></td></tr>';
  	  }
      print '</table>';
	  if($count==0) print 'NONE';
	  print '</center>';




     
///////////////////////////////
      //TAB des manip embryo
///////////////////////////////
      print '<br><strong>Embryo manipulations</strong> ';
      print '<center><table width="99%" cellpadding="0" cellspacing="0" border="0">  <tr align="center" valign="middle">  <td style="border-bottom:1px solid black;padding:2px;"><font color="#456898" size="2"><b>Removed anatomy part</b></font></td>  <td style="border-bottom:1px solid black;padding:2px;"><font color="#456898" size="2"><b>From stage</b></font></td> </tr>';
  
	  $requete="SELECT A.\"STRUCTURE_ID\", A.\"FROM_ID\", C.\"NAME\" FROM \"EMBRYO_MANIP\" A, \"ANAT_ENTITY\" C WHERE (A.\"IN_SITU_ID\"=$id) AND (A.\"STRUCTURE_ID\"=C.\"ANAT_ID\")";
      $stmt = pg_query($c,$requete);
  	  $count=0;
  	  while($row=pg_fetch_array($stmt)){
	      ++$count;
	  	  print "<tr align=\"center\" valign=\"middle\">\n";

		  	  //if(strlen(OCIResult($stmt, "STRUCTURE_ID"))>0){
				  //$re="SELECT NAME FROM CIONA_DESIGN.ANAT_ENTITY WHERE ANAT_ID=".OCIResult($stmt, "STRUCTURE_ID");
				  //$st = OCIParse($connection, $re);
				  //OCIExecute($st);
				  //OCIFetch($st);
				  print "<td><a href= \"short_hierarchy.php?dev=".$rowcond["DEV_STAGE_ID"]."&region=".$row["STRUCTURE_ID"]."#tag\"><font color=\"#000000\" size=\"-1\">".$row["NAME"]."</font></a><input type=\"checkbox\" name=\"".$row["STRUCTURE_ID"]."\"value=\"amputation\"></td>\n";
			  //}else{print "<td></td>";}
			  
			  if(strlen($row["FROM_ID"])>0){
				  $re = "SELECT \"NAME\" FROM \"DEV_STAGE\" WHERE \"DEV_STAGE_ID\"='".$row["FROM_ID"]."'";
				  $st = pg_query($c,$re);
				  $ro=pg_fetch_array($st);
				  print "<td><font color=\"#000000\" size=\"-1\">".$ro["NAME"]."</font></td>\n";
			  }else{print "<td>&nbsp;</td>";}
			  
			  //print "<td>".OCIResult($stmt, "COMMENTS")."&nbsp;</td>\n";
		  
	  	  print "</tr>\n";
		  print '<tr valign="top"><td><hr size="1"></td><td><hr size="1"></td></tr>';
  	  }
      print '</table>';
	  if($count==0) print 'NONE';
	  
	  print '</center>';
}else{
    print "<font color=\"#000000\" size=\"-1\">Wild_Type Embryo.</font>";
}
?>
</form>

<div style="border-top:1px solid black;padding:5px;"></div>

<font color="#456898" size="3"><b>References</b></font>
<table width="100%" border="0" cellspacing="0">
	
	<?php
	//$requete="SELECT \"TITLE\",\"PUBMED_ID\",\"PAPER\",\"AUTHORS\",\"COMMENTS\",\"URL\" FROM \"REFERENCE\" WHERE \"BIO_ID\"=$id";
	
	$requete="SELECT \"ARTICLE_ID\",\"TITLE\",\"PUBMED_ID\",\"PAPER\",\"AUTHORS\",\"COMMENTS\",\"URL\" FROM \"ARTICLE\" WHERE \"PUBMED_ID\" in (select \"PUBMED_ID\" from \"REFERENCE\" where \"BIO_ID\"=$id)";
 
	$stmtT = pg_query($c,$requete);
	$count=0;
	while ($rowT=pg_fetch_array($stmtT)){
		++$count;
		echo ('<tr><td>');
		echo ( "<a target=\"blank\" href=\"view-article.php?id=".$rowT["ARTICLE_ID"]."\"><font color=\"#000000\" size=\"-1\">".$rowT["TITLE"]."</font></a>  &nbsp; &nbsp;<font color=\"#000000\" size=\"-1\"><b>".$rowT["AUTHORS"]."</b></font>    &nbsp; &nbsp;<font color=\"#656565\" size=\"-1\">".$rowT["PAPER"]."</font>" );
		echo ( "&nbsp;&nbsp;&nbsp;<a target=\"blank\" href=\"".$rowT["URL"]."\"><font color=\"#000000\" size=\"-1\">".$rowT["URL"]."</font></a>" );
//30/04/2009 : don't want to print the comments for annotators	
		//	echo ( '<br><font color=\"#000000\" size=\"-1\">'.$rowT["COMMENTS"].'</font>' );
		echo ('</td></tr>');
	}
	if($count==0)
		echo ('<tr><td>NONE</td></tr>');
	?>
	
</table>



<div style="border-top:1px solid black;padding:5px;"></div>

<table width="100%" border="0" cellspacing="0">
	<tr>
  		<td><font color="#456898" size="3"><b>Search Tools</b></font></td>
	</tr>
	<tr><td><font color="#456898" size="-1"><b>Similarity search</b></font></td>
            <td></td></tr>
	<tr>
		
    	
    <td><font color="#000000" size="-1">To find pictures sharing similarities check the properties you are interested 
      in and press the 'Submit' button. </font></td>
		<td><img src="pictures/button-submit.jpg" border="0" onClick="self.searchIt();"></td>
	</tr>
	<tr>
		
    <td><font color="#000000" size="-1">For anatomical data you can choose to search for the same terms ('Exact'), 
      for terms including these regions ('Including'), or terms included in these 
      regions ('subset').</font></td>
		<td>
		  <form name="form3">

          <label><input type="radio" name="xref" value="0" checked><font color="#000000" size="-1">Exact</font></label><br>
          <label><input type="radio" name="xref" value="1"><font color="#000000" size="-1">Including</font></label>
         &nbsp;  <img src="pictures/up.gif"><br>
		  <label><input type="radio" name="xref" value="2"><font color="#000000" size="-1">Subset</font></label>
        &nbsp;&nbsp;&nbsp;&nbsp; <img src="pictures/down.gif"> 
      </form>
		</td>
	</tr>
</table>


<div style="border-top:1px solid black;padding:5px;"/></div>
<font color="#456898" size="-1"><b>in situ pictures clustering</b></font> 
<?php
    print "<center><a href=\"newcompare.php?mode=4&id=$id\"><img src=\"pictures/button-profiles.jpg\" border=\"0\"></a></center>";
?>


<?php

 	while (list($key, $value) = each($mol)) {
	
	    print '<div style="border-top:1px solid black;padding:5px;"></div><table width="99%" border="0" cellpadding="0" cellspacing="0">';
		echo '<tr align="left" valign="middle">';
		
		//echo "<td><strong>deregulated molecules context for $value expression: </strong></td>";
		//echo "<td><strong>Embryo manipulation context for $value expression: </strong></td>";.
		echo "<td><font color=\"#456898\" size=\"-1\"><b>Expression profile modification search for $value</b></font></td><td>&nbsp;</td>";
        //echo "<td background=\"pictures/barre-red.jpg\" align=\"right\"><strong>Varying experimental conditions for $value</strong></td>";
		echo "</tr><tr align=\"left\" valign=\"middle\"><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>";
		
		print "<center>
	<a href=\"compare.php?mode=2&id=$id&target=$key\"><img src=\"pictures/button-deregulated.jpg\" border=\"0\"></a></center></td>    <td><center>
	<a href=\"compare.php?mode=3&id=$id&target=$key\"><img src=\"pictures/button-manipulation.jpg\" border=\"0\"></a></center></td></tr>";
        print "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>  <tr><td><center><a href=\"compare.php?mode=1&id=$id&target=$key\"><img src=\"pictures/button-wild-type.jpg\" border=\"0\"></a></center></td>    <td>&nbsp;</td></tr>";
		
		echo "</td></tr></table>";
	}
	
?>


<br>

<?php
	//if( (isset($_GET["FHeader"]))and($_GET["FHeader"]!="n") )
	if( $head!="n" )
    	include("frames_footer.php");
	else
		echo '</body>';
?> 