<html>
<head>
<title>ANISEED - Expression data result (Ciona intestinalis, Halocynthia roretzi)</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="This page lists some Halocynthia roretzi or Ciona intestinalis expression data. You could click on the more button to have more information about an experiment">
<meta name="keywords" content="Daian, Dauga, Lemaire, Sobral, Tassy, Experiment data, Ciona intestinalis expression data, Ciona intestinalis, Halocynthia roretzi, ascidian database, ciona intestinalis database, expression data, in situ data">
<meta name = "robots" content = "index, follow, all">
<META HTTP-EQUIV="Content-Language" CONTENT="EN">
<style type="text/css">
</style>
</head>

<?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/>.

*/
 include("connection.php");

include("navigation.php");

//Title before frames_header
print '<title>ANISEED v3.0 - In situ result</title>';

include("frames_header.php");

//print_r($_POST);


if( isset($_POST["only_constructs"]) && $_POST["only_constructs"]==1) {
	print '<font color="#D64242" size="3"><b>Search results for regulatory region analysis.</b></font><br><br>';	
} else {
	print '<font color="#D64242" size="3"><b>In situ search results.</b></font><br><br>';
}
?>

<SCRIPT>
function ZoomIn() {
		for(a=0;a<document.images.length;++a){
			if( (document.images[a].name=="pics") && (document.images[a].width+20 < 1000) )
				document.images[a].width+=20;
		}
}
function ZoomOut() {
		for(a=0;a<document.images.length;++a){
			if( (document.images[a].name=="pics") && (document.images[a].width-20 > 0) )
				document.images[a].width-=20;
		}
}

function setbrowsernext() {
    document.formulaire.offset.value = eval(document.formulaire.offset.value) + eval(document.formulaire.nbMAX.value);
	return;
}
function setbrowserprev() {
    document.formulaire.offset.value = eval(document.formulaire.offset.value) - eval(document.formulaire.nbMAX.value);
    return;
}

function setbrowsergoto(a) {
	document.formulaire.offset.value=eval((a-1))*eval(document.formulaire.nbMAX.value);
}


</SCRIPT>


<?php
	

//connection
//include("connection.php");
	
//variables pour le systeme page suiv/prec
if( isset($_POST["option"]) ) $option=$_POST["option"];
if( isset($_POST["offset"]) ) $offset=$_POST["offset"];
if( isset($_POST["nbMAX"])  ) $nbMAX=$_POST["nbMAX"];
	
if(! isset($option)) $option= 1;
if(! isset($offset)) $offset= 0;
if(! isset($nbMAX)) $nbMAX= 20;
	
/////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////requete//////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
	

////////////////////////////
//RAJOUT A MOI 
$globalgenelist="";
///////////////////////////


//print_r($_POST);

//species
if(isset($_POST["species"])) $species = $_POST["species"];
	
//regions
$sql_region='';	



$boool=0;
//if (strlen($_POST["notidanat"])>1) {$boool=1;}
if ((strlen($_POST["notidanat"])>1)&&($_POST["fatemode"]==0)) {$boool=1;}



////////// AJOUT: 10/12/2007//////////.
//if (($_POST["notidanat"]>1) && ($_POST["fatemode"])==0) {$_POST["BOOLanat"]=0;$_POST["only"]=0;}
//////////////////////////////////////



if( ((strlen($_POST["idanat"])>1)&&($_POST["fatemode"]==0) ) || ($boool==1)  ){
		
		$tabanat=split(":",$_POST["idanat"]);
		array_pop($tabanat);
		
		if($_POST["BOOLanat"]==1){//and
		
			//signifie que l'on cherche aussi les parents des anat fournis
			if($_POST["xref"]==1){

				/* SIMULATION D'UNE REQUETE SUR HIERARCHIE PAR UNE PROCEDURE DE REQUETES RECURSIVES */
				$IN1="";
				function select_recursif_descendant_2($conn,$start,$res) {
					global $IN1;

					if ($start!='')
						$requete2="SELECT * FROM \"ANAT_ENTITY\" WHERE \"ANAT_ID\"= $start ";
					else 
						return;

					$stmt2=pg_query($conn,$requete2);
					while($row2=pg_fetch_array($stmt2)) {
						$IN1.=$row2["ANAT_ID"].",";
						$res=select_recursif_descendant_2($conn,$row2["CHILD_OF"],$res);
					}
					return $res;
				}

				for($a=0;$a<count($tabanat);++$a)
					{
					$IN1="";
					$res=select_recursif_descendant_2($c,$tabanat[$a],$res);
					//$IN1=substr($IN1,0,strlen($IN1)-1);
					$IN1.=$tabanat[$a];
					if ($IN1=="") $IN1="0";	/*Cas du IN vide*/
						$sql_region.="INTERSECT SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" IN(".$IN1.") ";
					}

					/* FIN DE LA SIMULATION */

			}
			//signifie que l'on cherche aussi les enfants des anat fournis
			else if($_POST["xref"]==2){


				/* SIMULATION D'UNE REQUETE SUR HIERARCHIE PAR UNE PROCEDURE DE REQUETES RECURSIVES */
				$IN2="";
				function select_recursif_descendant($conn,$start,$res){
					global $IN2;
					if ($start!='')
						$requete2="SELECT * FROM \"ANAT_ENTITY\" WHERE \"CHILD_OF\"= $start ";
					else 
						return;
					$stmt2=pg_query($conn,$requete2);
					while($row2=pg_fetch_array($stmt2))	{
						$IN2.=$row2["ANAT_ID"].",";
						$res=select_recursif_descendant($conn,$row2["ANAT_ID"],$res);
					}
					return $res;
				}
				/* FIN DE LA SIMULATION */

				for($a=0;$a<count($tabanat);++$a){
					$IN2="";
					$res=select_recursif_descendant($c,$tabanat[$a],$res);
					//$IN2=substr($IN2,0,strlen($IN2)-1);
					$IN2.=$tabanat[$a];
					if ($IN2=="") $IN2="0"; /*Cas du IN vide*/
					$sql_region.="INTERSECT SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" IN(".$IN2.") ";
				}

			}
			//signifie que l'on cherche le terme exact
			else{
				for($a=0;$a<count($tabanat);++$a){
					$sql_region.=" INTERSECT SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" = $tabanat[$a]";
				}
			}

//////////// AJOUT 12/12/2007/////////


			if ((strlen(trim($_POST["notidanat"]))>1)&&($_POST["fatemode"]==0))	{
				$nottabanat=split(":",$_POST["notidanat"]);
				array_pop($nottabanat);

				$notzz=join(",",$nottabanat);	
				$zz=join(",",$tabanat);
		

				if (strlen($_POST["idanat"])==0){//possible DISTINCT 

					$sql_region=" INTERSECT (
						SELECT \"IN_SITU_ID\" FROM \"TARGET\" where \"IN_SITU_ID\" in (
						select \"IN_SITU_ID\" from \"IN_SITU\" where \"DEV_STAGE_ID\" in (
						select \"DEV_STAGE_ID\" from \"ANAT_ENTITY\" where \"ANAT_ID\" in (".$notzz.")
						)
						)
						EXCEPT
						SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" IN (".$notzz.")";

				} else { 

				
				$sql_region.=" EXCEPT SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" IN (".$notzz.")";

				


/*
					$sql_region=" INTERSECT (
						SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" IN (".$zz.")
						EXCEPT
						SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" IN (".$notzz."))";
*/

				}		
			} /*else {
	
				$sql_region=" INTERSECT (
					SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" IN (".$zz.")";
		
			}*/

