<?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");
//Title before frames_header
print '<title>ANISEED v3.0- Anatomy</title>';

    include("frames_header.php");
?>

<?php
    $id=$_GET["idanat"];
	
	if(! is_numeric($id)){
	    Print "Error: missing parameter";
		include("frames_footer.php");
		return;
	}

	$requete="SELECT \"DEV_STAGE_ID\",\"SPECIES\" from \"ANAT_ENTITY\" where \"ANAT_ID\"='$id'";
	$stmt=pg_query($c,$requete);
	$row=pg_fetch_array($stmt);
	$species=$row["SPECIES"];
	$stage=$row["DEV_STAGE_ID"]



?>
  <link rel="stylesheet" type="text/css" media="screen" href="ongletv1.css" title="Version 1" />
<!-- Header pour l'onglet -->
<div id="header">
  <ul>
    <li><a href="anatomy.php?species=<?print $species;?>&dev=<?print $stage;?>&region=<?print $id;?>">Anatomical dictionary</a></li>
    <li><a onclick="this.href='short_hierarchy.php?region=<? print $id;?>&dev=<?print $stage;?>'" href="">Anatomical territory summary card</a></li>
    <li><a onclick="this.href='insitu-result.php?BOOLanat=1&xref=2&idanat=<?print $id;?>:'" href="">In situ</a></li>

    <!--<li><a href="fates.php?idanat=<?print $id;?>">Fate</a></li>-->
    <li><a href="lineage.php?idanat=<?print $id?>">Lineage</a></li>

    <!--<li><a onclick="this.href='insitu-result.php?BOOLanat=1&xref=2&idanat=<?print $id;?>:'" href="#">InSitu data</a></li>-->

    <!--<li><a href="position.php?idanat=<?print $id?>">Biometry</a></li>-->
    <li id="current"><a href="">Induction</a></li>

  </ul>
</div>
<!-- EOF Onglet -->
<br><br><br>
<?

	
    $dev="";
	print "<center>";

	
	$requete="select B.\"NAME\" as \"DEV\", A.\"NAME\", A.\"DEV_STAGE_ID\" from \"ANAT_ENTITY\" A, \"DEV_STAGE\" B where A.\"ANAT_ID\"='$id' and A.\"DEV_STAGE_ID\"=B.\"DEV_STAGE_ID\"";
    $stmt = pg_query($c,$requete);
	if ($row=pg_fetch_array($stmt)){
	    $dev=$row["DEV_STAGE_ID"];
	    print "<font color=\"#D64242\" size=\"3\"><b>".$row["NAME"]." &nbsp;(".$row["DEV"].")</b></font><br><br>";

	    $cellname=$row["NAME"];
	}

	
	
//////////////////////////////////////Competence//////////////////////////////////////////////
	print '<table width="99%" border="0" cellspacing="0" cellpadding="0">';
	print '<tr align="center"><td><b>Competence</b></td></tr><tr><td>&nbsp;</td></tr>';
	$requete="SELECT \"COMPETENCE\" FROM \"COMPETENCE\" WHERE \"CELL\"=".$id;
    $stmt = pg_query($c,$requete);
	$count=0;
	while ($row=pg_fetch_array($stmt)){
	    print "<tr align=\"center\"><td><font size=\"2\"><b>".$row["COMPETENCE"]."</b></font></td></tr>";
	     print "<tr align=\"center\"><td><hr size=\"1\"></td></tr>";
		++$count;
	}
	print '</table>';
	if($count==0)
	    print "<strong>No match</strong>";
///////////////////////////////////////////////////////////////////////////////////////	
	
	
	print '<br><br><br>';
