<?php
	//connection
	include("connection.php");
    include("frames_header.php");
?>
<SCRIPT TYPE="text/javascript">
<!--
function popup(mylink, windowname)
{
    if (! window.focus)
	    return true;

    var href;
    if (typeof(mylink) == 'string')
        href=mylink;
    else
        href=mylink.href;

    document.GO = window.open(href, windowname, 'width=600,height=200,scrollbars=yes,toolbar=no,resizable=yes');
    document.GO.focus();
	
	return false;
}
//-->
</SCRIPT>



<?php

    $name=$_GET["name"];
	
	$requete="select A.*, B.\"SPECIES\" from \"GENE\" A, \"MOL_ENTITY\" B where (A.\"NAME\"='$name')and(A.\"GENE_ID\"=B.\"MOL_ID\")";
	$stmt = pg_query($c,$requete);

	if($row=pg_fetch_array($stmt)){
	
	    $id=$row["GENE_ID"];
	    $species=$row["SPECIES"];

	
//	if(ocicolumnisnull($stmt,"GENE_ID")){
//	    print "<br><br><center><h2><strong>No match</strong></h2></center><br><br>";
//	}else{
	    $id=$row["GENE_ID"];
		print "<h2><strong><em>".$row["NAME"]."</em></strong></h2>";
        
	    print "<u><strong><font size=\"+2\">Features</font></strong></u><br>";
        print "<table width=\"100%\"><tr valign=\"top\" align=\"left\"><td width=\"25%\"><strong>Gene ID: </strong></td><td>".$row["NAME"]."</td></tr>";
        
		
	    $requete2="select \"SYNO\" from \"SYNO\" where \"GENE_ID\"=$id and \"ORIGIN\"='user-JGI'";
	    $stmt2 = pg_query($c,$requete2);
		
        print "<tr valign=\"top\" align=\"left\"><td><strong>Possible biological name</strong> (manual annotation)*: </td><td>";
		$a=0;
		while($row2=pg_fetch_array($stmt2)){
			   if($a++>0)
				    print ' <strong><font color="000000">/</font></strong> ';
		       print $row2["SYNO"];
		}
		print "</td></tr>";
	    print "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>";
		
		
	    $requete2="select \"SYNO\" from \"SYNO\" where \"GENE_ID\"=$id and \"ORIGIN\"='phylogeny'";
	    $stmt2 = pg_query($c,$requete2);
		print "<tr valign=\"top\" align=\"left\"><td><strong>Possible biological name</strong> :</td><td>";
		$a=0;
		while($row2=pg_fetch_array($stmt2)){
		    //if(OCIresult($stmt2,"SYNO") != $name)
				if($a++>0)
				    print ' <strong><font color="000000">/</font></strong> ';
		        print $row2["SYNO"];
		}
		if($a==0){
			$requete2="select \"DESCRIPTION\", \"EVALUE\" from \"BLAST\" where \"MOL_ID\"=$id and \"SCORE\"=(select max(\"SCORE\") from \"BLAST\" where \"MOL_ID\"=$id)";
			//$requete2="select max(score), description, evalue from ciona_design.blast where mol_id=$id";
			$stmt2 = pg_query($c,$requete2);
			if($row2=pg_fetch_array($stmt2)){
			    $eval = $row2["EVALUE"];
			    if( $eval <= 1e-10)
				    print "HIGHLY ";
				else if( ($eval >= 1e-4) and ($eval <= 1e-3) )
				    print "WEAKLY ";
					
				if($eval <= 1e-3)
			        print "SIMILAR TO ".$row2["DESCRIPTION"]." (Eval: $eval)";
			}
		}
		
		print "</td></tr>";
	    print "<tr><td>&nbsp;
<a href=\"gene2.php?species=$species&name=$name\"><img border=\"0\" src=\"pictures/button-cur-edit.gif\"></a>
</td><td>&nbsp;</td></tr>";
	
	/*
	    $requete2="select syno from ciona_design.syno where gene_id=$id and origin='user-JGI'";
	    $stmt2 = OCIParse($connection, $requete2);
	    OCIExecute($stmt2);
		
        print "<tr valign=\"top\" align=\"left\"><td><strong>Possible biological name</strong> (manual annotation)*: </td><td>";
        while(OCIFetch($stmt2)){
		       print OCIresult($stmt2,"SYNO")."&nbsp;&nbsp;&nbsp;";
		}
		print "</td></tr>";
	print "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>";
	*/
	
		print "<tr valign=\"top\" align=\"left\"><td><strong>Description: </strong></td><td>".$row["COMMENTS"]."</td></tr>";
		print "<tr valign=\"top\" align=\"left\"><td width=\"15%\"><strong>Species: </strong></td><td>".$row["SPECIES"]."</td></tr>";
        print "<tr valign=\"top\" align=\"left\"><td><strong>Scaffold: </strong></td><td>".$row["SCAFFOLD_ID"]."</td></tr>";
		print "<tr valign=\"top\" align=\"left\"><td><strong>Chr. number: </strong></td><td>".$row["CHR_NUM"]."</td></tr>";
		print "<tr valign=\"top\" align=\"left\"><td><strong>Strand: </strong></td><td>".$row["STRAND"]."</td></tr>";
		
		print "<tr valign=\"top\" align=\"left\"><td><strong>Corresponding cluster: </strong></td><td>";
		print "<a href=\"ESTcluster.php?name=".$id."\">".$id."</a></td></tr>";
		
		print "<tr valign=\"top\" align=\"left\"><td><strong>Promoter regions: </strong></td><td>";
	    $requete2="select a.\"NAME\", a.\"PROMOTER_ID\" from \"GENE_REGULATION\" b, \"PROMOTER\" a where a.\"PROMOTER_ID\"=b.\"PROMOTER_ID\" and b.\"GENE_ID\"=$id";
		$stmt2 = pg_query($c,$requete2);	
        while($row2=pg_fetch_array($stmt2)){
				print "<a href=\"reg-region-edit.php?id=".$row2["PROMOTER_ID"]."\">".$row2["NAME"]."</a>&nbsp;&nbsp;&nbsp;&nbsp;";
		}
		print '</td></tr>';
		
		print "</table>";
									/* APPEL AU BROWSER ICI  */
		if($row2["SPECIES"] == "Ciona intestinalis"){
		    print '<br>Go to the <a target="_BLANK" href="'.$gbrowseAddress.'intestinalis?name='.$name.'">browser</a>';
            print "<br><a target=\"blank\" href=\"http://genome.jgi-psf.org/cgi-bin/dispGeneModel.v4?db=ciona4&id=".eregi_replace( "ci0100","",$name)."\"> <img src=\"pictures/jgi.jpg\" align=\"middle\" border=\"0\"> Get the JGI file</a>";
	        //print "<br><a target=\"blank\" href=\"http://hgwdev.cse.ucsc.edu/cgi-bin/hgc?g=jgiGene&i=".$name."\"> <img src=\"pictures/UCSC.jpg\" align=\"middle\" border=\"0\"> Get the UCSC file</a>";
		}
		print "<br><br><center><a href=\"molecule-phylogeny.php?name=$name&id=$id\"><img border=\"0\" src=\"pictures/button-phylogeny.jpg\"></a>   &nbsp;&nbsp;&nbsp;&nbsp;  <a href=\"molecule-sequence.php?id=$id\"><img border=\"0\" src=\"pictures/button-sequence.jpg\"></a>  &nbsp;&nbsp;&nbsp;&nbsp;  <a href=\"insitu-result.php?target=$name&MOLtype=2&Order=DEV_STAGE_ID\"><img border=\"0\" src=\"pictures/button-getPics.jpg\"></a>  &nbsp;&nbsp;&nbsp;&nbsp;  <a href=\"est-expression.php?name=$id&species=$species\"><img src=\"pictures/button-library.jpg\" border=\"0\"></a></center>";
		
		
///////////////////////////////////////////INTERPRO////////////////////////////////////////////
		$requete="select \"LENGTH\" from \"SEQUENCE\" where \"MOL_ID\"=$id";
		$stmt = pg_query($c,$requete);
		
		$row=pg_fetch_array($stmt);
		
		$length=$row["LENGTH"];


		$requete="select A.*, B.\"NAME\" from \"IP_DESCRIPTION\" A, \"INTERPRO\" B where A.\"MOL_ID\"='$id' and A.\"IP_ID\"=B.\"IP_ID\"";
	    $stmt = pg_query($c,$requete);
		
        $count=0;
		while($row=pg_fetch_array($stmt)){
		
		    $tab[$row["METHOD"]][$row["IP_ID"]]["location"]=$row["LOCATION"];
		    $tab[$row["METHOD"]][$row["IP_ID"]]["IPID"]=$row["IP_ID"];
			$tab[$row["METHOD"]][$row["IP_ID"]]["DBID"]=$row["DB_ID"];
			$tabname[$row["IP_ID"]]=$row["NAME"];
			
			++$count;
		}
		
		if($count>0){
		
			print "<br><br><strong><font size=\"+2\">InterproScan</font></strong><br><br>";
			print "<center><table width=\"99%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
			
			foreach ($tab as $method => $dbid){			
			    print "<tr><td height=35  align=\"right\"><strong>".$method."</strong>&nbsp;</td><td align=\"left\"><img src=\"picture-motifs.php?size=".($length/3)."&data=".addslashes(urlencode(serialize($tab[$method])))."\" border=0 USEMAP=#img_map ISMAP></td></tr>";
			    $a=0;
				foreach ($dbid as  $data){
				    
				    print "<map name=\"img_map$a\">";
				    print "</map>";
					
					print "<tr><td align=\"right\" valign=\"top\">&nbsp;-</td><td><strong>".++$a.".</strong> ".$tabname[$data["IPID"]]." (<a target=\"_BLANK\" href=\"http://www.ebi.ac.uk/interpro/IEntry?ac=".$data["IPID"]."\">".$data["IPID"]."</a>)";
				                                                                                                   
				    if($method=="HMMSmart")
					    print " - <a target=\"_BLANK\" href=\"http://smart.embl-heidelberg.de/smart/do_annotation.pl?BLAST=DUMMY&DOMAIN=&ACC=".$data["DBID"]."\">".$data["DBID"]."</a>";
					else if($method=="BlastProDom")
					    print " - <a target=\"_BLANK\" href=\"http://prodes.toulouse.inra.fr/prodom/current/cgi-bin/request.pl?question=DBEN&query=".$data["DBID"]."\">".$data["DBID"]."</a>";
					else if($method=="ProfileScan")
					    print " - <a target=\"_BLANK\" href=\"http://au.expasy.org/cgi-bin/prosite-search-ac?".$data["DBID"]."\">".$data["DBID"]."</a>";
					else
					    print " - ".$data["DBID"];
						
					print "<br><font size=\"-2\">Position/Score: </font><font size=\"-1\">".$data["location"]."</font>";
						
				    print "</td></tr>";
				}
			}
			
			print "</TABLE></center>";
		
		}
		//print "<br><img src=\"pictures/superFamilly.gif\" align=\"middle\"> <a target=\"blank\" href=\"http://supfam.mrc-lmb.cam.ac.uk/SUPERFAMILY/cgi-bin/gene.cgi?genome=ci&seqid=$name\">Domain prediction from Superfamilly</a><br>";

/////////////////////////////////////////////////ORTHOLOG/////////////////////////////////////////////////
		print "<br><br><strong><font size=\"+2\">Ortholog prediction</font></strong><br>";
        print "<center><table width=\"99%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#333333\">";
	    print "<tr align=\"center\" valign=\"middle\" bgcolor=\"#990000\" bordercolor=\"#990000\"><td><strong>Ortholog name*</strong></td><td><strong>ID</strong></td><td><strong>Score</strong></td><td width=\"30%\"><strong>Protein familly*</strong></td><td background=\"pictures/barre-red.jpg\"><strong>Species</strong></td></tr>";
	   
	 $requete="select * from \"PHYLOGENY\" where \"MOL_ID\"=$id and \"ORTHOLOG\" is not NULL order by \"SPECIES\", \"ORTHOLOG\", \"SCORE2\" DESC";
    	$stmt = pg_query($c,$requete);
		$count=0;
    	while($row=pg_fetch_array($stmt)){
		    ++$count;
			if($row["DB"]=="ensembl"){
			    if($row["SPECIES"]=='Drosophila melanogaster')
		            print "<tr align=\"center\" valign=\"middle\"><td><a target=\"blank\" href=\"http://www.ensembl.org/Drosophila_melanogaster/protview?peptide=".$row["ID"]."\">".$row["ORTHOLOG"]."</a></td><td>".$row["ID"]."</td><td>".$row["SCORE2"]."%</td><td><font size=\"-1\">".$row["FAMILLY"]."</font></td><td>".$row["SPECIES"]."</td></tr>";
			    else if($row["SPECIES"]=='Homo sapiens')
				    print "<tr align=\"center\" valign=\"middle\"><td><a target=\"blank\" href=\"http://www.ensembl.org/Homo_sapiens/protview?peptide=".$row["ID"]."\">".$row["ORTHOLOG"]."</a></td><td>".$row["ID"]."</td><td>".$row["SCORE2"]."%</td><td><font size=\"-1\">".$row["FAMILLY"]."</font></td><td>".$row["SPECIES"]."</td></tr>";
			    else if($row["SPECIES"]=='Mus musculus')
				    print "<tr align=\"center\" valign=\"middle\"><td><a target=\"blank\" href=\"http://www.ensembl.org/Mus_musculus/protview?peptide=".$row["ID"]."\">".$row["ORTHOLOG"]."</a></td><td>".$row["ID"]."</td><td>".$row["SCORE2"]."%</td><td><font size=\"-1\">".$row["FAMILLY"]."</font></td><td>".$row["SPECIES"]."</td></tr>";
			    else
				    print "<tr align=\"center\" valign=\"middle\"><td>".$row["ORTHOLOG"]."</td><td>".$row["ID"]."</td><td>".$row["SCORE2"]."%</td><td><font size=\"-1\">".$row["FAMILLY"]."</font></td><td>".$row["SPECIES"]."</td></tr>";
			    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></tr>';
			}else
			    print "<tr valign=\"top\" align=\"center\"><td>".$row["ORTHOLOG"]."</td><td>".$row["ID"]."</td><td>".$row["SCORE2"]."%</td><td><font size=\"-1\">".$row["FAMILLY"]."</font></td><td>".$row["SPECIES"]."<td></tr>";
		}
		if($count==0){
		    print "</table></center><center><strong>No match</strong></center>";
		}else{
		    print "</table></center>";
			print "*annotations from <a target=\"blank\" href=\"http://www.ensembl.org/\">Ensembl</a>";
		}
	
	
//////////////////////////////////////////Best BLAST hits///////////////////////////////////////////

		print "<br><br><strong><font size=\"+2\">Best blast hits</font></strong><br>";
        print "<center><table width=\"99%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#333333\">";
	    print "<tr align=\"center\" valign=\"middle\" bgcolor=\"#990000\" bordercolor=\"#990000\"><td><strong>Protein name</strong></td><td><strong>ID%</strong></td><td><strong>Score</strong></td><td><strong>Evalue</strong></td><td><strong>HSP</strong></td><td background=\"pictures/barre-red.jpg\"><strong>Description</strong></td></tr>";
	    //$requete="select PROTEIN, EVALUE, SCORE, BLOCKS, DESCRIPTION, ID from ciona_design.blast where mol_id=$id order by score";
        $requete="select \"SCORE\", \"PROTEIN\", \"EVALUE\", \"BLOCKS\", \"DESCRIPTION\", \"ID\" from \"BLAST\" where \"MOL_ID\"=$id and \"DESCRIPTION\" is not NULL order by \"SCORE\" DESC";        	
		
		$stmt = pg_query($c,$requete);
		$count=0;
    	while($row=pg_fetch_array($stmt)){
		    ++$count;
			print "<tr align=\"center\"><td><a target=\"_BLANK\" href=\"http://us.expasy.org/cgi-bin/niceprot.pl?".$row["PROTEIN"]."\">".$row["PROTEIN"]."</a></td><td>".$row["ID"]."%</td><td>".$row["SCORE"]."</td><td>".$row["EVALUE"]."</td><td><a href=\"molecule-hsp.php?gene=".$id."&mol=".$row["PROTEIN"]."\">".$row["BLOCKS"]."</a></td><td><font size=\"-1\">".$row["DESCRIPTION"]."&nbsp;</font></td></tr>";
		    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></tr>';
		}
		if($count==0){
		    print "</table></center><center><strong>No match</strong></center>";
		}else{
		    print "</table></center>";
			print "PSI-Blast - Swissprot database";
		}
        

////////////////////////////////////////////////GO//////////////////////////////////////////////////
	    //$requete2="select B.species_origin, A.go_id, A.go_term, A.go_type, A.definition from ciona_design.go A, ciona_design.go_description B where (B.mol_id=$id) and (B.go_id=A.go_id) order by A.go_type, go_id";
		$requete2="select B.\"SPECIES_ORIGIN\", A.\"GO_ID\", A.\"GO_TERM\", A.\"GO_TYPE\" from \"GO\" A, \"GO_DESCRIPTION\" B where (B.\"MOL_ID\"=$id) and (B.\"GO_ID\"=A.\"GO_ID\") order by A.\"GO_TYPE\", \"GO_ID\"";
	    $stmt2 = pg_query($c,$requete2);
	    print "<br><br><strong><font size=\"+2\">Gene Ontology <a href=\"go2.php?species=$species&name=$name\"><img border=\"0\" src=\"pictures/button-cur-edit.gif\"></a></font></strong><br>";
        print "<center><table width=\"99%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#333333\">";
		//print '<tr align="center" valign="middle" bgcolor="#990000" bordercolor="#990000"><td><strong>GO ID</strong></td><td><strong>Type</strong></td><td><strong>Term</strong></td><td background="pictures/barre-red.jpg" ><strong>Definition</strong></td></tr>';
		print '<tr align="center" valign="middle" bgcolor="#990000" bordercolor="#990000"><td><strong>GO ID</strong></td><td><strong>Origin</strong></td><td><strong>Type</strong></td><td background="pictures/barre-red.jpg"><strong>Term</strong></td></tr>';
		$count=0;
		while($row2=pg_fetch_array($stmt2)){
		    ++$count;
		    //if( (OCIresult($stmt2,"GO_TYPE")!='process')or(OCIresult($stmt2,"SPECIES_ORIGIN")!='Drosophila melanogaster') )
                //print "<tr align=\"center\"><td><a target=\"blank\" href=\"http://www.godatabase.org/cgi-bin/go.cgi?action=replace_tree&query=".OCIresult($stmt2,"GO_ID")."&search_constraint=terms\">".OCIresult($stmt2,"GO_ID")."</a> <br>(from ".OCIresult($stmt2,"SPECIES_ORIGIN").")</td><td>".OCIresult($stmt2,"GO_TYPE")."</td><td>".OCIresult($stmt2,"GO_TERM")."</td><td width=\"40%\">&nbsp;".OCIresult($stmt2,"DEFINITION")."</td></tr>";
				//print "<tr align=\"center\"><td>".OCIresult($stmt2,"GO_ID")."<br>(from ".OCIresult($stmt2,"SPECIES_ORIGIN").")</td><td>".OCIresult($stmt2,"GO_TYPE")."</td><td>".OCIresult($stmt2,"GO_TERM")."</td><td width=\"40%\">&nbsp;".OCIresult($stmt2,"DEFINITION")."</td></tr>";
				print "<tr align=\"center\"><td>".$row2["GO_ID"]."</td><td>".$row2["SPECIES_ORIGIN"]."</td><td>".$row2["GO_TYPE"]."</td><td><a href=\"GO-definition.php?id=".$row2["GO_ID"]."\" onClick=\"return self.popup(this, 'Definition')\">".$row2["GO_TERM"]."</a></td></tr>";
		        print '<tr valign="top"><td><hr size="1"></td><td><hr size="1"></td><td><hr size="1"></td><td><hr size="1"></td></tr>';
		}
		print "</TABLE></center>";
		if($count==0)
		    print "<center><strong>No match</strong></center>";
		else
		    print "infered from ortholog prediction and interpro";
		/*else{
			print "<br><center>";
			print "<a href=\"GO-cluster.php?name=$name&mode=pr&id=$id\"><img border=\"1\" src=\"pictures/button-process.jpg\"></a>&nbsp;&nbsp;&nbsp;&nbsp;";
			print "<a href=\"GO-cluster.php?name=$name&mode=fu&id=$id\"><img border=\"1\" src=\"pictures/button-function.jpg\"></a>&nbsp;&nbsp;&nbsp;&nbsp;";
			print "<a href=\"GO-cluster.php?name=$name&mode=lo&id=$id\"><img border=\"1\" src=\"pictures/button-localisation.jpg\"></a>";
			print "</center>";
        }*/

	}else{ print "<br><br><center><h2><strong>No match</strong></h2></center><br><br>"; }

	print"<br><br><br>*includes JGI user annotations";
	
?>

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