\n";
echo "
\n";
echo "Other Names |
\n";
echo "
";
echo "";
echo "
\n";
while( $row = pg_fetch_row( $other_names ) )
{
printf("%s |
\n", $row[0]);
$total ++;
}
if ($total == 0) echo "No Other Names found. |
\n";
echo "
";
}
function ReadChildren($result_tax)
{
$total = 0;
echo "\n";
$flag = 0;
echo "
\n";
echo "Children |
\n";
echo "
";
while($row = pg_fetch_row( $result_tax ))
{
if($flag == 0)
{
echo "";
echo "
\n";
$flag = 1;
}
$tax_name = rawurlencode($row[6]);
$link = "taxon.php?Info=GetDetail&taxon_id=$row[5]&colum=$row[7]";
printf("%s |
\n", $link, $row[6]);
}
if ($flag == 1)
echo "
";
else
{
echo "
\n";
echo "Not found\n";
}
}
function ReadSequneces($dna, $rna, $aa, $t_dna, $t_rna, $t_aa)
{
$flag = 0;
$count = 0;
echo "\n";
$index = 0;
sort($dna);
sort($rna);
sort($aa);
while($dna[$index])
{
$row = $dna[$index];
if($index == 0)
{
echo "DNA Sequences : $t_dna\n";
echo "\n";
echo "
\n";
$i = 1;
$flag = 1;
}
$link ="genome.php?Info=details&NcbiID=$dna[$index]";
if( $count == 0 )
echo "\n";
echo"$dna[$index] | \n";
// printf ("%s | \n", $link , $dna[$index]);
$count++;
if( $count >=4 )
{
echo "
\n";
$count = 0;
}
$index++;
}
if( $count != 0 )
{
while( $count < 4 )
{
echo " | \n";
$count++;
}
echo "\n";
}
echo "
";
$count = 0;
$index = 0;
while($rna[$index])
{
if($index == 0)
{
echo "\n";
echo "RNA Sequences :$t_rna\n";
echo "
\n";
echo "
\n";
$flag = 1;
}
$link ="genome.php?Info=details&NcbiID=$rna[$index]";
if( $count == 0 )
echo "\n";
echo "$rna[$index] | \n";
//printf ("%s | \n", $link ,$rna[$index]);
$count++;
if( $count >=4 )
{
echo "
\n";
$count = 0;
}
$index++;
}
if( $count != 0 )
{
while( $count < 4 )
{
echo " | \n";
$count++;
}
echo "\n";
}
echo "
";
$count = 0;
$index = 0;
while($aa[$index])
{
$total++;
if($index == 0)
{
echo "\n";
echo "Protein Sequences :$t_aa\n";
echo "
\n";
echo "
\n";
$flag = 1;
}
$link ="genome.php?Info=details&NcbiID=$aa[$index]";
if( $count == 0 )
{
echo " \n";
}
/* ------------------- change 2004-12-21 show gene_name ------------------------------------------------------------------ */
// $gene_name ="protein";
$sql_name = "select gene_name from gene_class, extprot where gene_class.gene_id=extprot.gene_id and extprot.gi=$aa[$index]";
$result_name = FetchFromGOBASE( $sql_name,1 );
$row_name = pg_fetch_row($result_name);
$gene_name = trim($row_name[0]);
echo"$aa[$index] ($gene_name) | \n";
// echo"$aa[$index] | \n";
//printf ("%s | \n", $link ,$aa[$index]);
$count++;
if( $count >=4 )
{
echo "
\n";
$count = 0;
}
$index++;
}
if( $count != 0 )
{
while( $count < 4 )
{
echo " | \n";
$count++;
}
echo "\n";
}
echo "
";
if($flag == 0)
{
echo "
\n";
echo "Not found\n";
}
}
/* Display results on HTML page, often there are hundreds of results generated by
query so display only 100 results at a time. To display the remainder of results
create page links at bottom of page
*/
function DisplayTaxonQueryResults( $Title, $values, $sql, $total_rows, $table, $condition, $page)
{
// if ($total_rows == 0) display_message(1,"Your search produced no results !");
/* ------------------- change here, before show error, get $total_rows -------------------------------------- */
$tax_result = FetchFromGOBASE($sql, 1);
$total_rows = pg_num_rows($tax_result);
($page ==1) ? $count=1 : $count=(($page-1)*100)+1;
$last_entry = $total_rows - $count;
($last_entry >= 100) ? $last_entry = $count+99 : $last_entry = $last_entry+$count;
$cmp_values = explode (',', $values);
// $tax_result = FetchFromGOBASE($sql, 1);
$table = rawurlencode( $table);
if($condition != "") $condition = rawurlencode($condition);
//generate header information
GOBASEHeader($Title, $WhichPHP);
echo "Query Results
";
//Start to display data
echo "
\n";
echo "\n";
echo " Total Number of Entries: $total_rows | \n";
if ($total_rows > 100)
echo " Displayed Entries $count to $last_entry on page $page | \n";
echo "
\n";
echo "
\n";
echo "\n";
echo "Number | \n";
echo " Tax Name | \n";
echo " Tax Rank | \n";
echo "
\n";
$odd = 1;
$row_count = 1;
//iterate through data and display
while ($row = pg_fetch_row($tax_result))
{
if($row_count >= $count)
{
$color = ($odd) ? "#ddddff" : "#D3DCE3";
$tax_id = $row[0];
$TaxName = rawurlencode( $row[1] );
$taxon_link =
"taxon.php?Info=GetDetail&taxon_id=$tax_id&colum=$row[3]";
printf( "%d | " .
"%s | %s |
\n",
$color, $count, $taxon_link , $row[1], $row[2] );
$odd = ($odd==1) ? 0 : 1;
//display links to extra pages
if ($row_count == $last_entry)
{
echo "
";
if ($total_rows < 100) break;
//prepare arguments to be passed
$criteria = rawurlencode($criteria);
$FromTables = rawurlencode($FromTables);
$TableJoins = rawurlencode($TableJoins);
$i = 0;
$previouspage = $page-1;
if ($page > 11 && ($total_rows/100 > 20))
$page_number = $page - 10;
else
$page_number = 1;
if ($previouspage == 0)
echo "previous page";
else
echo "previous page\n";
echo "";
/* ------------ change here, $total_page,
, for loop ------------------------------------------------------- */
$total_page = ceil($total_rows/100);
echo "";
// $total = 0;
// while ($cmp_values[$i])
for ($page_number=1; $page_number<=$total_page; $page_number++)
{
// if( $total ==20 )
// break;
// $total ++;
$mod = fmod($page_number, 20); //each show only 20 page links
if ($mod==1) {
echo "
\n";
}
if ($page_number == $page )
echo "$page | " ;
else
{
echo "$page_number | \n";
}
if ($page_number == 1);
else
$i++;
// $page_number++;
}
echo "
";
echo "";
$nextpage = $page+1;
if ($nextpage == $page_number) echo "next page";
else
echo "next page\n";
break;
}
$count ++;
}
$row_count++;
}
echo "
\n";
}
function DisplayDetailResults($taxon_id, $tax_name,$rank, $GOdiv_id, $parent_tax_id, $parent_tax_name, $parent_col)
{
if( $GOdiv_id != 0 )
{
$TaxonDiv = "select GOdiv_name from GOdivision where GOdiv_id = $GOdiv_id";
$result = FetchFromGOBASE($TaxonDiv, 1);
$row = pg_fetch_row($result);
$Taxon_division = $row[0];
}
if( $MGC_id != "" )
{
$CodeName = "select name from genecode where GC_id = $MGC_id";
$result = FetchFromGOBASE($CodeName, 1);
$row = pg_fetch_row($result);
$Mito_code = $row[0];
}
$MapValue = "select substr(url,38) from map where tax_id = $taxon_id";
$result = FetchFromGOBASE($MapValue, 1);
$row = pg_fetch_row($result);
$Map_URL = $row[0];
$PIDValue = "select PIDurl from PIDlink where tax_id = $taxon_id";
$result = FetchFromGOBASE($PIDValue, 1);
$row = pg_fetch_row($result);
$PID_URL = $row[0];
$tax_name = str_replace("\\", "", $tax_name);
echo "Taxon $tax_name
\n";
echo "\n";
$odd=0;
$color = ($odd) ? "#D3DCE3" : "#ddddff" ;
if($Taxon_division != "n/a") {
echo "Taxon Division: | $Taxon_division |
\n";
$odd = (!$odd) ? 1 : 0;
$color = ($odd) ? "#D3DCE3" : "#ddddff" ;
}
if($rank != "") {
echo "Rank: | $rank |
\n";
$odd = (!$odd) ? 1 : 0;
$color = ($odd) ? "#D3DCE3" : "#ddddff" ;
}
if($tax_name != "") {
echo "Taxon name: | $tax_name |
\n";
$odd = (!$odd) ? 1 : 0;
$color = ($odd) ? "#D3DCE3" : "#ddddff" ;
}
if($GOtaxon_id != 0) {
echo "GOBASE Id: | $GOtaxon_id |
\n";
$odd = (!$odd) ? 1 : 0;
$color = ($odd) ? "#D3DCE3" : "#ddddff" ;
}
if($Mito_code != "") {
echo "Mitochondrial genetic code: | $Mito_code |
\n";
$odd = (!$odd) ? 1 : 0;
$color = ($odd) ? "#D3DCE3" : "#ddddff" ;
}
$Dec_Parent_name = rawurlencode($parent_tax_name);
if(( $parent_tax_id != "" )&&($parent_col > 2))
{
$anchor = "$parent_tax_name";
}
else
{
$anchor = "$parent_tax_name";
}
if($anchor != "n/a") {
echo "Parent Name: | $anchor |
\n";
$odd = (!$odd) ? 1 : 0;
$color = ($odd) ? "#D3DCE3" : "#ddddff" ;
}
if($Map_URL != "") {
echo "Map URL: | $Map_URL |
\n";
$odd = (!$odd) ? 1 : 0;
$color = ($odd) ? "#D3DCE3" : "#ddddff" ;
}
//if ($PID_URL == "n/a") echo "PID URL: | $PID_URL |
\n";
//else
if($PID_URL != "")
{
echo "PID URL: | $PID_URL |
\n";
}
echo "
\n";
}
if( $_POST['Search'] == "seq" )
{ global $query;
$TaxonScientificName = $_POST['TaxonScientificName'];
add_query_string($TaxonScientificName,"Taxon name",$query);
$TaxonDiv = $_POST['TaxonDiv'];
if($TaxonDiv != '')
{
$tmp = implode(" or ", $TaxonDiv);
add_query_string($tmp,"Taxon division",$query);
}
$GobaseId = $_POST['GobaseId'];
add_query_string($GobaseId,"Taxon ID",$query);
$Rank = $_POST['Rank'];
if($Rank != '')
{
$tmp = implode(" or ", $Rank);
add_query_string($tmp,"Rank",$query);
}
$Map = $_POST['Map'];
if($Map != ''){
$tmp = ($Map==1)?"yes":"no";
add_query_string($tmp,"Map available",$query);
}
$PIDrec = $_POST['PIDrec'];
if($PIDrec != ''){
$tmp = ($PIDrec==1)?"yes":"no";
add_query_string($tmp,"PID record available",$query);
}
$dataSource = $_POST['dataSource'];
add_query_string($dataSource,"Data source",$query);
// WriteSQL();
$x = array();
$y = array();
$y[] = "tax_names";
$y[] = "rank_assign";
$x[] = " trim(tax_names.tax_rank) = trim(rank_assign.tax_rank) " ;
$null_flag_advance = 0;
if( !empty( $TaxonScientificName ))
{
if(strchr($TaxonScientificName, "*"))
{
$val = str_replace("*", "%", $TaxonScientificName);
$x[] = " TRIM(upper(tax_names.alt_name)) like TRIM(upper('$val')) ";
}
else
{
$x[] = " TRIM(upper(tax_names.alt_name)) = trim(upper('$TaxonScientificName')) ";
}
// echo"*****************\n";
}
if( sizeof($TaxonDiv) )
{
$y[] = "GOdivision";
$x[] = " GOdivision.GOdiv_id = tax_names.GOdiv_id ";
$r = implode("' or GOdivision.GOdiv_name = '",$TaxonDiv);
$x[] = "( GOdivision.GOdiv_name = '$r' )";
}
if( !empty( $GobaseId ) )
{
$x[] =" tax_names.tax_id = $GobaseId ";
}
if( sizeof($Rank) )
{
$r = implode("' or tax_names.tax_rank = '",$Rank);
$x[] = "( tax_names.tax_rank = '$r' )";
}
if( $Map == "1")
{
$y[] = " map ";
$x[] = " map.tax_id = tax_names.tax_id ";
}
if( $PIDrec == "1")
{
$y[] = " pidlink ";
$x[] = " pidlink.tax_id = tax_names.tax_id ";
}
if( !empty( $dataSource ))
{
$x[] = " tax_names.data_source like '%$dataSource%' ";
}
//else
//{
// $x[] = " tax_names.data_source is not null ";
//}
$n = sizeof( $y );
//if there are any extra tables, then create a string, but if not
//then just use default value
if( $n > 1 )
{
$table = implode( ", ", $y );
}
else
{
$table = $y[0];
}
//build sql statment with user selected
$n = sizeof( $x );
if( $n == 0)
display_message(1,"Error: No Search Criteria Specified!!!");
else
$condition = " where " . implode( " and ", $x );
//CheckError($criteria, $Special);
if($sort == 0)
{
$condition = $condition ." order by tax_names.master_name ";
}
else
{
$condition = $condition ." order by rank_assign.rank_no ";
}
$sql = "select distinct(tax_names.tax_id), tax_names.master_name, tax_names.tax_rank, tax_names.use_col, rank_assign.rank_no from $table$condition ";
SetTaxonCount($sql);
//echo"****$sql*****\n";
$page = 1;
if( $total_rows == 0 ) display_message_query(1,"Your search produced no results !",$query);
DisplayTaxonQueryResults( $Title, $values, $sql, $total_rows, $table, $condition, $page);
include( "../common/footer.php" );
exit;
}
if( $_GET['Search'] == "displaynext")
{
$condition = $_GET['condition'];
$table = $_GET['table'];
$page = $_GET['page'];
$Title = $_GET['Title'];
$values = $_GET['values'];
$total_rows = $_GET['total_rows'];
$cmp_values = explode (',', $values);
$condition = str_replace("\\", "", $condition);
$sql = "select distinct(tax_names.tax_id), tax_names.master_name, tax_names.tax_rank, tax_names.use_col, rank_assign.rank_no from $table$condition ";
// echo"****$sql*****\n";
DisplayTaxonQueryResults( $Title, $values, $sql, $total_rows,
$table, $condition, $page);
include( "../common/footer.php" );
exit;
}
if($_POST['Info'] == "downloadALL" )
{
$str_dna = $_POST['str_dna'];
$str_rna = $_POST['str_rna'];
$str_aa = $_POST['str_aa'];
$t_dna = $_POST['t_dna'];
$t_rna = $_POST['t_rna'];
$t_aa = $_POST['t_aa'];
//header( "Content-Type:text" );
header("Content-Type: application/");
header("Content-Disposition: attachment; ");
$formatted_dna = (strlen($str_dna)>0) ?
$str_dna:
"No sequence.";
echo "DNA sequence gi : $t_dna\n";
echo "$formatted_dna\n";
echo "\n";
$formatted_rna = (strlen($str_rna)>0) ?
$str_rna :
"No sequence.";
echo "RNA sequence gi : $t_rna\n";
echo "$formatted_rna\n";
echo "\n";
$formatted_aa = (strlen($str_aa)>0) ?
$str_aa :
"No sequence.";
echo "Protein sequence gi : $t_aa\n";
echo "$formatted_aa\n";
echo "\n";
exit;
}
if ($_GET['Info'] == GetDetail)
{
//GetValues($taxon_id, $colum) ;
$colum = $_GET['colum'];
$taxon_id = $_GET['taxon_id'];
$parent_col = $colum -1;
$child_col = $colum + 1;
$res = FetchFromGOBASE(" select master_name, tax_rank, GOdiv_id, use_col,min_order, max_order from tax_names where tax_id = $taxon_id " ,1);
$row = pg_fetch_row( $res );
$tax_name = $row[0];
$rank = $row[1];
$GOdiv_id = $row[2];
if( $colum == "")
$colum = $row[3];
$parent_col = $colum -1;
$child_col = $colum + 1;
$min_taxID = $row[4];
$max_taxID = $row[5];
$SqlID = "select distinct(tax_id_col$child_col), tax_col$child_col, tax_id_col$parent_col, tax_col$parent_col from tax_lineage where tax_id_col$colum = $taxon_id";
$result_tax = FetchFromGOBASE($SqlID, 1);
$flag = 0;
$child = 0;
GOBASEHeader($Title, $WhichPHP);
while($row = pg_fetch_row( $result_tax ))
{
if($flag == 0)
{
$parent_tax_id = $row[2];
$parent_tax_name = $row[3];
$flag = 1;
DisplayDetailResults($taxon_id,$tax_name,$rank, $GOdiv_id,$parent_tax_id, $parent_tax_name, $parent_col);
echo "\n";
echo "Children |
\n";
echo "
";
}
if(($row[0] != '') && ($child == 0))
{
echo "";
echo "
\n";
$child = 1 ;
}
$link = "taxon.php?Info=GetDetail&taxon_id=$row[0]&colum=$child_col";
printf("%s |
\n", $link, $row[1]);
}
if ($child == 1)
echo "
";
else
{
echo "
\n";
echo "No children\n";
}
//ReadChildren($result_tax);
$OtherNames = "select distinct(alt_name) from tax_names where trim(UPPER(alt_name)) != trim(UPPER('$tax_name')) and trim(UPPER(master_name)) in ".
"(select trim(UPPER(master_name)) from tax_names where trim(UPPER(alt_name)) = trim(UPPER('$tax_name')) ) order by alt_name";
$other_names = FetchFromGOBASE($OtherNames, 1);
ReadNames($other_names);
echo "
";
$whole_tax = array();
$tax_id = array();
$whole_dna = array();
$whole_rna = array();
$whole_aa = array();
$t_dna = 0;
$t_rna = 0;
$t_aa = 0;
if($min_taxID == $max_taxID)
$sql_gi = "select seq_id, mol from sequence where tax_order = $min_taxID ";#changed from gi to seq_id on march 2010
else
$sql_gi = "select seq_id, mol from sequence where tax_order >= $min_taxID and tax_order <= $max_taxID order by gi ";#changed from gi to seq_id on march 2010
$result_gi = FetchFromGOBASE($sql_gi, 1);
while( $row = pg_fetch_row( $result_gi ) )
{
if( strtoupper(trim($row[1])) == 'DNA')
{
$whole_dna[] = $row[0];
}
else if( strtoupper(trim($row[1])) == 'RNA')
{
$whole_rna[] = $row[0];
}
else
$whole_aa[] = $row[0];
}
$t_dna = count($whole_dna);
$t_rna = count($whole_rna);
$t_aa = count($whole_aa);
/*
while($row = pg_fetch_row( $result_tax ) )
{
$tax_id[] = $row[0];
}
$size_tax = count($tax_id);
if( $size_tax > 500)
{
$whole_tax = array();
$result_seq = FetchFromGOBASE("select gi, tax_id, mol from sequence where tax_id != '' and gi>0 order by gi",1);
while($row = pg_fetch_row( $result_seq ) )
{
$x = $whole_tax[$row[1]];
$whole_tax[$row[1]] = $x ."-".$row[0].".".$row[2];
}
$i = 0;
while( $tax_id[$i] )
{
$index = $tax_id[$i];
$gi = $whole_tax[$index];
if($gi != '')
{
$gi_ary = explode("-", $gi);
$count = 1;
while($gi_ary[$count])
{
$total++;
$x = explode(".", $gi_ary[1]);
if( stristr($x[1], "dna" ))
{
$whole_dna[] = $x[0];
$t_dna++;
}
else if( stristr(trim($x[1]), "rna" ))
{
$whole_rna[] = $x[0];
$t_rna++;
}
else
{
$whole_aa[] = $x[0];
$t_aa++;
}
$count++;
}
}
$i++;
}
}
else
{
$taxid_str = implode(',', $tax_id);
$whole_gi = array();
$result_seq = FetchFromGOBASE("select gi, tax_id, mol from sequence where tax_id != '' and gi>0 order by gi",1);
while($row = pg_fetch_row( $result_seq ) )
{
if( stristr($taxid_str,trim($row[1]) ) != "")
{
if( stristr($row[2], "dna") )
{
$whole_dna[] = $row[0];
$t_dna++;
}
else if(stristr($row[2], "rna"))
{
$whole_rna[] = $row[0];
$t_rna++;
}
else
{
$whole_aa[] = $row[0];
$t_aa++;
}
}
}
}
*/
echo "\n";
$str_dna = implode(' ', $whole_dna);
$str_rna = implode(' ', $whole_rna);
$str_aa = implode(' ', $whole_aa);
echo"
\n";
ReadSequneces($whole_dna, $whole_rna, $whole_aa, $t_dna, $t_rna, $t_aa);
include( "../common/footer.php" );
exit;
}
GOBASEHeader($Title, $WhichPHP);
?>