////////////
			
			if($_POST["only"]==1){ //print_r($_POST); //print "<font color=\"red\">POST ONLY=1</font>";//gestion du only  //avec le and on veut autant de trucs marques que de trucs selectionnes mais pas plus.
			   
			/* $sql_region.=" intersect select IN_SITU_ID from (select CIONA_DESIGN.TARGET.*, count(*) over (partition by in_situ_id) count from CIONA_DESIGN.TARGET) where count = ".(count($tabanat));*/

			$sql_region.=" EXCEPT SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" NOT IN (".(join(",",$tabanat)).")";





			}
			
		}else{//or
	

			$zz=join(",",$tabanat);

			//if($_POST["only"]==2)  //gestion de l'option "not stained"
			//    $sql_region="INTERSECT SELECT IN_SITU_ID FROM CIONA_DESIGN.TARGET WHERE NOT EXIST( REGION_ID IN(".$zz.") )";
		    //else
			

			//Pour les notanat

			if ((strlen($_POST["notidanat"])>1)&&($_POST["fatemode"]==0))	{
				$nottabanat=split(":",$_POST["notidanat"]);
				array_pop($nottabanat);

				$notzz=join(",",$nottabanat);			

				if (strlen($_POST["idanat"])==0){//possible DISTINCT 
					/*$sql_region=" INTERSECT (
						SELECT \"IN_SITU_ID\" FROM \"TARGET\" EXCEPT
						SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" IN (".$notzz.")";*/
					$sql_region=" INTERSECT (
						SELECT \"IN_SITU_ID\" FROM \"TARGET\" where \"IN_SITU_ID\" in (
						select \"IN_SITU_ID\" from \"IN_SITU\" where \"DEV_STAGE_ID\" in (
						select \"DEV_STAGE_ID\" from \"ANAT_ENTITY\" where \"ANAT_ID\" in (".$notzz.")
						)
						)
						EXCEPT
						SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" IN (".$notzz.")";

				} else { 
					$sql_region=" INTERSECT (
						SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" IN (".$zz.")
						EXCEPT
						SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" IN (".$notzz.")";
				}		
			} else {
	
				$sql_region=" INTERSECT (
					SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" IN (".$zz.")";
		
			}


			if($_POST["only"]==1){  //gestion du only  //avec le or on veut juste l'un des trucs selectionn�comme marqu�ou une combinaison mais pas plus.
			    $sql_region.=" EXCEPT SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" NOT IN (".$zz.")";
			}
			$sql_region.=")";




		}
}

// Les Fates
$sql_fate="";
$tabfate="";
if(isset($_POST["fate"])) 
	$tabfate=$_POST["fate"];
	
$tabfatelist="";
if(is_array($tabfate)){
	$tabfatelist=join("','",$tabfate);
}else{
	$tabfatelist=$tabfate;
	//$tabfate=split("','",$tabfatelist);
}

//Traitement pour elimination eventuelles des Magic quotes !
$tabfatelist=str_replace("\\","",$tabfatelist);



//Ajout pour les NotFates

$tabnotfate="";
if (isset($_POST["notfate"])) {
	$tabnotfate=$_POST["notfate"];
	$tabnotfatelist="";
	if (is_array($tabnotfate)){
		$tabnotfatelist=join("','",$tabnotfate);
	}
	else{
		$tabnotfatelist=$tabnotfate;
	}

	//Traitement pour elimination eventuelles des Magic quotes !
	$tabnotfatelist=str_replace("\\","",$tabnotfatelist);
}

/*
print "Fate    : $tabfatelist <br>";
print "Not Fate: $tabnotfatelist <br>";
*/

//print $tabfate[0];
if((strlen($tabfatelist)>0)&&($_POST["fatemode"]==1))
{ 
	//Modif pour conformité a notfate
	if ((strlen($tabnotfatelist)>0))
	{
		$sql_fate="INTERSECT(
		SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" in (select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" in ('".$tabfatelist."') ) 
		EXCEPT
		SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" in ( (select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" in ('".$tabnotfatelist."') ) )
		)";
		//print $sql_fate;
	}
	else
	{
	$sql_fate="INTERSECT(SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" in (select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" in ('".$tabfatelist."') ))";

	}
//print $sql_fate;
}
//Le cas ou l'on ne regarde que les NotFate
else
{
	if ((strlen($tabnotfatelist)>0))
	{
	$sql_fate="INTERSECT(
	SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" in ( (select \"ANAT_ID\" from \"FATE\"))
	EXCEPT
	SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"REGION_ID\" in ( (select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" in ('".$tabnotfatelist."') ) )
	)";
	//print $sql_fate;
	}
}

