<html>
<head>
<title>ANISEED - Results neighbours of a cell (Ciona intestinalis)</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="This page will list the neighbouring territory of a cell you are interested in, thanks to 3D Virtual embryo data. For more information, please contact dauga@ibdm.univ-mrs.fr">
<meta name="keywords" content="Lemaire, Tassy, Daian, Dauga, Sobral, Khoueiry, Aniseed, Ciona intestinalis, neighbouring cell, 3D embryo, Ciona embryo, developmental stage, surface of contact.">
<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");
?>

<center>
<?php
/*
    $and="";
	if( isset($_POST["and"]) )
		$and=$_POST["and"];
*/
	$region=array();
	if( isset($_POST["region"]) ){
	    $region=$_POST["region"];
	}
	
	if(  count($region)<=0  ){
	    print '<center><h2><strong>Please select anatomical parts.</strong></h2></center>';
		include("frames_footer.php");
		return;
	}

	if($_POST["supinf"]==0)
		$supinf=">";
	else
		$supinf="<";

	$surf=$_POST["surf"];
	
	if(  (! is_numeric($surf))or($surf<0)  ){
	    print '<center><h2><strong>Wrong parameter.</strong></h2></center>';
		include("frames_footer.php");
		return;
	}


	if($_POST["supinf2"]==0)
		$supinf2=">";
	else
		$supinf2="<";

	$dist=$_POST["dist"];
	
	if(  (! is_numeric($dist))or($dist<0)  ){
	    print '<center><h2><strong>Wrong parameter.</strong></h2></center>';
		include("frames_footer.php");
		return;
	}


	$species="";
	if(isset($_POST["species"]))
	    $species=$_POST["species"];
	
	$celllist="";
	if(isset($_POST["celllist"]))
		$celllist=$_POST["celllist"];
	
	if(strlen($celllist)>0)
		print "<center><H2><font color=\"#FF6600\">Refining subset mode</font></H2></center>";
	
	
	$requete="( ";
	for($i=0;$i<count($region);++$i){
	    $anat_id=$region[$i];
		//print "=>>"+$anat_id;
	    $requete.="(SELECT \"CELL_A\", \"CELL_B\", \"CONTACT\", \"DISTANCE\" FROM \"NEIGHBOR\" where ((\"CELL_A\"=$anat_id) or (\"CELL_B\"=$anat_id))and(\"CONTACT\" $supinf= $surf)and(\"DISTANCE\" $supinf2= $dist))";
	    
		if($i<count($region)-1)
			//if($and=="n")
				$requete.=" UNION ";
			/*
			else
				$requete.=" INTERSECT ";
			*/
	}
    $requete.=" )";

//print $requete;