//////////////////////////////////////Inductor//////////////////////////////////////////////
	print '<table width="99%" border="0" cellspacing="0" cellpadding="0">';
	print '<tr align="center"><td><font color="#456898" size="2"><b>Cell(s) inducing '.$cellname.'</b></font></td><td><font color="#456898" size="2"><b>&nbsp;Molecule</b></font></td><td><font color="#456898" size="2"><b>&nbsp;Default fate of '.$cellname.'</b></font></td><td ><font color="#456898" size="2"><b>&nbsp;Induced fate of '.$cellname.'</b></font></td><td><font color="#456898" size="2"><b>&nbsp;Comments</b></font></td></tr>';
	$requete="SELECT b.\"NAME\", a.\"INDUCTION_ID\", a.\"INDUCTOR_ID\", a.\"DEFAULT_FATE\", a.\"COMMENTS\" FROM \"INDUCTION\" a, \"ANAT_ENTITY\" b WHERE (a.\"INDUCTOR_ID\"=b.\"ANAT_ID\") and (a.\"INDUCED_ID\"=".$id.")";
    $stmt = pg_query($c,$requete);
	$count=0;
	$allid="";
	while ($row=pg_fetch_array($stmt)){
	    
		$tmpid=$row["INDUCTION_ID"];
		$allid.=$tmpid.",";
		
		print "<tr align=\"center\"><td><a href=\"short_hierarchy.php?region=".$row["INDUCTOR_ID"]."&dev=$dev\"><font size=\"2\"><b>".$row["NAME"]."</b></font></a></td>   <td align=\"left\">";
		
		//molecules involved
		$requete="SELECT \"NAME\", \"TYPE\" FROM \"INDUCTION_MOL\", \"GENE\" WHERE \"GENE_ID\"=\"MOL_ID\" and \"INDUCTION_ID\"='$tmpid' order by \"TYPE\"";
		$stmt2 = pg_query($c,$requete);
		
		while ($row2=pg_fetch_array($stmt2)){

			///// PATCH pour le gene card

			$requete3="
			select \"GENE_CLUSTER_ID\" from \"GENE_CONCEPT\" where \"GENE_MODEL_ID\"=(
			SELECT \"GENE_ID\" from \"GENE\" where \"NAME\"='".$row2["NAME"]."')";
			$stmt3=pg_query($c,$requete3);
			$row3=pg_fetch_array($stmt3);

			$gc=$row3["GENE_CLUSTER_ID"];
			$gc=str_replace("cluster","aniseedV3_",$gc);
			
			print "<a href=\"gene-card.php?clusterid=".$row3["GENE_CLUSTER_ID"]."\"><font size=\"2\"><b>$gc</b></font></a><font size=\"2\"><b>&nbsp;(".$row2["TYPE"].")</b></font><BR>";



			//print "<a href=\"molecule-gene.php?name=".$row2["NAME"]."\"><font size=\"2\"><b>".$row2["NAME"]."</b></font></a><font size=\"2\"><b>&nbsp;(".$row2["TYPE"].")</b></font><BR>";





		}
		
		print "&nbsp;</td><td><font size=\"2\"><b>&nbsp;&nbsp;&nbsp;".$row["DEFAULT_FATE"]."&nbsp;&nbsp;&nbsp;</b></font></td><td >";
		
		//induced fates
		$requete="SELECT \"FATE\" FROM \"INDUCTION_FATE\" WHERE \"INDUCTION_ID\"=".$tmpid." order by \"FATE\"";
		$stmt2 = pg_query($c,$requete);
		while ($row2=pg_fetch_array($stmt2)){
		    print "<font size=\"2\"><b>".$row2["FATE"]."</b></font><BR>";
		}
		
			
		print "</td><td align=\"right\" width=\"33%\"><font size=\"2\"><b>".$row["COMMENTS"]."</b></font></td>  </tr>";
		
		
		print "<tr align=\"center\"><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>";
		++$count;
	}
	print '</table>';
	
	if($count==0)
	    print "<strong>No match</strong>";
	else{
	    //print "References: ";
		$requete="SELECT \"TITLE\",\"PUBMED_ID\",\"PAPER\",\"AUTHORS\",\"COMMENTS\",\"URL\" FROM \"REFERENCE\" WHERE \"BIO_ID\" in (".$tmpid.")";
		$stmt = pg_query($c,$requete);
		$count=0;
		print "</center>";
		while ($row=pg_fetch_array($stmt)){
			++$count;
			echo ('<br><u>References:</u> &nbsp;');
			echo ( "<a target=\"blank\" href=\"http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=PubMed&cmd=Retrieve&list_uids=".$row["PUBMED_ID"]."&dopt=Abstract\">".$row["TITLE"]."</a>  &nbsp; &nbsp;<strong>".$row["AUTHORS"]."</strong>    &nbsp; &nbsp;".$row["PAPER"] );
			echo ( "<br><a target=\"blank\" href=\"".$row["URL"]."\">".$row["URL"]."</a>" );
			echo ( '<br>'.$row["COMMENTS"]);
		}
		print "<center>";
	}
