<html>
<head>
<title>ANISEED - Fate result (Ciona intestinalis, Halocynthia roretzi)</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="This page is the result of a search by Ciona intestinalis or Halocynthia roretzi a fate. For more detail, contact aniseed@ibdm.univ-mrs.fr">
<meta name="keywords" content="Ciona intestinalis, Halocynthia roretzi, tunicate, ascidian database, ciona intestinalis database, nervous system, mesenchyme, endoderm, muscle, epiderme, notochord">
<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/>.

*/
//connection
include("connection.php");
include("frames_header.php");
?>


<?php
	
	
	$species="";
	if(isset($_POST["species"]))
	    $species=$_POST["species"];
	
	$devstage=array();
	if(isset($_POST["devstage"]))
	    $devstage=$_POST["devstage"];
	//print_r($devstage);

	$fate=array();
	if(isset($_POST["fate"]))
	    $fate=$_POST["fate"];
	
	$celllist="";
	if(isset($_POST["celllist"]))
		$celllist=$_POST["celllist"];

	

	$and="";
	if(isset($_POST["and"]))
		$and=$_POST["and"];
	
	$only="";
	if(isset($_POST["only"]))
		$only=$_POST["only"];
	
	if(count($fate)<=0){
	    print "<center>Error: please select fates</center>";
		include("frames_footer.php");
		return;
	}

	if (isset($_POST["notin"]))
		$notin=$_POST["notin"];

	
	
	print "<strong>Query: </strong>";
	if ($notin=='y') print 'NOT ( ';
	for($a=0;$a<count($fate);++$a)
	    print $fate[$a]." / ";
	if ($notin=='y') print ' ) ';
    print "<br><center>";
	
	
	if(strlen($celllist)>0)
		print "<center><H2><font color=\"#FF6600\">Refining subset mode</font></H2></center>";
				
	
	$fatelist=join("','",$fate);		
//	$requete="SELECT a.anat_id, b.name, b.species, b.dev_stage_id, c.name as dev FROM CIONA_DESIGN.fate a, CIONA_DESIGN.anat_entity b, CIONA_DESIGN.dev_stage c WHERE a.keywords in ('".$fatelist."') and (a.anat_id=b.anat_id) and (b.dev_stage_id=c.dev_stage_id) ";


