/*
###############################################################################
Indice p/ anota��o - mostra figuras p/ contig escolhido.
Desenvolvida: 30-Jul-2003 - Augusto Favetti
Atualizada: 30-Jul-2008 - Felipe R O Pisa
###############################################################################
*/
require ("../lib/genopar.lib.php");
require ("../lib/geraGraphAnnot.php");
$genopar = new Genopar(__FILE__);
?>
if(!doAuth(LVLPES)){
$genopar->fechaPagina(); exit;
}
$orfWidth=50;
$orfHeight=10;
$escala=1;
verGetPost(array("mtg", "processa", "contig", "start", "end", "reverse", "COGcolors", "showInvalid", "zoom", "showQual", "geraFrames", "showTable", "kb", "showClones", "orfWidth", "orfHeight", "escala"));
if (!$mtg){
/* */
$mtgs = $genopar->obtemMtgs();
$genopar->abrePagina("Contig Annotation Page");
$genopar->abreForm();
echo "
";
echo "";
echo "";
echo "Assembly: ";
echo " ";
echo "";
$genopar->select("mtg", $mtgs, "","", TRUE);
echo " ";
echo " ";
echo "";
$genopar->submit();
echo " ";
echo "
";
$genopar->fechaForm();
$genopar->fechaPagina();
}
if (strlen($UserAuth_group)!=2)
$table='FP';
else
$table= $UserAuth_group;
$genopar->abrePagina("Contig Annotation Page [$mtg] ");
echo '
';
$genopar->abreBanco();
$size=$reverse=$showInvalid=$showQual=$start=$end=$showTable=$geraFrames=$showClones=$COGcolors='';
$zoom=10;
$kb=10;
verGetPost(array("processa", "contig", "start", "end", "reverse", "showInvalid", "COGcolors", "geraFrames", "zoom", "showQual", "showTable", "kb", "showClones"));
if ($geraFrames == '')
$geraFrames = 0;
if (!$processa)
$geraFrames = 1;
if ($showInvalid == '')
$showInvalid=0;
if ($reverse == '')
$reverse = 0;
if ($COGcolors == '')
$COGcolors = 0;
if ($zoom == '' or $zoom<1 or $zoom>19)
$zoom=10;
$n= $genopar->queryBanco("SELECT id as contig, tam FROM contig WHERE idMontagem='$mtg' ORDER BY id");
$contig_lab= array();
while ($lin= $genopar->getArray()){
array_push($contig_lab, $lin['contig']);
$contigs[$lin['contig']]=$lin['tam'];
}
// $n= $genopar->queryBanco('select contig_num, bp_untrim from contigs where bp_trim>0 and qual_med>20 order by contig_num');
//
// $contigs= array();
// while ($lin= $genopar->getArray())
// $contigs[$lin['contig_num']]=$lin['tam'];
$kbArray = array(1,5,10,20,50,100);
$owArray = array(50,100, 150, 200, 300);
$ohArray = array(10,20,50);
echo '';
echo '
';
######### AVISO SOBRE BLAST
$blastAtualizado = $genopar->queryBanco("
SELECT max(idEdicao)
FROM edicaoORF
WHERE
idMontagem='$mtg' AND
BLAST_atualizado=0");
$blastAtualizado = $genopar->getArray();
if ($blastAtualizado[0]){
$updateBlastLink = "javascript:popup(\"outOfDateBLASTs.php?mtg=$mtg&popup=1\")";
echo "WARNING: There are out of date BLAST reports for this assembly. (update ) ";
}
echo '';
if ($processa == '')
tabelaContigs($genopar, $mtg);
if ($processa=='Graphic'){
$ctgLength = $contigs[$contig];
$toSplitSize = 100000;
if ($kb != '')
$kb *= 1000;
else
$kb = 0;
if ($start == '')
$ini = 0;
else
$ini = $start;
if ($end == '')
$fim = $ctgLength;
else
$fim = $end;
echo "
Statistics
";
tabelaEstatistica($genopar, $mtg, $contig, $ini, $fim, $COGcolors);
echo "
";
if ($fim - $ini > $toSplitSize){
$stop = $fim;
$split = 1;
// $i = 0;
for( $regionStart = $ini, $regionEnd = $ini + $toSplitSize -1;
$regionStart < $stop;
$regionStart += $toSplitSize, $regionEnd += $toSplitSize ){
if ($regionEnd > $fim)
$regionEnd = $fim;
$imgSrc = geraSingleGraphAnnot($mtg,$contig,$regionStart,$regionEnd,"",$zoom,$geraFrames,$showInvalid, $showQual, $showClones, $COGcolors, $kb);
echo "
";
echo " ";
echo "
";
ob_flush();
$areaFile_name = "tmp/area.$mtg.$contig.$geraFrames.$regionStart.$regionEnd.$kb.$zoom.$showInvalid";
if (is_readable($areaFile_name)){
$areaFile = fopen($areaFile_name, 'r');
while (!feof($areaFile)){
$line = fgets($areaFile, 4096);
echo "$line\n";
if (preg_match("/TITLE/i", $line) && $showTable){
$array = preg_split("/'/", $line);
$str = $array[1];
$info = preg_split("/ /", $str);
$i = $info[0];
foreach ($info as $data){
if ($data == '') continue;
if (preg_match("/<..?>/", $data)){
$split = preg_split("/<..?>/",$data);
$key = $split[1];
$value = $split[2];
}else{
$key = 'Gene Id';
$value = $data;
}
$tbl[$i][$key] = trim($value);
$keys[$key] = 1;
}
$i++;
}
}
fclose($areaFile);
}
}
}else{
$imgSrc = geraSingleGraphAnnot($mtg,$contig,$ini,$fim,"",$zoom,$geraFrames,$showInvalid, $showQual, $showClones, $COGcolors, $kb);
echo "
";
echo " ";
echo "
";
$areaFile_name = "tmp/area.$mtg.$contig.$geraFrames.$ini.$fim.$kb.$zoom.$showInvalid";
if (is_readable($areaFile_name)){
$areaFile = fopen($areaFile_name, 'r');
// $i = 0;
while (!feof($areaFile)){
$line = fgets($areaFile, 4096);
echo "$line\n";
if (preg_match("/TITLE/i", $line) && $showTable){
$array = preg_split("/'/", $line);
$str = $array[1];
$info = preg_split("/ /", $str);
$i = $info[0];
foreach ($info as $data){
if ($data == '') continue;
if (preg_match("/<..?>/", $data)){
$split = preg_split("/<..?>/",$data);
$key = $split[1];
$value = $split[2];
}else{
$key = 'Gene Id';
$value = $data;
}
$tbl[$i][$key] = trim($value);
$keys[$key] = 1;
}
$i++;
}
}
fclose($areaFile);
}
}
echo '';
echo "";
if ($showTable && count($keys) > 0){
echo '
}
}
elseif ($processa=='Fasta'){
$fcontig="../Fasta/$mtg/Contigs/n/Contig".$contig.".fas";
if ($start > $end) $reverse= 1;
if ( !(is_readable($fcontig)) )
$genopar->error(" Não foi possível ler contig do arquivo: $fcontig ");
$file = fopen($fcontig, 'r');
$header = trim(fgets($file, 4096));
$header .= " [$start..$end]\n";
$SEQ='';
for ($linha= 1; !feof($file); $linhas++){
$line = fgets($file, 4096);
$SEQ.= trim($line);
}
if ($reverse){
$size = $start-$end+1;
$seq = strtoupper(substr($SEQ,$end-1,$size));
$seq = strrev($seq);
$seq = str_replace(array('A','C','G','T',1,2,3,4), array(1,2,3,4,'T','G','C','A'), $seq);
}else{
$size = $end-$start+1;
$seq= strtoupper(substr($SEQ,$start-1,$size));
}
$seqn="";
$cols = 80;
for($i=0;$i';
$rows=10;
echo ($reverse?"Reverse Complement ":"")."Nucleotide Sequence: ($size pb)
";
}
elseif ($processa=='GenBank'){
if ($start == '')
$ini = 0;
else
$ini = $start;
if ($end == '')
$fim = -1;
else
$fim = $end;
$fcontig = "../Fasta/$mtg/Contigs/n/Contig".$contig.".fas";
$GBfile = "tmp/Contig".$contig."_".$mtg.".gbk";
system("perl geraGenBankFile.pl ".$genopar->MySQL_Default_DBname." $mtg $contig $ini $fim $fcontig $GBfile");
if (is_readable($fcontig)){
$file = fopen($GBfile, 'r');
if ($file){
echo "";
}
}
}
$genopar->fechaPagina();
function complement($nt){
switch ($nt){
case 'A':
case 'a':
return 'T';
case 'T';
case 't':
return 'A';
case 'C':
case 'c':
return 'G';
case 'G':
case 'g':
return 'C';
}
return $nt;
}
function tabelaEstatistica($genopar, $mtg, $contig, $ini, $fim, $COGcolor){
$size = $fim - $ini + 1;
$rRNA=0;
$ORF = array(
'Total' => 0,
'Valid' => 0,
'Pending' => 0,
'Hypothetical' => 0,
'Conserved Hypothetical' => 0
);
$q = " SELECT
a.id,
a.validation,
v.status
FROM
orf o,
anotacao a,
validation v
WHERE
o.idMontagem='$mtg' AND
a.idMontagem='$mtg' AND
o.contigId='$contig' AND
o.id=a.id AND
a.validation=v.code AND
a.validation>0 AND
o.start>=$ini AND
o.start<=$fim AND
o.end<=$fim AND
o.end>=$ini
";
$n = $genopar->queryBanco($q);
$ORF['Total'] = $n;
while ($lin = $genopar->getArray()){
$ORF[$lin['status']]++;
}
$basesCount = array('A' => 0,'C' => 0,'T' => 0,'G' => 0);
$fcontig="../Fasta/$mtg/Contigs/n/Contig".$contig.".fas";
if ( !(is_readable($fcontig)) )
$genopar->error(" N�o foi poss�vel ler contig do arquivo: $fcontig ");
$file = fopen($fcontig, 'r');
$line = fgets($file, 4096); #Eliminar primeira linha
for ($linha= 1; !feof($file); $linhas++){
$line = trim(fgets($file, 4096));
$seq .= $line;
}
if (!$ini)
$ini++;
$seq = substr($seq, $ini-1, $size);
$windowSize = 100000;
$arrayPartialSeqs = str_split($seq, $windowSize);
foreach($arrayPartialSeqs as $partialSeq){
$bases = str_split($partialSeq);
foreach ($bases as $b){
$b = strtoupper($b);
if ($b=='A' || $b=='C' || $b=='G' || $b=='T')
$basesCount[$b]++;
}
}
$gc = (($basesCount['C'] + $basesCount['G'])/$size * 100)."%";
$q = "
SELECT count(tRNAnum) as n
FROM
tRNA
WHERE
idMontagem='$mtg' AND
contigId='$contig'
";
$n = $genopar->queryBanco($q);
$lin = $genopar->getArray();
$tRNA = $lin['n'];
echo "";
echo "";
echo "";
echo "Contig #$contig";
echo " ";
echo " ";
echo "";
echo "";
echo "Size";
echo " ";
echo "";
echo $size." bp";
echo " ";
echo "";
echo "Annotated ORF's";
echo " ";
echo "";
echo "Additional Information";
echo " ";
echo " ";
echo "";
echo "";
echo "Bases";
echo " ";
echo "A: ";
echo $basesCount['A'];
echo " ";
echo "";
echo "C: ";
echo $basesCount['C'];
echo " ";
echo "";
echo "Valid: ";
echo $ORF['Valid'];
echo " ";
echo "";
echo "Pending: ";
echo $ORF['Pending'];
echo " ";
echo "";
echo "tRNAs: ";
echo "$tRNA";
echo " ";
echo " ";
echo "";
echo "";
echo "G: ";
echo $basesCount['G'];
echo " ";
echo "";
echo "T: ";
echo $basesCount['T'];
echo " ";
echo "";
echo "Hypothetical: ";
echo $ORF['Hypothetical'];
echo " ";
echo "";
echo "Conserved Hyp.: ";
echo $ORF['Conserved Hypothetical'];
echo " ";
echo "";
echo "rRNAs: ";
echo "$rRNA";
echo " ";
echo " ";
echo "";
echo "";
echo "GC%";
echo " ";
echo "";
echo number_format($gc,2,",",",")."%";
echo " ";
echo "";
echo "Total: ";
echo $ORF['Total'];
echo " ";
echo "";
echo "Colors Code ";
echo " ";
echo " ";
echo "
";
}
function tabelaContigs($genopar, $mtg){
$genopar->abreBanco();
$q = " SELECT
c.id,
c.tam,
count(a.id) as ORFs
FROM
contig c,
orf o,
anotacao a
WHERE
c.idMontagem='$mtg' AND
o.idMontagem=c.idMontagem AND
a.idMontagem=o.idMontagem AND
c.id = o.contigId AND
o.id = a.id
GROUP BY
o.contigId
";
$n = $genopar->queryBanco($q);
if ($n > 0){
while ($lin = $genopar->getArray(MYSQL_ASSOC)){
$contig[$lin['id']] = $lin;
$contig[$lin['id']]['tRNAs'] = 0;
$contig[$lin['id']]['rRNAs'] = 0;
}
$q = "
SELECT
contigId as id,
count(tRNAnum) as n
FROM
tRNA
WHERE
idMontagem='$mtg'
GROUP BY
contigId
";
$genopar->queryBanco($q);
while ($lin = $genopar->getArray())
$contig[$lin['id']]['tRNAs'] = $lin['n'];
echo "'$mtg' Assembly Contigs ";
echo "";
echo "";
echo "";
echo "Contig Id ";
echo "Size ";
echo "Total ORF's ";
echo "tRNA's ";
echo "rRNA's ";
echo " ";
echo " ";
$color[0] = '#CCCCEE';
$color[1] = '#DDDDFF';
$i=0;
echo "";
foreach($contig as $id => $info){
$contigLink = "index.php?mtg=$mtg&contig=$id&geraFrames=1&processa=Graphic";
echo "";
echo "$id ";
echo "".$info['tam']." ";
echo "".$info['ORFs']." ";
echo "".$info['tRNAs']." ";
echo "".$info['rRNAs']." ";
echo " ";
}
echo " ";
echo "
";
}
}
?>