/*
	if( strlen($celllist)>0){
	print $celllist;
		$celllist = substr($celllist, 0, strlen($celllist)-1);
		$celllist = ereg_replace(":","','",$celllist);

		$requete.="intersect select cell_a, cell_b, contact, distance FROM CIONA_DESIGN.neighbor where cell_a in('".$celllist."') or cell_b in('".$celllist."')";
	}
print "$requete";
*/
	
	

	$stmt = pg_query($c,$requete);
	
	
    $tabcelllist=array();
	if( strlen($celllist)>0){
	    //print $celllist;
		$celllist = substr($celllist, 0, strlen($celllist)-1);
		$tabcelllist=split(":",$celllist);
	}
	
	
	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>neighbour</b></font></td><td><font color="#456898" size="2"><b>Distance (&micro;)</b></font></td><td><font color="#456898" size="2"><b>Contact (&micro;&sup2;)</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) ){
	    
	    $cell1=$row["CELL_A"];
		$cell2=$row["CELL_B"];
        if(in_array($cell1,$region)){
		    $cell1=$row["CELL_B"];
			$cell2=$row["CELL_A"];
		}

        if((count($tabcelllist)>0)and(! in_array($cell1,$tabcelllist)))
		    continue;

  $requete="SELECT a.\"SPECIES\", a.\"NAME\", a.\"DEV_STAGE_ID\", b.\"NAME\" as \"DEV\" FROM \"ANAT_ENTITY\" a, \"DEV_STAGE\" b where a.\"ANAT_ID\"='".$cell2."' and a.\"DEV_STAGE_ID\"=b.\"DEV_STAGE_ID\"";
		$stmt2 = pg_query($c,$requete);
		if( $row20=pg_fetch_array($stmt2) ){
            print '<tr align="center" 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><td><hr size="1"></td></tr>';
			print '<tr align="center" valign="top"> <td><a href="short_hierarchy.php?region='.$cell2.'&dev='.$row20["DEV_STAGE_ID"].'"><font color="#000000" size="-1">'.$row20["NAME"].'</font></a></td>';
		}
        $requete="SELECT \"NAME\", \"DEV_STAGE_ID\" FROM \"ANAT_ENTITY\" where \"ANAT_ID\"='".$cell1."'";
		$stmt2 = pg_query($c,$requete);
		if( $row2=pg_fetch_array($stmt2)){
		    ++$count;
            print '<td><a href="short_hierarchy.php?region='.$cell1.'&dev='.$row2["DEV_STAGE_ID"].'"><font color="#000000" size="-1">'.$row2["NAME"].'</font></a></td> <td><font color="#656565" size="-1">'.$row["DISTANCE"].'</font></td><td><font color="#656565" size="-1">'.$row["CONTACT"].'</font></td><td><font color="#656565" size="-1">'.$row20["DEV"].'</font></td> <td><font color="#656565" size="-1">'.$row20["SPECIES"].'</font></td> </tr>';
		}

/*
        $requete="SELECT \"NAME\", \"DEV_STAGE_ID\" FROM \"ANAT_ENTITY\" where \"ANAT_ID\"='".$cell1."'";
		$stmt2 = pg_query($c,$requete);
		if( $row2=pg_fetch_array($stmt2)){
		    ++$count;
            print '<tr align="center" 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><td><hr size="1"></td></tr>';
            print '<tr align="center" valign="top"> <td><a href="short_hierarchy.php?region='.$cell1.'&dev='.$row2["DEV_STAGE_ID"].'"><font color="#000000" size="-1">'.$row2["NAME"].'</font></a></td>';
		}
		
        $requete="SELECT a.\"SPECIES\", a.\"NAME\", a.\"DEV_STAGE_ID\", b.\"NAME\" as \"DEV\" FROM \"ANAT_ENTITY\" a, \"DEV_STAGE\" b where a.\"ANAT_ID\"='".$cell2."' and a.\"DEV_STAGE_ID\"=b.\"DEV_STAGE_ID\"";
		$stmt2 = pg_query($c,$requete);
		if( $row2=pg_fetch_array($stmt2) ){
			print '<td><a href="short_hierarchy.php?region='.$cell2.'&dev='.$row2["DEV_STAGE_ID"].'"><font color="#000000" size="-1">'.$row2["NAME"].'</font></a></td> <td><font color="#656565" size="-1">'.$row["DISTANCE"].'</font></td><td><font color="#656565" size="-1">'.$row["CONTACT"].'</font></td><td><font color="#656565" size="-1">'.$row2["DEV"].'</font></td> <td><font color="#656565" size="-1">'.$row2["SPECIES"].'</font></td> </tr>';
		}
*/		
		
		
		if($count>500){
			//OCICancel($stmt);
			pg_cancel_query($c);
			break;
		}
	    $celllist.= $cell1.":";  //liste les cell id pour le rafinage.
	}
	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><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>';}

print '</center>';



//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-neighbour.php" method="POST">';
$regionlist=implode("@",$region);
print '<input type="hidden" value="'.$regionlist.'" name="regionlist">';
print '<input type="hidden" value="'.$_POST["supinf"].'" name="supinf">';
print '<input type="hidden" value="'.$_POST["surf"].'" name="surf">';
print '<input type="hidden" value="'.$_POST["supinf2"].'" name="supinf2">';
print '<input type="hidden" value="'.$_POST["dist"].'" name="dist">';
print '<input type="hidden" value="'.$_POST["species"].'" name="species">';
print '<input type="hidden" value="'.$_POST["celllist"].'" name="celllist">';

print '<input type="submit" style="'.$css.'" value="Display entry in raw text format">';
print '</form>';
//Fin


?>


<?php
    include("frames_footer.php");
?>