<?php
include("connection.php");
//Title before frames_header
print '<title>ANISEED - Molecule sequence</title>';

include("frames_header.php");
?>

<br><br>
<?php
        $id=$_GET["id"];

		$requete="select \"NAME\" from \"GENE\" where \"GENE_ID\"='$id'";
		$stmt = pg_query($c,$requete);
        if($row=pg_fetch_array($stmt)){
		    print "<h2><strong><em>".$row["NAME"]."</em></strong></h2>";
		}
        
//////////////////////////////////////////SEQUENCE/////////////////////////////////////////////
		$requete="select \"SEQUENCE\", \"LENGTH\", \"COMMENTS\", \"MOL_ID\" 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*/

		/* FIN DE L'AFFICHAGE DU LOB */



			$seq=ereg_replace("<br>","",$seq);
			$seq=ereg_replace("\n","",$seq);
			$seq = chunk_split($seq, 70, "\n");
			

//AJOUT
/*		
		$requete="select \"BEGIN\",\"END\",\"INTRON_EXON\" from \"GENE\" where \"GENE_ID\"='$id'";
		$stmt=pg_query($c,$requete);
		$row2=pg_fetch_array($stmt);

		$tab=explode(";",$row2["INTRON_EXON"]);
		$begin=$row2["BEGIN"];
		$end=$row2["END"];

		//Conversion position globale en locale
		for ($i=0;$i<count($tab)-1;$i++)
		{
		$tmp=$tab[$i];
		$tmp1=explode("-",$tmp);
		$tmp1[0]-=$begin;
		$tmp1[1]-=$begin;
		$tmp=implode("-",$tmp1);
		$tab[$i]=$tmp;
		}

		//Colorization du premier exons

		
		$tmp=$tab[0];
		$tmp1=explode("-",$tmp);

		$seq1=substr($seq,0,$tmp1[0]);
		$seq2=substr($seq,$tmp1[0],$tmp1[1]-($tmp1[0]+1));
		$seq3=substr($seq,$tmp1[1]-($tmp1[0]+1)+$tmp1[0],strlen($seq)-($tmp1[1]-($tmp1[0]+1)+$tmp1[0]));
		$seq=$seq1."<span STYLE=\"background: #0000FF;font: bold;\">$seq2</span>".$seq3;
*/	
//




		    print "<br><u><strong><font size=\"+2\">Sequence</font></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>";
		}


print '<br>';

//////////////////////////////////////////PROTEIC SEQUENCE/////////////////////////////////////////////
		$requete="select \"SEQUENCE\", \"LENGTH\", \"MOL_ID\" from \"PROT_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*/

		/* FIN DE L'AFFICHAGE DU LOB */



			$seq=ereg_replace("<br>","",$seq);
			$seq=ereg_replace("\n","",$seq);
			$seq = chunk_split($seq, 70, "\n");
			

		    print "<br><u><strong><font size=\"+2\">Amino acid sequence</font></strong></u><br><strong>Length: </strong>".$row["LENGTH"]."<br><br><pre><font face=\"Courier New, Courier, mono\" size=\"3\">$seq</font></pre>";
		}






?>

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