if ($notin!='y')	
{
	
    if($only=="yes"){
	    if($and=="or")
            $requete="SELECT distinct a.\"ANAT_ID\", b.\"NAME\", b.\"SPECIES\", b.\"DEV_STAGE_ID\", c.\"NAME\" as dev,c.\"DEV_PERCENT\" FROM \"FATE\" a, \"ANAT_ENTITY\" b, \"DEV_STAGE\" c WHERE a.\"ANAT_ID\" in( select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" in('".$fatelist."') EXCEPT select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" not in('".$fatelist."') ) and (a.\"ANAT_ID\"=b.\"ANAT_ID\") and (b.\"DEV_STAGE_ID\"=c.\"DEV_STAGE_ID\") ";
	        ////$requete="SELECT unique a.anat_id, b.name, b.species, b.dev_stage_id, c.name as dev FROM CIONA_DESIGN.fate a, CIONA_DESIGN.anat_entity b, CIONA_DESIGN.dev_stage c WHERE a.keywords in ('".$fatelist."') and not exists(  SELECT z.anat_id from CIONA_DESIGN.fate z where (z.keywords not in ('".$fatelist."')) and (z.anat_id = a.anat_id)  ) and (a.anat_id=b.anat_id) and (b.dev_stage_id=c.dev_stage_id) ";
			//$requete="select anat_id from ciona_design.fate where keywords in('".$tabfate."') MINUS select anat_id from ciona_design.fate where keywords not in('".$tabfate."')";
	    if($and=="and"){
		
	        //$requete="SELECT unique a.anat_id, b.name, b.species, b.dev_stage_id, c.name as dev FROM CIONA_DESIGN.fate a, CIONA_DESIGN.anat_entity b, CIONA_DESIGN.dev_stage c WHERE not exists(  SELECT z.anat_id from CIONA_DESIGN.fate z where (z.keywords not in ('".$fatelist."')) and (z.anat_id = a.anat_id)  ) and (a.anat_id=b.anat_id) and (b.dev_stage_id=c.dev_stage_id) ";
            $requete="SELECT distinct a.\"ANAT_ID\", b.\"NAME\", b.\"SPECIES\", b.\"DEV_STAGE_ID\", c.\"NAME\" as dev,c.\"DEV_PERCENT\" FROM \"FATE\" a, \"ANAT_ENTITY\" b, \"DEV_STAGE\" c WHERE (a.\"ANAT_ID\"=b.\"ANAT_ID\") and (b.\"DEV_STAGE_ID\"=c.\"DEV_STAGE_ID\") and   a.\"ANAT_ID\" in( (select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" in('".$fatelist."') EXCEPT select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" not in('".$fatelist."')) ";
			for ($a=0; $a<count($fate); ++$a)
			    $requete.= "intersect select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\"='$fate[$a]' ";
			    //$requete.= " and (exists (select x.anat_id from ciona_design.fate x where (x.keywords='".$fate[$a]."')and(a.anat_id=x.anat_id) ))";
		
		    $requete.=")";
		}
	}else{
	    if($and=="or")
	        $requete="SELECT distinct a.\"ANAT_ID\", b.\"NAME\", b.\"SPECIES\", b.\"DEV_STAGE_ID\", c.\"NAME\" as dev,c.\"DEV_PERCENT\" FROM \"FATE\" a, \"ANAT_ENTITY\" b, \"DEV_STAGE\" c WHERE a.\"KEYWORDS\" in ('".$fatelist."') and (a.\"ANAT_ID\"=b.\"ANAT_ID\") and (b.\"DEV_STAGE_ID\"=c.\"DEV_STAGE_ID\") ";
	    if($and=="and"){
            $requete="SELECT distinct a.\"ANAT_ID\", b.\"NAME\", b.\"SPECIES\", b.\"DEV_STAGE_ID\", c.\"NAME\" as dev,c.\"DEV_PERCENT\" FROM \"FATE\" a, \"ANAT_ENTITY\" b, \"DEV_STAGE\" c WHERE (a.\"ANAT_ID\"=b.\"ANAT_ID\") and (b.\"DEV_STAGE_ID\"=c.\"DEV_STAGE_ID\")    and   a.\"ANAT_ID\" in( select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" in('".$fatelist."') ";
			for ($a=0; $a<count($fate); ++$a)
			    $requete.= "intersect select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\"='$fate[$a]' ";
			$requete.=")";
		/*
	        $requete="SELECT unique a.anat_id, b.name, b.species, b.dev_stage_id, c.name as dev FROM CIONA_DESIGN.fate a, CIONA_DESIGN.anat_entity b, CIONA_DESIGN.dev_stage c WHERE (a.anat_id=b.anat_id) and (b.dev_stage_id=c.dev_stage_id) ";
            for ($a=0; $a<count($fate); ++$a)
			    $requete.= " and (exists (select z.anat_id from ciona_design.fate z where (z.keywords='".$fate[$a]."')and(a.anat_id=z.anat_id) ))";
		*/
		}
	}
	
	
	
	if( strlen($species)>1 )
		$requete.=" AND (b.\"SPECIES\" ='$species') ";
	
	if( count($devstage)>0 ){
	    $devstage=join("','",$devstage);
	//print_r($devstage);
		$requete.=" AND (b.\"DEV_STAGE_ID\" in ('".$devstage."')) ";
	}
	
	if( strlen($celllist)>0){
		$celllist = substr($celllist, 0, strlen($celllist)-1);
		$celllist = ereg_replace(":","','",$celllist);

		$requete.=" AND (a.\"ANAT_ID\" in('".$celllist."'))";
	}
	
	//$requete.="order by b.\"DEV_STAGE_ID\"";
	$requete.="order by c.\"DEV_PERCENT\"";

}
else
{

//On cherche les not fate

	
    if($only=="yes"){

	    if($and=="or")
            $requete="(SELECT distinct a.\"ANAT_ID\", b.\"NAME\", b.\"SPECIES\", b.\"DEV_STAGE_ID\", c.\"NAME\" as dev,c.\"DEV_PERCENT\" FROM \"FATE\" a, \"ANAT_ENTITY\" b, \"DEV_STAGE\" c WHERE a.\"ANAT_ID\" in( select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" not in('".$fatelist."') EXCEPT select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" in('".$fatelist."') ) and (a.\"ANAT_ID\"=b.\"ANAT_ID\") and (b.\"DEV_STAGE_ID\"=c.\"DEV_STAGE_ID\") ";
	       
	    if($and=="and"){
		
	        
            $requete="(SELECT distinct a.\"ANAT_ID\", b.\"NAME\", b.\"SPECIES\", b.\"DEV_STAGE_ID\", c.\"NAME\" as dev,c.\"DEV_PERCENT\" FROM \"FATE\" a, \"ANAT_ENTITY\" b, \"DEV_STAGE\" c WHERE (a.\"ANAT_ID\"=b.\"ANAT_ID\") and (b.\"DEV_STAGE_ID\"=c.\"DEV_STAGE_ID\") and   a.\"ANAT_ID\" in( (select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" not in('".$fatelist."') EXCEPT select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" in('".$fatelist."')) ";
			for ($a=0; $a<count($fate); ++$a)
			    $requete.= "intersect select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\"<>'$fate[$a]' ";
			    
		
		    $requete.=")";
		}
	}else{
	    if($and=="or")
	        $requete="(SELECT distinct a.\"ANAT_ID\", b.\"NAME\", b.\"SPECIES\", b.\"DEV_STAGE_ID\", c.\"NAME\" as dev,c.\"DEV_PERCENT\" FROM \"FATE\" a, \"ANAT_ENTITY\" b, \"DEV_STAGE\" c WHERE a.\"KEYWORDS\" not in ('".$fatelist."') and (a.\"ANAT_ID\"=b.\"ANAT_ID\") and (b.\"DEV_STAGE_ID\"=c.\"DEV_STAGE_ID\") ";
	    if($and=="and"){
            $requete="(SELECT distinct a.\"ANAT_ID\", b.\"NAME\", b.\"SPECIES\", b.\"DEV_STAGE_ID\", c.\"NAME\" as dev,c.\"DEV_PERCENT\" FROM \"FATE\" a, \"ANAT_ENTITY\" b, \"DEV_STAGE\" c WHERE (a.\"ANAT_ID\"=b.\"ANAT_ID\") and (b.\"DEV_STAGE_ID\"=c.\"DEV_STAGE_ID\")    and   a.\"ANAT_ID\" in( select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" not in('".$fatelist."') ";
			for ($a=0; $a<count($fate); ++$a)
			    $requete.= "intersect select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\"='$fate[$a]' ";
			$requete.=")";
		}
	}
	
	
	
	if( strlen($species)>1 )
		$requete.=" AND (b.\"SPECIES\" ='$species') ";
	
	if( count($devstage)>0 ){
	    $devstage=join("','",$devstage);

		$requete.=" AND (b.\"DEV_STAGE_ID\" in ('".$devstage."')) ";
	}
	
	if( strlen($celllist)>0){
		$celllist = substr($celllist, 0, strlen($celllist)-1);
		$celllist = ereg_replace(":","','",$celllist);

		$requete.=" AND (a.\"ANAT_ID\" in('".$celllist."'))";
	}
	
	//$requete.="order by b.\"DEV_STAGE_ID\")";
	$requete.="order by c.\"DEV_PERCENT\")";



//LE EXCEPT


 if($only=="yes"){
	    if($and=="or")
            $requete.=" EXCEPT (SELECT distinct a.\"ANAT_ID\", b.\"NAME\", b.\"SPECIES\", b.\"DEV_STAGE_ID\", c.\"NAME\" as dev FROM \"FATE\" a, \"ANAT_ENTITY\" b, \"DEV_STAGE\" c WHERE a.\"ANAT_ID\" in( select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" in('".$fatelist."') EXCEPT select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" not in('".$fatelist."') ) and (a.\"ANAT_ID\"=b.\"ANAT_ID\") and (b.\"DEV_STAGE_ID\"=c.\"DEV_STAGE_ID\") ";
	       
	    if($and=="and"){
		
	        
            $requete.=" EXCEPT (SELECT distinct a.\"ANAT_ID\", b.\"NAME\", b.\"SPECIES\", b.\"DEV_STAGE_ID\", c.\"NAME\" as dev FROM \"FATE\" a, \"ANAT_ENTITY\" b, \"DEV_STAGE\" c WHERE (a.\"ANAT_ID\"=b.\"ANAT_ID\") and (b.\"DEV_STAGE_ID\"=c.\"DEV_STAGE_ID\") and   a.\"ANAT_ID\" in( (select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" in('".$fatelist."') EXCEPT select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" not in('".$fatelist."')) ";
			for ($a=0; $a<count($fate); ++$a)
			    $requete.= "intersect select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\"='$fate[$a]' ";
			    
		
		    $requete.=")";
		}
	}else{
	    if($and=="or")
	        $requete.=" EXCEPT (SELECT distinct a.\"ANAT_ID\", b.\"NAME\", b.\"SPECIES\", b.\"DEV_STAGE_ID\", c.\"NAME\" as dev FROM \"FATE\" a, \"ANAT_ENTITY\" b, \"DEV_STAGE\" c WHERE a.\"KEYWORDS\" in ('".$fatelist."') and (a.\"ANAT_ID\"=b.\"ANAT_ID\") and (b.\"DEV_STAGE_ID\"=c.\"DEV_STAGE_ID\") ";
	    if($and=="and"){
            $requete.=" EXCEPT (SELECT distinct a.\"ANAT_ID\", b.\"NAME\", b.\"SPECIES\", b.\"DEV_STAGE_ID\", c.\"NAME\" as dev FROM \"FATE\" a, \"ANAT_ENTITY\" b, \"DEV_STAGE\" c WHERE (a.\"ANAT_ID\"=b.\"ANAT_ID\") and (b.\"DEV_STAGE_ID\"=c.\"DEV_STAGE_ID\")    and   a.\"ANAT_ID\" in( select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\" in('".$fatelist."') ";
			for ($a=0; $a<count($fate); ++$a)
			    $requete.= "intersect select \"ANAT_ID\" from \"FATE\" where \"KEYWORDS\"='$fate[$a]' ";
			$requete.=")";
		}
	}
	
	
	
	if( strlen($species)>1 )
		$requete.=" AND (b.\"SPECIES\" ='$species') ";
	
	if( count($devstage)>0 ){
	    //$devstage=join("','",$devstage);
		$requete.=" AND (b.\"DEV_STAGE_ID\" in ('".$devstage."')) ";
	}
	
	if( strlen($celllist)>0){
		//$celllist = substr($celllist, 0, strlen($celllist)-1);
		//$celllist = ereg_replace(":","','",$celllist);

		$requete.=" AND (a.\"ANAT_ID\" in('".$celllist."'))";
	}
	
	//$requete.="order by b.\"DEV_STAGE_ID\")";
	$requete.="order by c.\"DEV_PERCENT\")";


}









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

	//print $requete;

	print "<font color=\"#D64242\" size=\"3\"><b>Matching records:</b></font><br><br>";
	print '<table width="99%" border="0" cellspacing="0" cellpadding="0">';
	print '<tr align="center" valign="middle"><td><font color="#456898" size="2"><b>Anatomical entity</b></font></td><td><font color="#456898" size="2"><b>Developmental stage</b></font></td><td><font color="#456898" size="2"><b>Species</b></font></td></tr>';
	$count=0;
	$celllist="";
	while( $row=pg_fetch_array($stmt) ){
		
		++$count;
		print '<tr align="center" valign="top"><td><hr size="1"></td><td><hr size="1"></td><td><hr size="1"></td></tr>';

		print '<tr align="center" valign="top"> <td><a href="short_hierarchy.php?region='.$row["ANAT_ID"].'&dev='.$row["DEV_STAGE_ID"].'"><font color="#000000" size="-1">'.$row["NAME"].'</font></a></td> <td><font color="#656565" size="-1">'.$row["dev"].'</font></td> <td><font color="#656565" size="-1">'.$row["SPECIES"].'</font></td> </tr>';
		
		if($count>500){
			//OCICancel($stmt);
			pg_cancel_query($c);
			break;
		}
		
	    $celllist.= $row["ANAT_ID"].":";  //liste les cell id pour le rafinage.
		
	}
	print '<tr align="center" valign="top"><td><hr size="1"></td><td><hr size="1"></td><td><hr size="1"></td></tr>';
	print '</table>';
	
	if($count==0)
		print "<br><br><center><h2><strong>No match</strong></h2></center><br><br>";
	else
		print "<br><center>$count result(s)</center><br><br>";

	
	if($count>500)
		print "...<br>More than 500 results has been returned.<br>Please refine your query";
	



	if(substr_count($celllist,":")<1000){
		print '<form name="formulaire3" action="" method="post">';
		print '<input type="hidden" value="'.$celllist.'" name="celllist">';
		print'&nbsp;&nbsp;&nbsp;<input type="image" src="pictures/button-subset.jpg" onClick="javascript: window.document.formulaire3.action= window.document.formulaire3.redirect.value; submit;">';
		
		/*print '<br>
			   <select name="redirect" size="1">
				   <option value="biometry-search.php">Biometry</option>
				   <option value="neighbour-search.php">Neighbours</option>
				   <option value="fate-search.php">Fate</option>
				   <option value="lineage-search.php">Lineage</option>
				   <option value="division-search.php">Cleavage inequality</option>
				   <option value="insitu-search.php">In situ</option>
				   <option value="ID.php">Export ID list</option>
			   </select>';*/
		include("refine_anatomy.php");
			   
		print '</form>';
    }else{print '<font size="-1" color="#999999">Refine mode not available for set > 1000</font>';}



?>
</center>

<?php

    include("frames_footer.php");
?>