//recup des dev stage id
//ne s'utilise qu'en l'absence d'anat_id
//if( (strlen($_POST["selectediddev"])>1)&&((! strlen($sql_region)>0)||$_POST["only"]==2) ){
$sql_dev_stage="";
if( (strlen($_POST["selectediddev"])>1)&&(! strlen($sql_region)>0) ){
//if (strlen($_POST["selectediddev"])>1){
	$tabdev=split(":",$_POST["selectediddev"]);
	array_pop($tabdev);
	$zz=join(",",$tabdev);
		
	$sql_dev_stage="INTERSECT SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" WHERE ( \"DEV_STAGE_ID\" IN(".$zz.") )";
}
	
//verif les auteurs
$sql_author="";
if( strlen($_POST["author"])>1 ){
	$author=split(":",$_POST["author"]);
	$zz=join("','",$author);
	$zz=strtoupper($zz);
		
	$sql_author="INTERSECT SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" WHERE \"IN_SITU_ID\" IN(  select \"BIO_ID\" from \"ENTRY_ORIGIN\" where \"AUTHOR_ID\" in (select \"AUTHOR_ID\" from \"AUTHOR\" where UPPER(\"NAME\") in ('".$zz."') ) ) ";
	
}
	
//Verif annotator
$sql_annot="";
if( strlen($_POST["annotator"])>1 ){
	$annotator=split(":",$_POST["annotator"]);
	$zz=join("','",$annotator);
	$zz=strtoupper($zz);
	//print "ICI";
	$sql_annot="INTERSECT SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" WHERE \"IN_SITU_ID\" IN(  select \"BIO_ID\" from \"ENTRY_ORIGIN\" where \"ANNOTATOR_ID\" in (select \"AUTHOR_ID\" from \"AUTHOR\" where UPPER(\"NAME\") in ('".$zz."') ) ) ";
	
}

//check pmid
$sql_pmid="";
if( strlen($_POST["pmid"])>1 ){
	
	$pmid=split(":",$_POST["pmid"]);
	$zz=join("','",$pmid);
	$zz=strtoupper($zz);
		
	$sql_pmid="INTERSECT SELECT \"BIO_ID\" AS \"IN_SITU_ID\" FROM \"REFERENCE\" where \"PUBMED_ID\"='$zz' ";
}
	
//recup target
$sql_target="";
if(strlen($_POST["target"])>0){

	//Test pour savoir si c un refine foireux
	$test=explode(" ",$_POST["target"]);
	if ($test[0]=="Error!")
	{
   		print "<br><br><strong>ERROR:</strong> due to performance reasons, you cannot search for more than 100 molecules";
		include ("frames_footer.php");
		return;
	}

	$targetTMP = split(":",strtoupper($_POST["target"]));
		
//print_r($targetTMP);print "<br>";
	//// Traitement spécifique pour le traitement des aniseed Gene model

	if ($_POST["MOLtype"]==10)
		{
		//print "ANISEED_GME";

		$tar=(array) null;
		for ($i=0;$i<count($targetTMP);$i++)
		{
		$new=strtolower($targetTMP[$i]);
		$new=str_replace("aniseedv3_","cluster",$new);

		$requete0="select \"NAME\" from \"MOL_ENTITY\" where \"MOL_ID\" in (SELECT \"GENE_MODEL_ID\" from \"GENE_CONCEPT\" where \"GENE_CLUSTER_ID\"='$new')";
		//print "==>".$requete0;
		$stmt0=pg_query($c,$requete0);
		while ($row0=pg_fetch_array($stmt0))
		{
			$tar[count($tar)]=trim(strtoupper($row0["NAME"]));
		}

		}

		$targetTMP=$tar;
		$_POST["MOLtype"]=2;

		}

//print_r($targetTMP);print "<br>";

	//////////////////////////////////////////////////////////////////////





/*	if(count($targetTMP)>100){
	    print "<br><br><strong>ERROR:</strong> due to performance reasons, you cannot search for more than 100 molecules";
	    include ("frames_footer.php");
		return;
	}
*/

		
	if($_POST["BOOLtarg"]==1){//and
/*
		if ($_POST["MOLtype"]==10)
		{
		//// C'est un ANISEED GENE MODEL
		print "RECHERCHE PAR ANISEED GM<br>";

		$sql_target.="INTERSECT SELECT \"IN_SITU_ID\" from \"TARGET\" where \"TARGET_ID\" in (";		


		
		for ($a=0;$a<count($targetTMP);$a++)
			{

			$new=trim(str_replace("ANISEEDV3_","cluster",$targetTMP[$a]));

			$requete0="SELECT \"GENE_MODEL_ID\" from \"GENE_CONCEPT\" where \"GENE_CLUSTER_ID\"='$new'";
			$stmt0=pg_query($c,$requete0);
			print "====>$requete0<bR>";
			$c=0;
			while ($row0=pg_fetch_array($stmt0))
				{
				if ($c==0) $sql_target.="(SELECT \"MOL_ID\" from \"MOL_ENTITY\" where \"MOL_ID\"='".$row0["GENE_MODEL_ID"]."')";
				else $sql_target.="UNION (SELECT \"MOL_ID\" from \"MOL_ENTITY\" where \"MOL_ID\"='".$row0["GENE_MODEL_ID"]."')";
				$c++;
				}
			}
		$sql_target.=")";
		}

		else */if($_POST["MOLtype"]==2){ //si c un gene -> recup des clones correspondant
			/*
			for ($a=0; $a < count($targetTMP); ++$a){
                    $sql_target.=" INTERSECT SELECT IN_SITU_ID FROM CIONA_DESIGN.TARGET WHERE TARGET_ID IN ( select B.clone_id from ciona_design.clone_seq A, ciona_design.clone B where (A.clone_name=B.clone_name) and A.cluster_id=(select cluster_id from ciona_design.clustering where gene_id=(select gene_id from ciona_design.gene where name='$targetTMP[$a]')) ) OR TARGET_ID IN ( select clone_seq_id from ciona_design.clone_seq where cluster_id=(select cluster_id from ciona_design.clustering where gene_id=(select gene_id from ciona_design.gene where name='$targetTMP[$a]')) )";
				}
			*/
			
			////nouvelle version pour utiliser le clustering maison
			for ($a=0; $a < count($targetTMP); ++$a){
				/*
					$sql_target.=" INTERSECT
					 SELECT IN_SITU_ID
					  FROM CIONA_DESIGN.TARGET
					   WHERE TARGET_ID IN ( select B.clone_id from ciona_design.clone_seq A, ciona_design.clone B where A.clone_name=B.clone_name and A.aniseed_cluster_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]') )
					    OR TARGET_ID IN ( select clone_seq_id from ciona_design.clone_seq where aniseed_cluster_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]'))
						 OR TARGET_ID IN (select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]')";
				*/
                    /*$sql_target.=" INTERSECT
					 SELECT \"IN_SITU_ID\"
					  FROM \"TARGET\"
					   WHERE \"TARGET_ID\" IN ( 
					   select B.\"CLONE_ID\" from \"CLONE_SEQ\" A, \"CLONE\" B where A.\"CLONE_NAME\"=B.\"CLONE_NAME\" and A.\"ANISEED_CLUSTER_ID\"=(select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]') 
					   UNION select \"CLONE_SEQ_ID\" from \"CLONE_SEQ\" where \"ANISEED_CLUSTER_ID\"=(select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]')
					   UNION select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]')";*/
				
				//KYOTO
				if ($targetTMP[$a]{0}=="K") //KYOTO
				{
					$temp=explode(".",$targetTMP[$a]);
					$abstract=$temp[0].".".$temp[1].".".$temp[2];
					$qu="SELECT \"MOL_ID\" from \"MOL_ENTITY\" where \"NAME\"='$abstract' and \"TYPE\"='abstract'";
					$st=pg_query($c,$qu);
					$ro=pg_fetch_array($st);

					$clustidK=$ro["MOL_ID"];
					//FIN AJOUT
				}

				//ENSEMBL
				if ($targetTMP[$a]{0}=="E")
				{
					$qu="SELECT \"ABSTRACT_ID\" from \"TRANSCRIPT\" where \"TRANSCRIPT_ID\"=(select \"MOL_ID\" from \"MOL_ENTITY\" where \"NAME\"='".$targetTMP[$a]."')";
					$st=pg_query($c,$qu);
					$ro=pg_fetch_array($st);

					$clustidE=$ro["ABSTRACT_ID"];
				}

				$sql_target.=" INTERSECT
					SELECT \"IN_SITU_ID\"
					FROM \"TARGET\"
					WHERE \"TARGET_ID\" IN ( 
					select B.\"CLONE_ID\" from \"CLONE_SEQ\" A, \"CLONE\" B where A.\"CLONE_NAME\"=B.\"CLONE_NAME\" and
				   (A.\"ANISEED_CLUSTER_ID\"=(select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]')";				   
			    if (strlen($clustidK)>0) $sql_target.="OR \"ANISEED_KYOTO_CLUSTER_ID\" ='$clustidK'";
				if (strlen($clustidE)>0) $sql_target.="OR \"ANISEED_ENSEMBL_CLUSTER_ID\"='$clustidE'";
				$sql_target.=")
				   UNION select \"CLONE_SEQ_ID\" from \"CLONE_SEQ\" where (\"ANISEED_CLUSTER_ID\"=(select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]')";
				if (strlen($clustidK)>0) $sql_target.="OR \"ANISEED_KYOTO_CLUSTER_ID\" ='$clustidK'";
				if (strlen($clustidE)>0) $sql_target.="OR \"ANISEED_ENSEMBL_CLUSTER_ID\"='$clustidE'";
				$sql_target.=")
					   UNION select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]')";

			}
			
		}else{
                //si c un clone
				for ($a=0; $a < count($targetTMP); ++$a){
					$sql_target.=" INTERSECT SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE \"TARGET_ID\" IN (SELECT \"MOL_ID\" FROM \"MOL_ENTITY\" WHERE upper(\"NAME\")='$targetTMP[$a]' OR upper(\"FULL_NAME\")='$targetTMP[$a]')";
				}
		}
			
	}else{//or
			
		if($_POST["MOLtype"]==2){ //si c un gene -> recup des clones correspondant
			$name='';
			    /*	
				for ($a=0; $a < count($targetTMP); ++$a){
					if($a==0)
						$name.=" (TARGET_ID IN ( select B.clone_id from ciona_design.clone_seq A, ciona_design.clone B where (A.clone_name=B.clone_name) and A.cluster_id=(select cluster_id from ciona_design.clustering where gene_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]')) ) OR TARGET_ID IN ( select clone_seq_id from ciona_design.clone_seq where cluster_id=(select cluster_id from ciona_design.clustering where gene_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]')) )) ";
					else
						$name.=" OR (TARGET_ID IN ( select B.clone_id from ciona_design.clone_seq A, ciona_design.clone B where (A.clone_name=B.clone_name) and A.cluster_id=(select cluster_id from ciona_design.clustering where gene_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]')) ) OR TARGET_ID IN ( select clone_seq_id from ciona_design.clone_seq where cluster_id=(select cluster_id from ciona_design.clustering where gene_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]')) )) ";
				}
				$sql_target=" INTERSECT SELECT IN_SITU_ID FROM CIONA_DESIGN.TARGET WHERE ".$name;
				*/
				
				////nouvelle version pour utiliser le clustering maison
            for ($a=0; $a < count($targetTMP); ++$a){
				if($a==0)
				{
					//KYOTO
					if ($targetTMP[$a]{0}=="K") //KYOTO
					{
						$temp=explode(".",$targetTMP[$a]);
						$abstract=$temp[0].".".$temp[1].".".$temp[2];
						$qu="SELECT \"MOL_ID\" from \"MOL_ENTITY\" where \"NAME\"='$abstract' and \"TYPE\"='abstract'";
						$st=pg_query($c,$qu);
						$ro=pg_fetch_array($st);

						$clustidK=$ro["MOL_ID"];
						//FIN AJOUT
					}

					//ENSEMBL
					if ($targetTMP[$a]{0}=="E")
					{
						$qu="SELECT \"ABSTRACT_ID\" from \"TRANSCRIPT\" where \"TRANSCRIPT_ID\"=(select \"MOL_ID\" from \"MOL_ENTITY\" where \"NAME\"='".$targetTMP[$a]."')";
						$st=pg_query($c,$qu);
						$ro=pg_fetch_array($st);

 						$clustidE=$ro["ABSTRACT_ID"];
					}
					//FIN AJOUT

					$name.=" (\"TARGET_ID\" IN ( 
						select B.\"CLONE_ID\" from \"CLONE_SEQ\" A, \"CLONE\" B where A.\"CLONE_NAME\"=B.\"CLONE_NAME\" and (A.\"ANISEED_CLUSTER_ID\"=(select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]')";
					if (strlen($clustidK)>0) $name.="OR \"ANISEED_KYOTO_CLUSTER_ID\" ='$clustidK'";
					if (strlen($clustidE)>0) $name.="OR \"ANISEED_ENSEMBL_CLUSTER_ID\"='$clustidE'";
					$name.=")
						UNION select \"CLONE_SEQ_ID\" from \"CLONE_SEQ\" where (\"ANISEED_CLUSTER_ID\"=(select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]')";
					if (strlen($clustidK)>0) $name.="OR \"ANISEED_KYOTO_CLUSTER_ID\" ='$clustidK'";
					if (strlen($clustidE)>0) $name.="OR \"ANISEED_ENSEMBL_CLUSTER_ID\"='$clustidE'";
					$name.=")
						UNION select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]'
						";
				}
					//$name.=" (TARGET_ID IN ( select B.clone_id from ciona_design.clone_seq A, ciona_design.clone B where A.clone_name=B.clone_name and A.aniseed_cluster_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]') ) OR TARGET_ID IN ( select clone_seq_id from ciona_design.clone_seq where aniseed_cluster_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]')) OR TARGET_ID IN (select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]') )";
				else
				{
					//KYOTO
					if ($targetTMP[$a]{0}=="K") //KYOTO
					{
						$temp=explode(".",$targetTMP[$a]);
						$abstract=$temp[0].".".$temp[1].".".$temp[2];
						$qu="SELECT \"MOL_ID\" from \"MOL_ENTITY\" where \"NAME\"='$abstract' and \"TYPE\"='abstract'";
						$st=pg_query($c,$qu);
						$ro=pg_fetch_array($st);

						$clustidK=$ro["MOL_ID"];
						//FIN AJOUT
					}

					//ENSEMBL

					if ($targetTMP[$a]{0}=="E")
					{
						$qu="SELECT \"ABSTRACT_ID\" from \"TRANSCRIPT\" where \"TRANSCRIPT_ID\"=(select \"MOL_ID\" from \"MOL_ENTITY\" where \"NAME\"='".$targetTMP[$a]."')";
						$st=pg_query($c,$qu);
						$ro=pg_fetch_array($st);

 						$clustidE=$ro["ABSTRACT_ID"];
					}
					//FIN AJOUT


					$name.= "UNION select B.\"CLONE_ID\" from \"CLONE_SEQ\" A, \"CLONE\" B where A.\"CLONE_NAME\"=B.\"CLONE_NAME\" and (A.\"ANISEED_CLUSTER_ID\"=(select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]')";
					if (strlen($clustidK)>0) $name.="OR \"ANISEED_KYOTO_CLUSTER_ID\" ='$clustidK'";
					if (strlen($clustidE)>0) $name.="OR \"ANISEED_ENSEMBL_CLUSTER_ID\"='$clustidE'";
					$name.=")
						UNION select \"CLONE_SEQ_ID\" from \"CLONE_SEQ\" where (\"ANISEED_CLUSTER_ID\"=(select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]')";
					if (strlen($clustidK)>0) $name.="OR \"ANISEED_KYOTO_CLUSTER_ID\" ='$clustidK'";
					if (strlen($clustidE)>0) $name.="OR \"ANISEED_ENSEMBL_CLUSTER_ID\"='$clustidE'";
					$name.=")
						UNION select \"GENE_ID\" from \"GENE\" where upper(\"NAME\")='$targetTMP[$a]'
						";
				}
						//$name.=" OR (TARGET_ID IN ( select B.clone_id from ciona_design.clone_seq A, ciona_design.clone B where A.clone_name=B.clone_name and A.aniseed_cluster_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]') ) OR TARGET_ID IN ( select clone_seq_id from ciona_design.clone_seq where aniseed_cluster_id=(select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]')) OR TARGET_ID IN (select gene_id from ciona_design.gene where upper(name)='$targetTMP[$a]') )";
				
			} //end for
				$sql_target=" INTERSECT SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE ".$name."))";
                                
		}else{
            //si c un clone
			$name='';
			for ($a=0; $a < count($targetTMP); ++$a){
				if($a==0)
					$name.=" (\"TARGET_ID\" IN (SELECT \"MOL_ID\" FROM \"MOL_ENTITY\" WHERE(upper(\"NAME\")='$targetTMP[$a]' OR upper(\"FULL_NAME\")='$targetTMP[$a]'))) ";
				else
					$name.=" OR (\"TARGET_ID\" IN (SELECT \"MOL_ID\" FROM \"MOL_ENTITY\" WHERE(upper(\"NAME\")='$targetTMP[$a]' OR upper(\"FULL_NAME\")='$targetTMP[$a]'))) ";
			}
			$sql_target=" INTERSECT SELECT \"IN_SITU_ID\" FROM \"TARGET\" WHERE ".$name;
		}
			
	}
}
	
	
//recup des mutants
$sql_mutant="";
if((strlen($_POST["mutant"])>0)&&($_POST["BOOLmut"]<2)){
	$mutantTMP = split(":",strtoupper($_POST["mutant"]));
	if($_POST["BOOLmut"]==1){//and
		for ($a=0; $a < count($mutantTMP); ++$a){
			$sql_mutant.=" INTERSECT SELECT \"IN_SITU_ID\" FROM \"MUTANT\" WHERE \"BIO_ID\" IN (SELECT \"MOL_ID\" FROM \"MOL_ENTITY\" WHERE upper(\"NAME\")='$mutantTMP[$a]' OR upper(\"FULL_NAME\")='$mutantTMP[$a]')";
		}
	}else 
		if($_POST["BOOLmut"]==0){//or
			$name='';
			for ($a=0; $a < count($mutantTMP); ++$a){
				if($a==0)
					$name.=" (\"BIO_ID\" IN (SELECT \"MOL_ID\" FROM \"MOL_ENTITY\" WHERE(upper(\"NAME\")='$mutantTMP[$a]' OR upper(\"FULL_NAME\")='$mutantTMP[$a]'))) ";
				else
					$name.=" OR (\"BIO_ID\" IN (SELECT \"MOL_ID\" FROM \"MOL_ENTITY\" WHERE(upper(\"NAME\")='$mutantTMP[$a]' OR upper(\"FULL_NAME\")='$mutantTMP[$a]'))) ";
			}
			$sql_mutant=" INTERSECT SELECT \"IN_SITU_ID\" FROM \"MUTANT\" WHERE ".$name;
		}
		
}else 
	if($_POST["BOOLmut"]==2){//any
		//$sql_mutant=" INTERSECT select in_situ_id from ciona_design.in_situ where wild_type='n'";
		$sql_mutant=" INTERSECT select \"IN_SITU_ID\" from \"MUTANT\"";
	}else 
		if($_POST["BOOLmut"]==3){//none
		    //$sql_mutant=" INTERSECT select in_situ_id from ciona_design.in_situ where wild_type='y'";
			$sql_mutant=" INTERSECT select \"IN_SITU_ID\" from \"IN_SITU\" where \"IN_SITU_ID\" not in (select \"IN_SITU_ID\" from \"MUTANT\")";
		}
		
