<?php

require('../lib/genopar.lib.php');

// if(!doAuth(LVLPES))
// 	exit;

$genopar = new Genopar(__FILE__);

echo '
<script type="text/javascript" src="'.$URL_PADRAO.'/css/ddown.js"></script>

<script>
function abreLink(url){
	window.open(url, "", "toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=600,height=400");
}
</script>
<style>
body {
	background: #DDE;
}
</style>
</head>
<body>
 <div style="
	margin-top: 10px;
	margin-left: 10px;
	margin-right: 10px;

	width: auto;

	overflow: auto;
	background:#EEF;
	text-align:justify;

	border-top:3px dotted #666;
	border-left:3px dotted #666;
	border-right:3px dotted #666;
	border-bottom:3px dotted #666;

	padding-top: 3px;
	padding-left: 10px;
 "> ';

verGetPost(array('id', 'mtg'));

if ($id == '')
	$genopar->error("Erro.");

$tipos = array('n', 'p');

foreach ($tipos as $tipo){
	$dir = "../Fasta/$mtg/ORFs/".$tipo."/";
	$fileName = $dir."ORF".$id.".fas";
	$seq = '';
	$col = 60;
	
	$file = fopen($fileName, "r");
	
	echo "<textarea cols=".($col+1)." rows=8 readonly>\n";
	$tit = strtoupper(fgets($file, 1024));
	while (!feof($file))
		$seq .= strtoupper(fgets($file, 4096));
	
	echo "$tit";
	foreach (str_split($seq, $col) as $seqPart)
		echo "$seqPart";
	
	echo '</textarea>';
	
	echo "<p>";
	if ($tipo == 'n'){
		$megablast="http://www.ncbi.nlm.nih.gov/BLAST/Blast.cgi?QUERY=$seq&DATABASE=nr&PAGE=Nucleotides&PROGRAM=blastn&BLAST_PROGRAMS=megaBlast&PAGE_TYPE=BlastSearch";
		$blastx="http://www.ncbi.nlm.nih.gov/BLAST/Blast.cgi?QUERY=$seq&DATABASE=nr&PAGE=Nucleotides&PROGRAM=blastn&BLAST_PROGRAMS=blastx&PAGE_TYPE=BlastSearch";
		echo "<a href=\"javascript:abreLink('$megablast')\">Mandar para o BLAST (MEGABLAST)</a><br>";
		echo "<a href=\"javascript:abreLink('$blastx')\">Mandar para o BLAST (BLASTX)</a>";
	}else{
		$blastp="http://www.ncbi.nlm.nih.gov/BLAST/Blast.cgi?QUERY=$seq&DATABASE=nr&PAGE=Proteins&PROGRAM=blastp&BLAST_PROGRAMS=blastp&PAGE_TYPE=BlastSearch";
		echo "<a href=\"javascript:abreLink('$blastp')\">Mandar para o BLAST (BLASTP)</a>";
	}

		if ($tipo == 'n')
			$link = "http://www.ncbi.nlm.nih.gov/BLAST/Blast.cgi?QUERY=$seq&DATABASE=nr&PAGE=Nucleotides&PROGRAM=blastn";
		elseif($tipo == 'p')
			$link = "http://www.ncbi.nlm.nih.gov/BLAST/Blast.cgi?QUERY=$seq&DATABASE=nr&PAGE=Proteins&PROGRAM=blastp";
		else
			exit;
	
// 		$progr = array("megaBlast","blastx");
// 		foreach ($progr as $prog){
// 			$link .= "&BLAST_PROGRAMS=$prog&PAGE_TYPE=BlastSearch";
// 			echo "<a href=\"javascript:abreLink('$link')\">Mandar para o BLAST (".strtoupper($prog).")</a><br>";
// 		}
		echo "</p>";
}

?>