///////////////////////////////////////////////////////////////////////////////////////


	print '<br><br><br>';
//////////////////////////////////////Induced cells//////////////////////////////////////////////
	print '<table width="99%" border="0" cellspacing="0" cellpadding="0">';
	print '<tr align="center"><td><font color="#456898" size="2"><b>CCell(s) induced by '.$cellname.'</b></font></td><td><font color="#456898" size="2"><b>Molecule</b></font></td><td><font color="#456898" size="2"><b>Default fate</b></font></td><td><font color="#456898" size="2"><b>Induced fate</b></font></td><td ><font color="#456898" size="2"><b>Comments</b></font></td></tr>';
	$requete="SELECT b.\"NAME\", a.\"INDUCTION_ID\", a.\"INDUCED_ID\", a.\"DEFAULT_FATE\", a.\"COMMENTS\" FROM \"INDUCTION\" a, \"ANAT_ENTITY\" b WHERE (a.\"INDUCED_ID\"=b.\"ANAT_ID\") and (a.\"INDUCTOR_ID\"=".$id.")";
    $stmt = pg_query($c,$requete);
	$count=0;
	$allid="";
	while ($row=pg_fetch_array($stmt)){
	    
		$tmpid=$row["INDUCTION_ID"];
		$allid.=$tmpid.",";
		
		print "<tr align=\"center\"><td><a href=\"short_hierarchy.php?region=".$row["INDUCED_ID"]."&dev=$dev\"><font size=\"2\"><b>".$row["NAME"]."</b></font></a></td>   <td>";
		
		//molecules involved
		$requete="SELECT \"NAME\", \"TYPE\" FROM \"INDUCTION_MOL\", \"GENE\" WHERE \"GENE_ID\"=\"MOL_ID\" and \"INDUCTION_ID\"=".$tmpid." order by \"TYPE\"";
		$stmt2 = pg_query($c,$requete);
		while ($row2=pg_fetch_array($stmt2)){
			print "<a href=\"molecule-gene.php?name=".$row2["NAME"]."\"><font size=\"2\"><b>".$row2["NAME"]."</b></font></a><font size=\"2\"><b>(".$row2["TYPE"].")</b></font><BR>";
		}
		
		print "&nbsp;</td><td><font size=\"2\"><b>".$row["DEFAULT_FATE"]."</b></font></td><td>";
		
		//induced fates
		$requete="SELECT \"FATE\" FROM \"INDUCTION_FATE\" WHERE \"INDUCTION_ID\"=".$tmpid." order by \"FATE\"";
		$stmt2 = pg_query($c,$requete);
		while ($row2=pg_fetch_array($stmt2)){
		    print "<font size=\"2\"><b>".$row2["FATE"]."</b></font><BR>";
		}
		
			
		print "&nbsp;</td><td width=\"33%\"><font size=\"2\"><b>".$row["COMMENTS"]."</b></font></td>  </tr>";
		
		
		print "<tr align=\"center\"><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>";
		++$count;
	}
	print '</table>';
	
	if($count==0)
	    print "<strong>No match</strong>";
	else{
	    //print "References: ";
		$requete="SELECT \"TITLE\",\"PUBMED_ID\",\"PAPER\",\"AUTHORS\",\"COMMENTS\",\"URL\" FROM \"REFERENCE\" WHERE \"BIO_ID\"=$id";
		$stmt = pg_query($c,$requete);
		$count=0;
		while ($row=pg_fetch_array($stmt)){
			++$count;
			echo ('<br>References: &nbsp;');
			echo ( "<a target=\"blank\" href=\"http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=PubMed&cmd=Retrieve&list_uids=".$row["PUBMED_ID"]."&dopt=Abstract\">".$row["TITLE"]."</a>  &nbsp; &nbsp;<strong>".$row["AUTHORS"]."</strong>    &nbsp; &nbsp;".$row["PAPER"] );
			echo ( "<br><a target=\"blank\" href=\"".$row["URL"]."\">".$row["URL"]."</a>" );
			echo ( '<br>'.$row["COMMENTS"].'<br><br>' );
			echo ('</td></tr>');
		}
	}
///////////////////////////////////////////////////////////////////////////////////////

	print "</center>";
	
?>

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