//recup des manip d'embryon
$sql_manip="";
if($_POST["BOOLmanip"]==1){
    $sql_manip.=" INTERSECT select \"IN_SITU_ID\" from \"EMBRYO_MANIP\"";
}else if($_POST["BOOLmanip"]==2){
	$sql_manip=" INTERSECT select \"IN_SITU_ID\" from \"IN_SITU\" where \"IN_SITU_ID\" not in (select \"IN_SITU_ID\" from \"EMBRYO_MANIP\")";
}
	
	
////////////////////////////////
//MEGA requete //
////////////////////////////////

$requete="SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" WHERE (\"CHECKED\"='y') AND (\"PRIVATE\" = 'n') ";
	
if( (strlen($_POST["idanat"])==0)&&(strlen($species)>0))
	$requete.=" INTERSECT SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" WHERE \"SPECIES\" = '$species' ";


if(strlen($sql_dev_stage)>0)
	$requete.= $sql_dev_stage;
	
if(strlen($sql_region)>0)
	$requete .= $sql_region;
	
if(strlen($sql_fate)>0)
    $requete .= $sql_fate;
	
if(strlen($sql_author)>0)
	$requete .= $sql_author;

if(strlen($sql_annot)>0)
	$requete .= $sql_annot;

if (strlen($sql_pmid)>0)
	$requete .= $sql_pmid;
		
if(strlen($sql_target)>0)
	$requete.= $sql_target;
		
if(strlen($sql_mutant)>0)
	$requete.= $sql_mutant;
		
if(strlen($sql_manip)>0)
	$requete .= $sql_manip;	
	
	
// SPECIAL REGULATORY REGION
if(isset($_POST["only_constructs"]) && $_POST["only_constructs"]==1){
	$only_constructs = 1;	
	//$requete = "(" .$requete.") INTERSECT SELECT \"IN_SITU_ID\" FROM \"TARGET\", \"MOL_ENTITY\" WHERE \"MOL_ID\"=\"TARGET_ID\" AND \"TYPE\"=\'construction\';";
	$requete = "SELECT \"IN_SITU_ID\" FROM \"TARGET\", \"MOL_ENTITY\" WHERE \"MOL_ID\"=\"TARGET_ID\" AND \"TYPE\"='construction' AND \"IN_SITU_ID\" IN (".$requete.")";
		
}
	
if(strlen($_POST["Order"])>0){
	if ($_POST["Order"]=="SPECIES")		 
	   $requete = "SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" A, \"DEV_STAGE\" B  WHERE \"IN_SITU_ID\" IN ($requete) and (A.\"DEV_STAGE_ID\"=B.\"DEV_STAGE_ID\") ORDER BY B.\"SPECIES\", B.\"DEV_PERCENT\", \"IN_SITU_ID\"";
		
	else
	    $requete = "SELECT \"IN_SITU_ID\" FROM \"IN_SITU\" A, \"DEV_STAGE\" B WHERE \"IN_SITU_ID\" IN ($requete) and (A.\"DEV_STAGE_ID\"=B.\"DEV_STAGE_ID\") ORDER BY B.\"DEV_PERCENT\", B.\"SPECIES\", \"IN_SITU_ID\"";
			
}
	
//Debug	
//if(isset($_POST["only_constructs"]) && $_POST["only_constructs"]==1){	
	//print $requete;
//}

$BIGrequete=$requete;	



// print $requete."<br>";


/////////////////////////////////////////////////////////////////////////////////
 /////////////////////////////lecture du resultat/////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

	
$query= pg_query($c,$requete);

resultsBar($query,$offset);

print '<br>
<img src="pictures/zoom-in.gif" onClick="ZoomIn()" border="0">
<img src="pictures/zoom-out.gif" onClick="ZoomOut()" border="0">
';

// Start of table and column headings (ID and Name)
 print "<center><TABLE CELLSPACING=\"0\" BORDER=\"0\" style=\"border:1px solid black;padding:5px;margin:10px;\" WIDTH=\"99%\">\n";
   
// Loop through results
$count=0;
 while( ($row=pg_fetch_array($query)) && ($count < $offset+$nbMAX) )
//while( $row=pg_fetch_array($query) )
   {  
	  if($count++ >= $offset){
   	    print "  <TR><TD>\n";
		
		$id=$row["IN_SITU_ID"];
	    		
		$requete="SELECT A.\"BEING_CURATED\",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.\"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\")";
		//print $requete;
		$resultset = pg_query($c,$requete);
				
		$row2=pg_fetch_array($resultset);
		
		//couleur en fonction de wild type ou non
		$wild=$row2["WILD_TYPE"];
		if($wild=='n'){$color='#CCCC99';}else{$color='#FFFFCC';}
		
		//espece & stade de devt. & logo
		print "<TABLE CELLSPACING=\"0\" BORDER=\"0\" bgcolor=\"$color\" WIDTH=\"100%\" style=\"color:black\"><TR>\n";		
		print '<td><table width="100%" border="0" cellspacing="0" cellpadding="0" style="color:black">'
		  .'<tr>'
		  ."<td align=\"left\" >";
		if(strlen($row2["LOGO"])>0)
			print "<img align=\"absmiddle\" src=\"pictures/".$row2["LOGO"]."\">&nbsp;&nbsp;";
		
		print "<a href=\"insitu.php?id=$id\"><img src=\"pictures/button-more.jpg\" border=\"1\"></a>";

if ($row2["BEING_CURATED"]=='y')
			print "&nbsp;&nbsp;<font size=\"2\" color=\"orange\">This entry is  <strong> being manually curated</font></strong>&nbsp;&nbsp;</td>";
		
//TAG HIGH THROUGHPUT
/*
$qh="select \"BIO_ID\" from \"ENTRY_ORIGIN\" where \"ANNOTATOR_ID\" is null and \"CURATOR_ID\" is null
and \"ANNOTATION_DATE\" is null and \"CURATION_DATE\" is null and \"BIO_ID\" in (
SELECT \"IN_SITU_ID\" from \"IN_SITU\" where \"PRIVATE\"='n' and \"CHECKED\"='y' and \"SPECIES\" like 'Ciona%'
) and \"AUTHOR_ID\" in ('10','151','170','171','190','210')";
$stqh=pg_query($c,$qh);

while ($rh=pg_fetch_array($stqh)) 
	if ($rh["BIO_ID"]==$id) 
		{
		print "&nbsp;&nbsp;<font size=\"2\" color=\"red\"><strong> [High throughput entry]</font></strong>&nbsp;&nbsp;</td>";
		break;
		}
// END OF TAG HIGH THROUGHPUT
*/



		print "<td align=\"right\" valign=\"top\"><font color=\"#456898\" size=\"2\"><b>".$row2["SPECIES"]."&nbsp;&nbsp;&nbsp;&nbsp;".$row2[ "dev"]."</b></font></td>"
		  .'</tr></table></td></tr>';

		
		/* ATTENTION   ICI ON TRAITE LES IMAGES DONC MODIFIER LES CHEMINS D'ACCES EN CONSEQUENCE !!!! */

		//picture
		//$requete="SELECT \"PICTURE_ID\", \"PATH\" FROM \"PICTURE\" WHERE \"IN_SITU_ID\" = $id and \"CONTROL\" IS NULL ";
	$requete="SELECT \"PICTURE_ID\", \"PATH\" FROM \"PICTURE\" WHERE \"IN_SITU_ID\" = $id and \"CONTROL\" IS NULL";		

		$stmtpic = pg_query($c,$requete);
		

		print "<TR><TD><TABLE><tr align=\"top\"><td>";
		while($row3=pg_fetch_array($stmtpic)){
			$idpicture=$row3["PICTURE_ID"];
			if(strlen($row3["PATH"])>0)
				{
				if (!preg_match("/mix/",$row3["PATH"]))
			    echo "<a href=\"insitu.php?id=$id\"><img src=\"picturesDB/".$row3["PATH"]."\" border=1 width=\"100\" name=\"pics\"></a> ";
				}
			else
			    echo "<a href=\"insitu.php?id=$id\"><img src=\"picture-mini.php?id=$idpicture\" border=1 width=\"100\" name=\"pics\"></a> ";
		}
		print "</td><td width=\"45%\"><font size=\"-1\" color=\"#000000\">".(str_replace("<br>"," ",$row2[ "IM_COMMENTS"]))."</font></td></tr>";
		print "</TABLE></TD></TR>\n";
		
		
		print "<TABLE cellpadding=\"0\" CELLSPACING=\"0\" BORDER=\"0\" bgcolor=\"$color\" WIDTH=\"100%\" style=\"color:black\">\n";
			//recherche des cibles
			$requete = "SELECT distinct B.\"SURE\", B.\"PART_OF\", A.\"MOL_ID\", A.\"NAME\", A.\"TYPE\", C.\"NAME\" AS \"REGION\", C.\"ANAT_ID\", C.\"DEV_STAGE_ID\" FROM \"MOL_ENTITY\" A, \"TARGET\" B, \"ANAT_ENTITY\" C where (B.\"IN_SITU_ID\"=$id) AND (B.\"TARGET_ID\"=A.\"MOL_ID\") AND (B.\"REGION_ID\"=C.\"ANAT_ID\") ORDER BY C.\"NAME\"";
			
			//print $requete;

			$resultset = pg_query($c, $requete);
			
			$str='';
			$str2='';
			$mol=null; $typemol=null;//sert a retrouver le gene correspondant

			//Le tableau des parties anatomiques a trier + avoid doublons
			$strsort=(array) null;

			while( $row4=pg_fetch_array($resultset )){
				if(substr_count (  $str, $row4["NAME"] )==0){
					if( $row4["TYPE"]=="clone" )
					    $str.="<a href=\"molecule-clone2.php?name=";
					else if( $row4["TYPE"]=="clone_sequence" )
					    $str.="<a href=\"molecule-clone.php?name=";
					else if( $row4["TYPE"]=="gene" )
					    $str.="<a href=\"molecule-gene.php?name=";
					//REGULATORY REGION	
					else if( $row4["TYPE"]=="construction" ) {					
							$str.="<a href=\"construct-view.php?constructid=".$row4["MOL_ID"]."\">".$row4["NAME"]."</a> - ";	
					} else
					    $str.="<a href=\"\" name=\"";
					
					if( $row4["TYPE"]!="construction" )
						$str.=$row4["NAME"]."\">".$row4["NAME"]."</a> - ";
				    
					$mol[$row4["MOL_ID"]]=$row4["NAME"];
					$typemol[$row4["MOL_ID"]]=$row4["TYPE"];
				}
				//anotation sup sur les "stained anatomy part"
				$partof="";$sure="";
				if($row4["PART_OF"]=="X") $partof="Part of ";  else $partof="";
				if($row4["SURE"]=="X") $sure="?"; else $sure="";
			
				//Sort+avoid doublon
				if (!in_array($row4["REGION"],$strsort))
				{		
$str2.="<a href=\"short_hierarchy.php?region=".$row4["ANAT_ID"]."&dev=".$row4["DEV_STAGE_ID"]."\">$partof".$row4["REGION"]."$sure</a> - ";
//$str2.="<a onmouseover=\"return escape('<center><img src=\'embryos/late32c/late32anim.gif\'></center>');\" href=\"short_hierarchy.php?region=".$row4["ANAT_ID"]."&dev=".$row4["DEV_STAGE_ID"]."\">$partof".$row4["REGION"]."$sure</a> - ";

				$strsort[count($strsort)]=$row4["REGION"];
				}
			}
			
			print "<TR valign=\"top\"><TD width=\"250\"><font color=\"#456898\" size=\"2\"><b>Stained molecule: - </b></font><font size=\"-1\" color=\"#000000\">$str</font></TD>\n";
			
			
			//region
			//Classement des régions anatomiques par ordre alphabétique

			/*
			print_r($strsort);
			usort($strsort,"strcasecmp");
			//sort($strsort);
			print_r($strsort);
			*/
			
			print "<TD><font color=\"#456898\" size=\"2\"><b>Stained region: - </b></font><font size=\"-1\" color=\"#000000\">$str2</font></TD></TR>\n";
			
			
			
///////////////////////
            
			
			while (list($key, $value) = each($mol)) {
			      $count2=0;
			      $geneidlist="";
				  if( $typemol[$key]=="clone" ){
					  $requete="SELECT distinct \"ANISEED_CLUSTER_ID\" from \"CLONE_SEQ\" where \"CLONE_NAME\"='$value'";
					    	$resultset=pg_query($c,$requete);
						
						  
					while($row5=pg_fetch_array($resultset)){
						   $geneidlist[$count2++]=$row5["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 limit 1)";
				    	$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[$count2++]=$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[$count2++]=$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 distinct \"ANISEED_CLUSTER_ID\" from \"CLONE_SEQ\" where \"CLONE_SEQ_ID\"=$key";
					  $resultset=pg_query($c,$requete);
					  while($row5=pg_fetch_array($resultset)){
						   $geneidlist[$count2++]=$row5["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[$count2++]=$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[$count2++]=$row5["TRANSCRIPT_ID"]; //+ieur genes poss si les est d'un meme clone correspondent a des modeles differents

					  }




				  }
				  else if( $typemol[$key]=="gene" ){
					  $geneidlist[$count2++]=$key;
				  }
				  
				  //recherche des noms possibles pour le gene correspondant
				  if(count($geneidlist)>1)
				      $geneidlist=array_unique($geneidlist);

/////////// AJOUT POUR LES CONCEPTS DE GENES //////////////////////////////////////
				$GENE=(array) null;
				for ($a=0;$a<count($geneidlist);++$a)
					{
					//print "==>>".$geneidlist[$a];
					if (strlen($geneidlist[$a])==0) continue;
					$requete0="SELECT distinct \"GENE_CLUSTER_ID\" from \"GENE_CONCEPT\" where \"GENE_MODEL_ID\"='".$geneidlist[$a]."'";
					$stmt0=pg_query($c,$requete0);
					$row0=pg_fetch_array($stmt0);
					//print "==>".$row0["GENE_CLUSTER_ID"]."<br>";

					$GENE[count($GENE)]=$row0["GENE_CLUSTER_ID"];
					}
				$GENE=array_unique($GENE);

				//print_r($GENE);

				for ($a=0;$a<count($GENE);$a++)
				{
				$requete0="SELECT \"GENE_CLUSTER_NAME\" from \"GENE_CONCEPT_NAME\" where \"GENE_CLUSTER_ID\"='".$GENE[$a]."'";
				$stmt0=pg_query($c,$requete0);
				$aaa=0;
				$syno="";
				if (pg_num_rows($stmt0)==0)
					{
					$requete0="SELECT \"GENE_CLUSTER_NAME_BLAST\" as \"GENE_CLUSTER_NAME\" from \"GENE_CONCEPT_NAME_BLAST\" where \"GENE_CLUSTER_ID\"='".$GENE[$a]."'";
					$stmt0=pg_query($c,$requete0);
					}
				while ($row0=pg_fetch_array($stmt0))
					{
					//$genename=$row0["GENE_CLUSTER_NAME"];
					$genename=$GENE[$a];
					if (++$aaa>1)
						$syno.=' <strong><font color="#990000">/</font></strong> ';
					$syno.=$row0["GENE_CLUSTER_NAME"];
					/*if( strlen($syno)-(($aaa-1)*48) > 100 ){
							  $syno.=" <strong><font color=\"#990000\">/</font></strong>...";
							  break;
						}*/
					}


if (strlen($species)==0)
	{
	$requete10="SELECT \"SPECIES\" from \"MOL_ENTITY\" where \"MOL_ID\"='".$geneidlist[0]."'";
	$stmt10=pg_query($c,$requete10);
	$row10=pg_fetch_array($stmt10);
	$species=$row10["SPECIES"];

	}


			if ($species=="Ciona intestinalis")
				{
				print "<tr valign=\"top\"><td><div style=\"border-top:1px solid black;\"/><font size=\"-1\">Predicted Aniseed Gene model for ".$value.": <a href=\"gene-card.php?clusterid=".$genename."\">".(str_replace("cluster","aniseedV3_",$genename))."</a></font></td><td><div style=\"border-top:1px solid black;\"/><font size=\"-1\">".$syno."</font></td></tr>";
				}

////// BOUHHHH
			if ($species=="Halocynthia roretzi")
				{

					$requete10="SELECT \"NAME\" from \"GENE\" where \"GENE_ID\"='".$geneidlist[0]."'";
					$stmt10=pg_query($c,$requete10);
					$row10=pg_fetch_array($stmt10);
					$NAME=$row10["NAME"];
				
					$requete10="SELECT \"DESCRIPTION\",\"EVALUE\" from \"BLAST\" where \"MOL_ID\"='".$geneidlist[0]."'";
					$stmt10=pg_query($c,$requete10);
					$row10=pg_fetch_array($stmt10);
					$syno="";
					$eval=$row10["EVALUE"];
					$description=$row10["DESCRIPTION"];
					if ((strlen($eval)>0)&&(strlen($description)>0))
						{
							if( $eval <= 1e-10)
								$syno.= "HIGHLY ";
							else if( ($eval >= 1e-4) and ($eval <= 1e-3) )
								$syno.= "WEAKLY ";
							if($eval <= 1e-3)
								$syno.= "SIMILAR TO ".$row10["DESCRIPTION"]." (Eval: $eval)";
						}

				print "<tr valign=\"top\"><td><div style=\"border-top:1px solid black;\"/><font size=\"-1\">Halocynthia Transcript model for ".$value.": <a href=\"molecule-gene.php?name=$NAME\">$NAME</a></font></td><td><div style=\"border-top:1px solid black;\"/><font size=\"-1\">".$syno."</font></td></tr>";
				}





				}
/////////////////////////////////////////////////////////////////

				 /* for($a=0; $a<count($geneidlist); ++$a){
					//print "=>>".$geneidlist[$a]."<br>";
					if( (isset($geneidlist[$a]))and(strlen($geneidlist[$a])>0) ){
					  $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";
					  $resultset=pg_query($c,$requete);
					  $syno=""; $aaa=0;
					  while($row6=pg_fetch_array($resultset)){
					      $genename=$row6["NAME"];
						  if($row6["SYNO"]==$row6["NAME"])
							  continue;
						  if(++$aaa>1)
						      $syno.=' <strong><font color="#990000">/</font></strong> ';
						  $syno.=$row6["SYNO"];
						  if($row6["ORIGIN"]=="user-JGI")
							  $syno.="*";
						  
						  if( strlen($syno)-(($aaa-1)*48) > 100 ){
							  $syno.=" <strong><font color=\"#990000\">/</font></strong>...";
							  break;
						  }
					  }
					if($aaa==0){
						$requete="select \"DESCRIPTION\", \"EVALUE\" from \"BLAST\" where \"MOL_ID\"='".$geneidlist[$a]."' and \"SCORE\"=(select max(\"SCORE\") from \"BLAST\" where \"MOL_ID\"='".$geneidlist[$a]."')";
						
						$resultset = pg_query($c,$requete);
						if($row7=pg_fetch_array($resultset)){

							$eval = $row7["EVALUE"];
							if( $eval <= 1e-10)
								$syno.= "HIGHLY ";
							else if( ($eval >= 1e-4) and ($eval <= 1e-3) )
								$syno.= "WEAKLY ";
							if($eval <= 1e-3)
								$syno.= "SIMILAR TO ".$row7["DESCRIPTION"]." (Eval: $eval)";

						}
					}
					
					  
					  
print "<tr valign=\"top\"><td><div style=\"border-top:1px solid black;\"/><font size=\"-1\">Predicted gene model for ".$value.": <a href=\"molecule-gene.php?name=".$genename."\">".$genename."</a></font></td><td><div style=\"border-top:1px solid black;\"/><font size=\"-1\">".$syno."</font></td></tr>";


					////////////////
					//RAJOUT A MOI
					////////////////
					$globalgenelist.=$genename.":";


					}
				  }*/
			}
//////////////////////////////////



            //description des manipulations d'embryon
			if($wild=='n'){
				//recherche des mutants
                $requete = "SELECT distinct \"NAME\", \"BIO_ID\" FROM \"MUTANT\" where \"IN_SITU_ID\"=$id";
				$resultset = pg_query($c,$requete);
				$str='';
				$a=0; $geneidlist="";//sert ensuite a retouver les noms des genes
				while( $row8=pg_fetch_array($resultset) ){
				    $geneidlist[$a++]=$row8["BIO_ID"];
					$str.="<a href=\"molecule-gene.php?name=".$row8["NAME"]."\">".$row8["FULL_NAME"]." ".$row8["NAME"]."</a> - ";
				}
				print "<TR valign=\"top\"><TD><div style=\"border-top:1px solid black;\"/><font color=\"#456898\" size=\"2\"><b>Deregulated molecule: - </b></font><font color=\"#000000\" size=\"-1\">$str</font></TD>\n";
				
				//recherche des amputations
				$requete = "SELECT A.\"DEV_STAGE_ID\", A.\"ANAT_ID\", A.\"NAME\" FROM \"ANAT_ENTITY\" A, \"EMBRYO_MANIP\" B WHERE (B.\"IN_SITU_ID\"=$id) AND (B.\"STRUCTURE_ID\"=A.\"ANAT_ID\")";
				$resultset = pg_query($c,$requete);
				$str='';
				while( $row9=pg_fetch_array($resultset) ){
					$str.="<a href=\"short_hierarchy.php?region=".$row9["ANAT_ID"]."&dev=".$row9["DEV_STAGE_ID"]."\">".$row9["NAME"]."</a> - ";
				}
			    print "<TD><div style=\"border-top:1px solid black;\"/><font color=\"#456898\" size=\"2\"><b>Embryo manipulation: - </b></font><font color=\"#000000\" size=\"-1\">$str</font></TD></TR>\n";


//On va tenter d'introduire la description des conditions experimentales
if ($wild=='n')
{
//Requete pour recuperer le commentaire 
$r="SELECT \"EXP_COMMENTS\" from \"IN_SITU\" where \"IN_SITU_ID\"='$id'";
$st=pg_query($c,$r);
if (pg_num_rows($st)>0)
{
	$rro=pg_fetch_array($st);
	$comment=$rro["EXP_COMMENTS"];
print "<TR valign=\"top\"><TD><div style=\"border-top:1px solid black;\"/><font color=\"#456898\" size=\"2\"><b>Experimental conditions:</b></font></TD>\n";
	print "<TD><div style=\"border-top:1px solid black;\"/><font size=\"2\"><font color=\"#000000\" size=\"-1\"><em> $comment</em></font></TD></TR>\n";
}

}	

			
			
				//recherche des noms possibles pour le gene correspondant
				if(count($geneidlist)>1)
				    $geneidlist=array_unique($geneidlist);
				for($a=0; $a<count($geneidlist); ++$a){
					if( (isset($geneidlist[$a]))and(strlen($geneidlist[$a])>0) ){
						  $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";
						  $resultset = pg_query($c,$requete);
						  $syno=""; $aaa=0;
						  while($row10=pg_fetch_array($resultset)){
						      $genename=$row10["NAME"];
							  if($row10["SYNO"]==$row10["NAME"])
								  continue;
							  if(++$aaa>1)
								  $syno.=' <strong><font color="#990000">/</font></strong> ';
							  $syno.=$row10["SYNO"];
							  if($row10["ORIGIN"]=="user-JGI")
								  $syno.="*";
							  if( strlen($syno)-(($aaa-1)*48) > 100 ){
								  $syno.=" <strong><font color=\"#990000\">/</font></strong>...";
								  break;
							  }
						  }
						if($aaa==0){
							$requete="select \"DESCRIPTION\", \"EVALUE\" from \"BLAST\" where \"MOL_ID\"='".$geneidlist[$a]."' and \"SCORE\"=(select max(\"SCORE\") from \"BLAST\" where \"MOL_ID\"='".$geneidlist[$a]."')";
							//$requete2="select max(score), description, evalue from ciona_design.blast where mol_id=$id";
							$resultset = pg_query($c,$requete);
							if($row11=pg_fetch_array($resultset)){
								$eval = $row11["EVALUE"];
								if( $eval < 1e-10)
									$syno.= "HIGHLY ";
								else if( $eval > 1e-4) 
									$syno.= "WEAKLY ";
								$syno.= "SIMILAR TO ".$row11["DESCRIPTION"]." (Eval: $eval)";
							}
						}
						  
						  if(strlen($syno)>0)
						      print "<tr valign=\"top\"><td><div style=\"border-top:1px solid black;\"/><font size=\"-1\">Possible names for <a href=\"molecule-gene.php?name=".$genename."\">".$genename.": </a></font></td><td><div style=\"border-top:1px solid black;\"/><font size=\"-1\">".$syno."</font></td></tr>";
					}
				}
			    $geneidlist=null;
		
		}
		//print "</TABLE><br>";
		print "</TABLE><br>";

	  }
   }

   print "</TD></TR></TABLE></center>\n";


   if($count==0){
	   print "<br><br><center><h2><strong>No match</strong></h2></center><br><br>";

   }


   print '<img src="pictures/zoom-in.gif" onClick="ZoomIn()" border="0"><img src="pictures/zoom-out.gif" onClick="ZoomOut()" border="0"><br><br>';
   
   //navigation dans les pages (prec suivant)
    echo "<font SIZE=2><center>";
	
	print '<form Method="POST" Action="'.$_SERVER["PHP_SELF"].'" name="formulaire">';
	
	//SPECIAL REGULATORY REGION
	if(isset($only_constructs))
		print '<input type="hidden" name="only_constructs" value="'.$only_constructs.'">';
		
	if(isset($option))
		print '<input type="hidden" name="option" value="'.$option.'">';
	if(isset($species))
		print '<input type="hidden" name="species" value="'.$species.'">';
	if(isset($_POST["selectediddev"]))
		print '<input type="hidden" name="selectediddev" value="'.$_POST["selectediddev"].'">';
	if(isset($_POST["mutant"]))
		print '<input type="hidden" name="mutant" value="'.$_POST["mutant"].'">';
	if(isset($_POST["target"]))
		print '<input type="hidden" name="target" value="'.$_POST["target"].'">';
	if(isset($_POST["amputation"]))
		print '<input type="hidden" name="amputation" value="'.$_POST["amputation"].'">';
	if(isset($_POST["idanat"]))
		print '<input type="hidden" name="idanat" value="'.$_POST["idanat"].'">';
	if(isset($_POST["notidanat"]))
		print '<input type="hidden" name="notidanat" value="'.$_POST["notidanat"].'">';
	if(isset($_POST["Order"]))
		print '<input type="hidden" name="Order" value="'.$_POST["Order"].'">';
	if(isset($_POST["BOOLmut"]))
		print '<input type="hidden" name="BOOLmut" value="'.$_POST["BOOLmut"].'">';
	if(isset($_POST["BOOLtarg"]))
		print '<input type="hidden" name="BOOLtarg" value="'.$_POST["BOOLtarg"].'">';
	if(isset($_POST["BOOLanat"]))
		print '<input type="hidden" name="BOOLanat" value="'.$_POST["BOOLanat"].'">';
	if(isset($_POST["xref"]))
		print '<input type="hidden" name="xref" value="'.$_POST["xref"].'">';
	if(isset($_POST["MOLtype"]))
		print '<input type="hidden" name="MOLtype" value="'.$_POST["MOLtype"].'">';
	if(isset($_POST["author"]))
		print '<input type="hidden" name="author" value="'.$_POST["author"].'">';
	if(isset($_POST["annotator"]))
		print '<input type="hidden" name="annotator" value="'.$_POST["annotator"].'">';

	if(isset($_POST["pmid"]))
		print '<input type="hidden" name="pmid" value="'.$_POST["pmid"].'">';

	if(isset($_POST["only"]))
		print '<input type="hidden" name="only" value="'.$_POST["only"].'">';
	if(isset($_POST["BOOLmanip"]))
		print '<input type="hidden" name="BOOLmanip" value="'.$_POST["BOOLmanip"].'">';
	if(isset($tabfate))
		print '<input type="hidden" name="fate" value="'.$tabfatelist.'">';
	
	if(isset($tabnotfate))
		print '<input type="hidden" name="notfate" value="'.$tabnotfatelist.'">';
	
	if(isset($_POST["fatemode"]))
		print '<input type="hidden" name="fatemode" value="'.$_POST["fatemode"].'">';
	if(isset($nbMAX))
		print '<input type="hidden" name="nbMAX" value="'.$nbMAX.'">';
	if(isset($offset))
		print '<input type="hidden" name="offset" value="'.$offset.'">';
	

currentPageBar();



	if($offset>0)
        echo '<input type="image" src="pictures/previous.jpg" onClick="javascript:self.setbrowserprev(); submit;">';
		//echo '<img src="pictures/previous.jpg" onClick="javascript:self.setbrowserprev(); submit();">';
	
	echo "&nbsp;&nbsp;&nbsp;";

navigationBarPOST();

	echo "&nbsp;&nbsp;&nbsp;";

	if( ($count%$nbMAX==0)&&($count>0)&&($count>$offset) )
	    echo '<input type="image" src="pictures/next.jpg" onClick="javascript:self.setbrowsernext(); submit;">';
		//echo '<img src="pictures/next.jpg" onClick="javascript:self.setbrowsernext(); submit();">';
	
	echo "</form></center></font>";
	
   //free the resources.
   //OCIFreeStatement($stmt);

   
//Pour l'affichage fichier plat par la methode POST
$css="text-decoration:underline; color:black; font-size:15; text-align:center; background-color:transparent; padding:5px border-width:0px;border-style:none;border-color:blue";
print '<form name="formu" action="FLATexport-ISH.php" method="POST">';
	//print '<form Method="POST" Action="FLATexport-ISH.php" name="formulaire" >';
	if(isset($option))
		print '<input type="hidden" name="option" value="'.$option.'">';
	if(isset($species))
		print '<input type="hidden" name="species" value="'.$species.'">';
	if(isset($_POST["selectediddev"]))
		print '<input type="hidden" name="selectediddev" value="'.$_POST["selectediddev"].'">';
	if(isset($_POST["mutant"]))
		print '<input type="hidden" name="mutant" value="'.$_POST["mutant"].'">';
	if(isset($_POST["target"]))
		{
		print '<input type="hidden" name="target" value="'.$_POST["target"].'">';
		}
	if(isset($_POST["amputation"]))
		print '<input type="hidden" name="amputation" value="'.$_POST["amputation"].'">';
	if(isset($_POST["idanat"]))
		print '<input type="hidden" name="idanat" value="'.$_POST["idanat"].'">';

if(isset($_POST["notidanat"]))
		print '<input type="hidden" name="notidanat" value="'.$_POST["notidanat"].'">';

if(isset($_POST["Order"]))
		print '<input type="hidden" name="Order" value="'.$_POST["Order"].'">';
	if(isset($_POST["BOOLmut"]))
		print '<input type="hidden" name="BOOLmut" value="'.$_POST["BOOLmut"].'">';
	if(isset($_POST["BOOLtarg"]))
		print '<input type="hidden" name="BOOLtarg" value="'.$_POST["BOOLtarg"].'">';
	if(isset($_POST["BOOLanat"]))
		print '<input type="hidden" name="BOOLanat" value="'.$_POST["BOOLanat"].'">';
	if(isset($_POST["xref"]))
		print '<input type="hidden" name="xref" value="'.$_POST["xref"].'">';
	if(isset($_POST["MOLtype"]))
		print '<input type="hidden" name="MOLtype" value="'.$_POST["MOLtype"].'">';
	if(isset($_POST["author"]))
		print '<input type="hidden" name="author" value="'.$_POST["author"].'">';
	if(isset($_POST["annotator"]))
		print '<input type="hidden" name="annotator" value="'.$_POST["annotator"].'">';
	if(isset($_POST["pmid"]))
		print '<input type="hidden" name="pmid" value="'.$_POST["pmid"].'">';

	if(isset($_POST["only"]))
		print '<input type="hidden" name="only" value="'.$_POST["only"].'">';
	if(isset($_POST["BOOLmanip"]))
		print '<input type="hidden" name="BOOLmanip" value="'.$_POST["BOOLmanip"].'">';
	if(isset($tabfate))
		print '<input type="hidden" name="fate" value="'.$tabfatelist.'">';

	if(isset($tabnotfate))
		print '<input type="hidden" name="notfate" value="'.$tabnot