<?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 - Molecule phylogeny</title>';

include("frames_header.php");
?>


<?php
    

	
    $name=$_GET["name"];
	$id=$_GET["id"];

$requete="SELECT \"NAME\",\"SPECIES\" from \"MOL_ENTITY\" where \"MOL_ID\"='$id'";
$stmt=pg_query($c,$requete);
$row=pg_fetch_array($stmt);
$species=$row["SPECIES"];

	
$clustid=$id;

if ($row["NAME"]{0}=="K") //KYOTO
{
//AJOUT POUR L'ABSTRACT de KYOTO

$qu="SELECT \"NAME\" from \"MOL_ENTITY\" where \"MOL_ID\"='$id'";
$st=pg_query($c,$qu);
$ro=pg_fetch_array($st);

$temp=explode(".",$ro["NAME"]);
$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);

	$clustid=$ro["MOL_ID"];
		//print "<tr valign=\"top\" align=\"left\"><td><font color=\"#656565\" size=\"-1\"><b>Corresponding cluster: </b></font></td><td>";
		//print "<a href=\"ESTcluster.php?name=".$ro["MOL_ID"]."\"><font color=\"#000000\" size=\"-1\">".$ro["MOL_ID"]."</font></a></td></tr>";
//FIN AJOUT
}

if ($row["NAME"]{0}=="E")
	{
	//POUR ENSEMBL

	$qu="SELECT \"ABSTRACT_ID\" from \"TRANSCRIPT\" where \"TRANSCRIPT_ID\"='$id'";
	$st=pg_query($c,$qu);
	$ro=pg_fetch_array($st);

 	$clustid=$ro["ABSTRACT_ID"];
//	print "<tr valign=\"top\" align=\"left\"><td><font color=\"#656565\" size=\"-1\"><b>Corresponding cluster: </b></font></td><td>";
//	print "<a href=\"ESTcluster.php?name=".$ro["ABSTRACT_ID"]."\"><font color=\"#000000\" size=\"-1\">".$ro["ABSTRACT_ID"]."</font></a></td></tr>";
	}



?>

<!-- Header pour l'onglet -->
<link rel="stylesheet" type="text/css" media="screen" href="ongletv1.css" title="Version 1" />
<div id="header">
  <ul>
    <li><a href="molecule-gene.php?name=<?print $name;?>">Features</a></li>
    <li><a href="molecule-sequence.php?id=<? print $id; ?>">Sequence</a></li>
    <li><a href="ESTcluster.php?name=<? print $clustid; ?>&base=<?print $id;?>">Cluster</a></li>
    <li id="current"><a href="#">Paralog</a></li>
    <li><a href="est-expression.php?name=<?print $clustid;?>&base=<? print $id; ?>&species=<?print $species;?>">EST count</a></li>
    <li><a href="insitu-result.php?target=<? print $name;?>&MOLtype=2&Order=DEV_STAGE_ID">InSitu data</a></li>
    <li><a href="#">Molecular tool</a></li>
    <li><a href="#">Microarray probe</a></li>
    <li><a href="FLATexport-molecule-gene.php?name=<? print $name; ?>">Flat file</a></li>

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


<?


    print "<br><br><font color=\"#D64242\" size=\"3\"><b>Paralog prediction for $name</b></font>";
	
	if( (strlen($name)<=0)or(strlen($id)<=0) ){
    	print "<br><br><center><h2><strong>No match</strong></h2></center><br><br>";
	}else{
        print "<br><br><center>";
        print "<table width=\"99%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
	    print "<tr align=\"center\" valign=\"middle\"><td><font color=\"#456898\" size=\"2\"><b>Paralog name</b></font></td><td><font color=\"#456898\" size=\"2\"><b>Score</b></font></td></tr>";
		
		
	    $requete="select * from \"PHYLOGENY\" where \"MOL_ID\"=$id and \"PARALOG\" is not NULL order by \"SPECIES\", \"SCORE1\" DESC";
    	$stmt = pg_query($c,$requete);
		$count=0;
    	while($row=pg_fetch_array($stmt)){
		    ++$count;
		    
		    print "<tr valign=\"top\" align=\"center\"> <td><a href=\"molecule-gene.php?name=".$row["PARALOG"]."\">".$row["PARALOG"]."</a></td><td>".$row["SCORE2"]."%</td></tr>";
		    print '<tr valign="top"><td><hr size="1"></td><td><hr size="1"></td></tr>';
		}
		if($count==0){print "</table><br><center>NONE</center>";}
		else{
    		print "<tr valign=\"top\" align=\"center\"> <td><a href=\"molecule-gene.php?name=".$name."\">".$name."</a></td><td>".$row["SCORE1"]."%</td></tr>";
		    print '<tr valign="top"><td><hr size="1"></td><td><hr size="1"></td></tr>';
			print "</table>";
		}
	
	
		
     }

    print "</center><br>study made with <a target=\"blank\" href=\"http://inparanoid.cgb.ki.se/\">inparanoid</a>";

?>


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