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

<?php
	$name = $_GET["name"];
	
	
	
	$requete="select B.\"SPECIES\", A.* from \"CLONE_SEQ\" A, \"MOL_ENTITY\" B where (A.\"NAME\"='$name' or A.\"GENBANK_ID\"='$name') and (B.\"MOL_ID\"=A.\"CLONE_SEQ_ID\")";
	$stmt = pg_query($c,$requete);
	if( $row=pg_fetch_array($stmt) ){
		
		$id=$row["CLONE_SEQ_ID"];
		$nameClone=$row["CLONE_NAME"];
		
		print "<h2><strong><em>".$row["GENBANK_ID"]."&nbsp;&nbsp;&nbsp;&nbsp;".$row["CLONE_NAME"]."</em></strong></h2>";
		
	    print "<u><strong>Features</strong></u><br>";
		print "<table width=\"100%\">";
    	print "<tr><td  width=\"20%\"><strong>Name: </strong></td><td>".$row["NAME"]."</td></tr>";
		print "<tr valign=\"top\" align=\"left\"><td><strong>Species: </strong></td><td>".$row["SPECIES"]."</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><strong>Sequence type: </strong></td><td>".$row["TYPE"]."</td></tr>";
		print "<tr valign=\"top\" align=\"left\"><td><strong>Orientation: </strong></td><td>".$row["END"]."</td></tr>";
		print "<tr valign=\"top\" align=\"left\"><td><strong>Genbank ID: </strong></td><td><a target=\"blank\" href=\"http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=nucleotide&cmd=search&term=".$row["GENBANK_ID"]."\">".$row["GENBANK_ID"]."</a></td></tr>";
		print "<tr valign=\"top\" align=\"left\"><td><strong>Cluster: </strong></td><td><a href=\"ESTcluster.php?name=".$row["ANISEED_CLUSTER_ID"]."\">".$row["ANISEED_CLUSTER_ID"]."</a></td></tr>";
//UNIGENE//		print "<tr valign=\"top\" align=\"left\"><td><strong>Unigene cluster: </strong></td><td><a href=\"ESTcluster.php?name=".OCIresult($stmt,"CLUSTER_ID")."\">".OCIresult($stmt,"CLUSTER_ID")."</a></td></tr>";
    	print "<tr valign=\"top\" align=\"left\"><td><strong>Clone name: </strong></td><td><a href=\"molecule-clone2.php?name=".$row["CLONE_NAME"]."\">".$row["CLONE_NAME"]."</a></td></tr>";
    //UNIGENE//	$clust=OCIresult($stmt,"CLUSTER_ID");
		$clust=$row["ANISEED_CLUSTER_ID"];
		$clonename=$row["CLONE_NAME"];
	

	
		//if(! ocicolumnisnull($stmt,"CLONE_NAME")){
			if ($row["CLONE_NAME"]!=null)
			{
		

		    //requete pour les librairies
			$requete="select \"LIBRARY_ID\" from \"CLONE\" where \"CLONE_NAME\"='".$row["CLONE_NAME"]."'";
			$stmt = pg_query($c,$requete);                                                      //on commence par voir s'il existe 1 enregistrement, ensuite on l'affiche
			if($row=pg_fetch_array($stmt)){                                                                  //en passant par 2 requetes separees
			//if(! ocicolumnisnull($stmt,"LIBRARY_ID")){                                        //
			    $requete="select b.\"LIBRARY_ID\", a.\"TITLE\", a.\"TISSUE\", a.\"ORGAN\", a.\"VECTOR\" from \"LIBRARY\" a, \"CLONE\" b where (a.\"LIBRARY_ID\"=b.\"LIBRARY_ID\")and(b.\"CLONE_NAME\"='".$clonename."')";
				$stmt = pg_query($c,$requete);
				//OCIFetch($stmt);
				//if(! ocicolumnisnull($stmt,"LIBRARY_ID")){
				if($row=pg_fetch_array($stmt)){
				    print "<tr valign=\"top\" align=\"left\"><td><strong>Library: </strong></td><td>".$row["TITLE"]."</td></tr>";
					print "<tr valign=\"top\" align=\"left\"><td><strong>Tissue: </strong></td><td>".$row["TISSUE"]."</td></tr>";
					print "<tr valign=\"top\" align=\"left\"><td><strong>Organ: </strong></td><td>".$row["ORGAN"]."</td></tr>";
					print "<tr valign=\"top\" align=\"left\"><td><strong>Vector: </strong></td><td>".$row["VECTOR"]."</td></tr>";
				}
			}
		}
	/*   ////ancienne version pour utiliser unigene
		//requete pour gene affecte a ce clone

		$requete="SELECT GENE_ID FROM CIONA_DESIGN.CLUSTERING WHERE CLUSTER_ID='$clust'"; //
		$stmt = OCIParse($connection, $requete);                                          //hideux mais impossible de faire autrement a cause d'un bug
		OCIExecute($stmt);                                                                //on commence par voir s'il existe 1 enregistrement, ensuite on l'affiche
		if( OCIFetch($stmt) ){                                                                  //en passant par 2 requetes separees
		//if(  (! ocicolumnisnull($stmt,"GENE_ID"))and(strlen($clust)>0)  ){                                           //
			$requete="SELECT B.CLUSTER_ID, B.GENE_ID, A.NAME FROM CIONA_DESIGN.GENE A, CIONA_DESIGN.CLUSTERING B WHERE (A.GENE_ID=B.GENE_ID) AND (B.CLUSTER_ID='$clust')";
			$stmt = OCIParse($connection, $requete);
			OCIExecute($stmt);
			//OCIFetch($stmt);
		
			//if(! ocicolumnisnull($stmt,"GENE_ID"))
			if( OCIFetch($stmt) )
				print "<tr valign=\"top\" align=\"left\"><td><strong>Corresponding gene: </strong></td><td><a href=\"molecule-gene.php?name=".OCIresult($stmt,"NAME")."\">".OCIresult($stmt,"NAME")."</a></td></tr>";
    	}
	*/
	
        ////nouvelle version pour utiliser le clustering maison
	    ///requete pour gene affect�a ce clone
		$requete="SELECT \"NAME\" FROM \"GENE\" WHERE \"GENE_ID\"='$clust'";
		$stmt = pg_query($c,$requete);
		if( $row=pg_fetch_array($stmt) ){
			print "<tr valign=\"top\" align=\"left\"><td><strong>Corresponding gene: </strong></td><td><a href=\"molecule-gene.php?name=".$row["NAME"]."\">".$row["NAME"]."</a></td></tr>";
    	}
		print "</table>";//</tr></table>
        
		if(strlen($nameClone)>0)
    	    print "<center><a href=\"insitu-result.php?target=$nameClone\"><img src=\"pictures/button-getPics.jpg\" border=\"0\"></a></center>";
        else
		    print "<center><a href=\"insitu-result.php?target=$name&MOLtype=1&Order=DEV_STAGE_ID\"><img src=\"pictures/button-getPics.jpg\" border=\"0\"></a></center>";
		
//////////////////////////////////////////SEQUENCE/////////////////////////////////////////////
		$requete="select \"SEQUENCE\", \"LENGTH\", \"COMMENTS\" from \"SEQUENCE\" where \"MOL_ID\"=$id";
		$stmt = pg_query($c,$requete);
								
    	if( $row=pg_fetch_array($stmt) ){
	    	$lob = $row["SEQUENCE"];

		/* DEBUT DE L'AFFICHAGE DU CLOB */

		pg_query ($c, "begin");	/*Debut de la transaction*/
		
		$handle_lo = pg_lo_open($c,$lob,"r");
		$seq=pg_lo_read($handle_lo);

		pg_query($c,"end"); /*fin de la Transaction*/

			
			$seq=ereg_replace("<br>","",$seq);
			$seq=ereg_replace("\n","",$seq);
			$seq = chunk_split($seq, 70, "\n");
			
	    	print "<br><br><u><strong>Sequence</strong></u><br><strong>Length: </strong>".$row["LENGTH"]."<br>".strtoupper($row["COMMENTS"])."<br><br><pre><font face=\"Courier New, Courier, mono\" size=\"3\">$seq</font></pre>";
		}
	
	}else{ print "<br><br><center><h2><strong>No match</strong></h2></center><br><br>"; }
?>

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