#!/bin/perl -w

use strict;

#use CGI;
use CGI qw(:standard *table *TR *th *td *ul *ol);
use Gramene::GetProteinData; 
use GramenePage; 


my $page_title = "Protein page";
my $q = CGI->new();
my $page = GramenePage->new(Apache->request);

my $table_only = $q->param("table");

unless( ( $table_only ) && ( $table_only eq "1" ) ) {

print $q->header;

print $q->start_html( -title=>$page_title,
		      -style=>{'src'=>$page->stylesheet}
		    );
print $page->start_body();


########################
print("<center><h1>Rice Protein Database</h1></center>" );

print $q->table( {-border=>'0',
		  -cellspacing=>'0',
		  -cellpadding=>'3',
		  -width=>'98%',
                  -align=>'CENTER'},
		 $q->start_form(),

                 $q->Tr( {-align=>'CENTER', -nowrap=>'nowrap'},
	             
			 $q->th( {-align=>'CENTER',
				  -class=>'searchtitle'},
			         "Protein Database Search" )
		
		       ),
		 $q->Tr( {-align=>'CENTER',
			  -valign=>'CENTER',
			  -nowrap=>'nowrap',
			  -class=>'searchbody'},
			 $q->td( {-align=>'CENTER'},
				 $q->checkbox(-name=>'wild_card',
						     -checked=>0,
						     -value=>'ON',
						     -label=>' Wildcards On'),
				 
				 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",
				 $q->textfield( -name=>'word',
						-size=>30,
						-maxlength=>60 ),
				 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",
                                 $q->submit( -name=>'do_it',
					     -value=>'Search' ),
				 $q->p( "&nbsp;&nbsp;&nbsp;Search by Acc, SPTrEMBL ID, name, gene name, organism.&nbsp;[ e.g.",
					$q->a( {-href=>"/perl/protein_search?word=P93436"}, "P93436" ),
					",&nbsp;",
					$q->a( {-href=>"/perl/protein_search?word=alcohol"}, "alcohol" ),
					",&nbsp;",
                                        $q->a( {-href=>"/perl/protein_search?word=indica"}, "indica" ), "]" ) )
			
			),
		 
		
		
		 $q->end_form() );


###########################


unless( $q->param("word") || $q->param("protein_id") || $q->param("swall") || $q->param("acc") ) {

print <<FRONTPAGE;
<hr>
<center><h2>Rice Protein Database Release 5.0.0, April 26, 2002</h2></center>
<table border="0" cellspacing="0" cellpadding="0" width="98%" align="CENTER"><tr align="CENTER"><td align="CENTER"> 
  <ul>
    <li><span class="alert">Rice to Gene Ontology Associations: <a href="ftp://www.gramene.org/pub/gramene/protein/gene_association.gramene_oryza">Associations</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="ftp://www.gramene.org/pub/gramene/protein/gramene_oryza.README">README</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.geneontology.org/#annotations">GO Consortium</a></span><img src="/images/new.gif" alt="NEW"></li>
    <li><span class="alert">Want to find the proteins associated with a specific Ontology term? Try the <a href="/plant_ontology">Ontology Browser</a></span></li>
  </ul>  
</td></tr></table> 
<table border="0" cellspacing="0" cellpadding="0" width="98%" align="CENTER"><tr><td>  
<br><b>The</b> protein database at Gramene is an
attempt to provide collective information about the proteins from rice
(Oryza sp.). Effort has been made to provide a functional annotation of
the entries by associating the Gene Ontology (GO) terms that describe a
protein's molecular function, its role in a biological process and/or the
localization of the gene product at the sub cellular level. We further
enhances the quality of annotation by providing links to:
<ul>
<li>
<font face="Arial,Helvetica">The enzymes and pathways at the KEGG database
in Japan</font></li>

<li>
<font face="Arial,Helvetica">The associated protein signatures available
from InterPro and Prosite databases</font></li>

<li>
<font face="Arial,Helvetica">Classification as a member of a protein family
from the Pfam database</font></li>

<li>
<font face="Arial,Helvetica">Analyses of Physio-chemical features available
from ProtParam</font></li>

<li>
<font face="Arial,Helvetica">BLink to GenBank to identify homologs and
orthologs</font></li>

<li>
<font face="Arial,Helvetica">NCBI and the SAS (Sequence Annotated by Structure)
database at University College London to identify similarity to protein
3D structure.</font></li>
</ul>
<b>To</b> minimize incorrect preliminary identifications
based on genome prediction softwares and GenBank / EMBL submitted annotations,
Gramene curators use predefined <a href="http://www.gramene.org/plant_ontology/evidence_codes.html">EVIDENCE
CODES</a> to validate feature annotations, to distinguish experimental
from predicted data and discretely classify the data using significant
information from other databases of interest and from literature citations.</font>
<p><b>A</b> description of each field on a protein
page and the links to external databases are available in the <a href="http://www.gramene.org/documentation/protein_help.html">HELP
DOCUMENT</a>.
<p><b>You</b> can search the rice protein database
by typing either the full or abbreviated name of the protein or the GenBank / SWISS-PROT
Accession number, gene name or a keyword at <a href="http://www.gramene.org/perl/protein_search">http://www.gramene.org/perl/protein_search</a>.
<br>
<P><b>A</b> BLAST search for the rice proteins can
be performed at <a href="http://www.gramene.org/gramene/searches/blast">http://www.gramene.org/gramene/searches/blast</a>
<p><b>A</b> more comprehensive description of the
Gramene database can be found in the following paper:
<br><font face="Arial,Helvetica">Gramene: a resource for comparative grass
genomics; <a href="http://nar.oupjournals.org/cgi/gca?sendit=Get+All+Checked+Abstract%28s%29&SEARCHID=1010366452364_1564&FULLTEXT=gramene&VOLUME=30&ISSUE=1&JOURNALCODE=&FIRSTINDEX=0&hits=10&RESULTFORMAT=&gca=30%2F1%2F103">Nucleic
Acids Res. 30 (1), 103-105 (2002)</a></font>
<br><font face="Arial,Helvetica"><font size=-5>(Please cite this article
when the Gramene database assists you in published research)</font></font>
<br>&nbsp;
</td></tr></table>
FRONTPAGE

}


}

##############################

if( $q->param("word") ) {

    my $word = $q->param("word");

    my $wild_card = $q->param("wild_card");
    
    my $test_word = $word;
    $test_word  =~ tr/A-Z/a-z/;    #in lower case
    $test_word =~ tr/a-z//cd;     #delete non-letters

    if( $test_word ) {

        my $db = Gramene::GetProteinData->new();
        $db->connect_to_ora( );

        print $q->hr();

        my $original = $q->param("word");
        $word =~ tr/a-z/A-Z/;

        my $complete_result = $q->param("complete");
        if( $complete_result eq "1" ) {

            $wild_card = "OFF";
            my ( $id_ref, $acc_ref ) = $db->get_protein_complete( $word, $wild_card );

            display_list_simple( $q, $id_ref, $acc_ref );
        } else {

            $complete_result = 0;
            
            my ( $id_ref, $acc_ref, $sid_ref, $name_ref, $orga_ref, $code_ref, $part_result );

            ( $id_ref, $acc_ref, $sid_ref, $name_ref, $orga_ref, $code_ref, $part_result ) = $db->get_protein( $word, $wild_card, $complete_result );
            display_list( $q, $id_ref, $acc_ref, $sid_ref, $name_ref, $orga_ref, $code_ref, $original, $part_result );
        }
    }

}


#################

if( $q->param("protein_id") ) {

    my $id = $q->param("protein_id");
    print $q->hr();

    if( $id =~ /\D/ ) {
      
        print $q->table( {-border=>'0',
			  -cellpadding=>'2',
			  -width=>'98%',
			  -align=>'CENTER'},
			 $q->Tr( $q->th( {-class=>'resultstitle',
					  -align=>'CENTER'}, 
					 "Sorry, the protein id you entered is not valid. Please try again." ) ) );
    } else {

        my $db = Gramene::GetProteinData->new();
	$db->connect_to_ora( );

	my $pid = $db->validate_id( $id );
	if( $pid ) {
	  
	    display_detail( $q, $id, $db );
	} else {
	    
	    print $q->table( {-border=>'0',
			  -cellpadding=>'2',
			  -width=>'98%',
			  -align=>'CENTER'},
			 $q->Tr( $q->th( {-class=>'resultstitle',
					  -align=>'CENTER'}, 
					 "Sorry, the protein id you entered is not valid. Please try again." ) ) );
	}
    }
}


if( $q->param("acc") ) {

    my $db = Gramene::GetProteinData->new();
    $db->connect_to_ora( );

    my $acc = $q->param("acc");
    $acc =~ tr/a-z/A-Z/; 

    my $id ||= $db->get_id_by_acc( $acc ) if( $acc );
	#should be an error message if can't find
    print STDERR "ACC<$acc> id=$id\n";

    if( $id ) {
        print $q->hr();
        display_detail( $q, $id, $db );

    } else {

        print $q->hr();
        print $q->table( {-border=>'0',
			  -cellpadding=>'2',
			  -width=>'98%',
			  -align=>'CENTER'},
			 $q->Tr( $q->th( {-class=>'resultstitle',
					  -align=>'CENTER'}, 
					 "Sorry, the Accession number you entered is not valid. Please try again." ) ) );
    }
        

}


if( $q->param("swall") ) {

    my $db = Gramene::GetProteinData->new();
    $db->connect_to_ora( );

    my $swall= $q->param("swall");
    $swall =~ tr/a-z/A-Z/; 

    my $id ||= $db->get_id_by_swall ( $swall) if($swall);
	#should be an error message if can't find
    print STDERR "SWALL<$swall> id=$id\n";

    if( $id ) {
        print $q->hr();
        display_detail( $q, $id, $db );

    } else {
        
        print $q->hr();
        print $q->table( {-border=>'0',
			  -cellpadding=>'2',
			  -width=>'98%',
			  -align=>'CENTER'},
			 $q->Tr( $q->th( {-class=>'resultstitle',
					  -align=>'CENTER'}, 
					 "Sorry, the SWALL ID you entered is not valid. Please try again." ) ) );
    }
  
}



###########################
#print $page->end_body;

unless( ( $table_only ) && ( $table_only eq "1" ) ) {

    print $page->end_body;

}

################


sub display_list {

    my ( $q, $id_ref, $acc_ref, $sid_ref, $name_ref, $orga_ref, $code_ref, $original, $part_result ) = @_;
    my @ids = @$id_ref;
    my @names = @$name_ref;
    my @accs = @$acc_ref;
    my @sids = @$sid_ref;
    
    my @orgas = @$orga_ref;
    my @codes = @$code_ref;

    

    unless( (scalar @ids) == 0 ) {
      foreach my $name ( @names ) {
	  $name =~ s/   /; /g;
	  $name =~ s/($original)/<span class='matching'>$1<\/span>/ig;
      }
      foreach my $acc ( @accs ) {
	  $acc =~ s/($original)/<span class='matching'>$1<\/span>/ig;
      }
      foreach my $sid ( @sids ) {
	  $sid =~ s/($original)/<span class='matching'>$1<\/span>/ig;
      }
      
      foreach my $orga ( @orgas ) {
	  my @parts = split( /   /, $orga );
	  $orga = "<i>".$parts[0]."</i>"." (".$parts[1].", ".$parts[2].")";
	  $orga =~ s/($original)/<span class='matching'>$1<\/span>/ig;
      }
      foreach my $code ( @codes ) {
	  my @parts = split( / /, $code );
	  foreach my $p ( @parts ) {
	      $p = "<a href=\"/plant_ontology/evidence_codes.html#$p\">".$p."</a>";
	  }
	  $code = join( " ", @parts );
      }
      
    }

    if( (scalar @ids) == 0 ) {

        print $q->table( {-border=>'0',
			  -cellpadding=>'2',
			  -width=>'98%',
			  -align=>'CENTER'},
			 $q->Tr( $q->th( {-class=>'resultstitle',
					  -align=>'CENTER'}, 
					 "Sorry, no matching records have been found." ) ) );
    } else {

        #print( "<center><h1>Protein Search Result for <i>".$original."<i></h1></center>" );

        
        if( (scalar @ids) == 1 ) {

	    print $q->table( {-border=>'0',
			      -cellpadding=>'2',
			      -width=>'98%',
			      -align=>'CENTER'},
			     $q->Tr( $q->th( {-class=>'resultstitle',
					      -align=>'CENTER'}, 
					     "1 matching record has been found." ) ) );
	} else {

	    if( $part_result ) {

	        my $string = "More than 500 matching records have been found.<br>But only the first 500 records are displayed."
                   ."<br>To see all the matching records, please <a href=\"/perl/protein_search?word=$original&complete=1\">click here</a>."; 

	        print $q->table( {-border=>'0',
				  -cellpadding=>'2',
				  -width=>'98%',
				  -align=>'CENTER'},
				 $q->Tr( $q->th( {-class=>'resultstitle',
						  -align=>'CENTER'}, 
						 $string ) ) ); 
	    } else {
	  
	        print $q->table( {-border=>'0',
				  -cellpadding=>'2',
				  -width=>'98%',
				  -align=>'CENTER'},
				 $q->Tr( $q->th( {-class=>'resultstitle',
						  -align=>'CENTER'}, 
						 (scalar @ids), " matching records have been found." ) ) );
	    }
	}

	print start_table( {-width=>'98%', -cellpadding=>'4', -border=>'1', -align=>'CENTER'} );
	print $q->Tr( $q->td( {-class=>'resultstitle',
			       -align=>'CENTER'}, "Accession No." ),
		      #$q->td( {-class=>'resultstitle',
			#       -align=>'CENTER'}, "SWALL ID" ),
		      $q->td( {-class=>'resultstitle',
			       -align=>'CENTER'}, "Names/Symbols" ),
		      $q->td( {-class=>'resultstitle',
			       -align=>'CENTER'}, "Organism (Subspecies, Cultivar)" ),
		      $q->td( {-class=>'resultstitle',
			       -align=>'CENTER'}, "Evidence codes" ) );

	for( my $i=1; $i<=(scalar @ids); $i++ ) {

	  if( ( $i % 2 ) == 1 ) {

	    print $q->Tr( {-valign=>'TOP'},
			  $q->td( {-class=>'resultsbody',
				   -align=>'CENTER'}, 
				   $q->a( {-href=>"/perl/protein_search?protein_id=$ids[$i-1]"}, $accs[$i-1] ) ), 
			  #$q->td( {-class=>'resultsbody',
			#	   -align=>'CENTER'}, $sids[$i-1] ),
			  $q->td( {-class=>'resultsbody',
				   -align=>'LEFT'}, $names[$i-1] ),
			  $q->td( {-class=>'resultsbody',
				   -align=>'LEFT'}, $orgas[$i-1] ),
			  $q->td( {-class=>'resultsbody',
				   -align=>'CENTER'}, $codes[$i-1] ) );
	  } else {
	    
	    print $q->Tr( {-valign=>'TOP'},
			  $q->td( {-align=>'CENTER'}, 
				   $q->a( {-href=>"protein_search?protein_id=$ids[$i-1]"}, $accs[$i-1] ) ), 
			  #$q->td( {-align=>'CENTER'}, $sids[$i-1] ),
			  $q->td( {-align=>'LEFT'}, $names[$i-1] ),
			  $q->td( {-align=>'LEFT'}, $orgas[$i-1] ),
			  $q->td( {-align=>'CENTER'}, $codes[$i-1] ) );
	  }
	
	}
	print end_table;
    }#End else

}
		
############################


sub display_list_simple {

    my ( $q, $id_ref, $acc_ref ) = @_;
    my @ids = @$id_ref;
    my @accs = @$acc_ref;
    
    print $q->table( {-border=>'0',
				  -cellpadding=>'2',
				  -width=>'98%',
				  -align=>'CENTER'},
				 $q->Tr( $q->th( {-class=>'resultstitle',
						  -align=>'CENTER'}, 
						 (scalar @ids), " matching records have been found." ) ) );

    print start_table( {-width=>'98%', -cellpadding=>'4', -border=>'1', -align=>'CENTER'} );
    #print $q->Tr( $q->td( {-class=>'resultstitle',
	#		       -align=>'CENTER'}, "Accession No." ) );
		    

    for( my $i=1; $i<=(scalar @ids); $i++ ) {

        if( ( $i % 10 ) == 1 ) {

	    print start_TR();
	    
	}
	print start_td( {-align=>'CENTER'} );
	print $q->a( {-href=>"/perl/protein_search?protein_id=$ids[$i-1]"}, $accs[$i-1] );
	#print ( "&nbsp;&nbsp;&nbsp;" );
	print end_td();
	if( ( $i == (scalar @ids) ) || ( ( $i % 10 ) == 0 ) ) {

	    
	    print end_TR();
	    
	}
    }

    
    print end_table;
  

}
		





#########################

sub display_detail {

    my ( $q, $gp_id, $db ) = @_;


    ###########################
print <<SMALLBARS;
<table align="CENTER">
  <tr>
    <td>&nbsp;<img src="/images/icons/grain_icon.jpg" alt="grain_icon" height=16 width=16 align="top">
    </td>
    <td>
      &nbsp;<b>[</b>&nbsp;<a href="#general" class="gopage"><b>General Information</b></a>&nbsp;<b>]</b>&nbsp;&nbsp;
      &nbsp;<b>[</b>&nbsp;<a href="#associations" class="gopage"><b>Associations</b></a>&nbsp;<b>]</b>&nbsp;&nbsp;
      &nbsp;<b>[</b>&nbsp;<a href="#similarity" class="gopage"><b>Similarity to Other Proteins</b></a>&nbsp;<b>]</b>&nbsp;&nbsp;
      &nbsp;<b>[</b>&nbsp;<a href="#references" class="gopage"><b>References</b></a>&nbsp;<b>]</b>&nbsp;&nbsp;
      &nbsp;<b>[</b>&nbsp;<a href="#comments" class="gopage"><b>Comments</b></a>&nbsp;<b>]</b>&nbsp;
      &nbsp;<b>[</b>&nbsp;<a target="help" href="/documentation/protein_help.html" class="gopage"><b>Help</b></a>&nbsp;<b>]</b>&nbsp;
    </td>
  </tr>
</table>
SMALLBARS
    ############################

    
    my $acc = $db->get_acc( $gp_id );
    my $symbol = $db->get_symbol( $gp_id );
    my $name = $db->get_names( $gp_id );
    
    my $ecs = $db->get_ecs( $gp_id );
    my $gns = $db->get_gns( $gp_id );
    
    my ( $genus, $spe, $taxa_id, $sub, $cul ) = $db->get_organisms( $gp_id ); 
    my $exp = $db->get_exp( $gp_id );

    my $tissue = $db->get_tissue( $gp_id );
    my $keyword = $db->get_keywords( $gp_id );
   
    my $swall = $db->get_swall( $gp_id );
    my $comment = $db->get_comment( $gp_id );
    
    my @gis = $db->get_gis( $gp_id ); 
    my $gi;
    if( @gis ) {
        $gi = $gis[0];
    }
    my $trans = $db->get_trans( $gp_id );
    my ( $pfam, $pfam_extra ) = $db->get_pfam( $gp_id );

    
    my $trembl_new = $db->get_trembl_new( $gp_id );
    
    print start_table( {-width=>'98%', -cellpadding=>'5', -border=>'0', -align=>'CENTER'} );

    print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'CENTER',
			   -colspan=>'4'}, 
			   "<a name=\"general\"></a>General Information about $acc" ) );

    print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'LEFT'}, "Name(s)" ),
		  $q->td( {-class=>'resultsbody',
			   -align=>'LEFT',
			   -colspan=>'3'}, $name ) );

    if( !( $ecs eq "Not available" ) ) {
        my @parts = split( /, /, $ecs );
	my $eclinks;
	foreach my $p ( @parts ) {
	    if( $eclinks ) {
	        $eclinks = $eclinks.", ".$q->a( {-target=>'ec_number', -href=>"http://www.genome.ad.jp/dbget-bin/www_bget?ec:$p"}, $p );
	    } else {
	        $eclinks = $q->a( {-target=>'ec_number', -href=>"http://www.genome.ad.jp/dbget-bin/www_bget?ec:$p"}, $p );
	    }
	}

	print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'LEFT'}, "E.C. Number(s)" ),
		  $q->td( {-class=>'resultsbody',
			   -align=>'LEFT',
			   -colspan=>'3'}, $eclinks ) );
    } else {
        
        print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'LEFT'}, "E.C. Number(s)" ),
		  $q->td( {-class=>'resultsbody',
			   -align=>'LEFT',
			   -colspan=>'3'}, "Not available" ) );
    }

    print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'LEFT'}, "Gene Name(s)" ),
		  $q->td( {-class=>'resultsbody',
			   -align=>'LEFT',
			   -colspan=>'3'}, "<i>", $gns, "</i>" ) );

    
   
        print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'LEFT',
			   -width=>'15%'}, "Symbol" ),
		  $q->td( {-class=>'resultsbody',
			   -align=>'LEFT',
			   -colspan=>'3'}, $symbol ) );


    ###############

     if( !( $trans eq "Not available" ) ) {
        my @parts = split( /, /, $trans );
	my $eclinks;
	foreach my $p ( @parts ) {
	    if( $eclinks ) {
	        $eclinks = $eclinks.", ".$q->a( {-target=>'genome_browser', -href=>"/perl/geneview?peptide=$p"}, $p );
	    } else {
	        $eclinks = $q->a( {-target=>'genome_browser', -href=>"/perl/geneview?peptide=$p"}, $p );
	    }
	}

	print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'LEFT'}, "Genome Browser" ),
		  $q->td( {-class=>'resultsbody',
			   -align=>'LEFT',
			   -colspan=>'3'}, $eclinks ) );
    } else {
        
        print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'LEFT'}, "Genome Browser" ),
		  $q->td( {-class=>'resultsbody',
			   -align=>'LEFT',
			   -colspan=>'3'}, "Not available" ) );
    }


   
    

    ################

    print start_TR();

        print $q->th( {-class=>'resultstitle',
		       -align=>'LEFT',
		       -rowspan=>"2"}, "Accession Numbers" );
        

        print $q->th( {-class=>'resultstitle',
		       -align=>'CENTER'}, "GenBank" );
	print $q->th( {-class=>'resultstitle',
		       -colspan=>'2',
		       -align=>'CENTER'}, "SWISS-PROT/TrEMBL" );
	#print $q->th( {-class=>'resultstitle',
		#       -align=>'CENTER'}, "SWALL" );

    print end_TR();

    ############
    my $genbank_link;
    if( @gis ) {
         
        foreach my $gii ( @gis ) {
	    if( $genbank_link ) {
	        $genbank_link = $genbank_link.",&nbsp;&nbsp;".$q->a( {-target=>'cross_reference', -href=>"http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=protein&list_uids=$gii&dopt=GenPept"}, $gii ); 
	    } else {
	        $genbank_link = $q->a( {-target=>'cross_reference', -href=>"http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=protein&list_uids=$gii&dopt=GenPept"}, $gii ); 
	    }
	}

    } else {
        $genbank_link = "Not available";
    }
                            


    #############

    if( $trembl_new ) {
        print $q->Tr( $q->td( {-class=>'resultsbody',
			       -align=>'CENTER'}, 
			      $genbank_link ),
		  $q->td( {-class=>'resultsbody',
			   -colspan=>'2',
			   -align=>'CENTER'}, 
			   "None" )#,
		  #$q->td( {-class=>'resultsbody',
			#   -align=>'CENTER',
			 #  -colspan=>'2'}, 
			  # $q->a( {-target=>'cross_reference', -href=>"http://srs.ebi.ac.uk/srs6bin/cgi-bin/wgetz?-id+1uEaX1HPoFg+-e+%5BSWALL:'$swall'%5D"}, 
                           #       $acc ) )
                     );
    } else {

    print $q->Tr( $q->td( {-class=>'resultsbody',
			   -align=>'CENTER'}, 
			  $genbank_link ),
		  $q->td( {-class=>'resultsbody',
			   -colspan=>'2',
			   -align=>'CENTER'}, 
			   $q->a( {-target=>'cross_reference', -href=>"http://us.expasy.org/cgi-bin/niceprot.pl?$acc"}, 
                                  $acc ) )#,
		  #$q->td( {-class=>'resultsbody',
			#   -align=>'CENTER',
			 #  -colspan=>'2'}, 
			  # $q->a( {-target=>'cross_reference', -href=>"http://srs.ebi.ac.uk/srs6bin/cgi-bin/wgetz?-id+1uEaX1HPoFg+-e+%5BSWALL:'$swall'%5D"}, 
                           #       $acc ) )
		 );

    }

    ################

    print start_TR();

        #my $orga_row = scalar( @organisms ) + 1;

        #print $q->th( {-class=>'resultstitle',
		#       -align=>'LEFT',
		 #      -rowspan=>"$orga_row"}, "Organism(s)" );
        print $q->th( {-class=>'resultstitle',
		       -align=>'LEFT',
		       -rowspan=>"2"}, "Organism(s)" );
        

        print $q->th( {-class=>'resultstitle',
		       -align=>'CENTER'}, "Species" );
	print $q->th( {-class=>'resultstitle',
		       -align=>'CENTER'}, "Subspecies" );
	print $q->th( {-class=>'resultstitle',
		       -align=>'CENTER'}, "Cultivar" );

    print end_TR();

    my $species_link; 
			   
    if( $taxa_id ) {
        $species_link = $q->a( {-target=>'ncbi', -href=>"http://www.ncbi.nlm.nih.gov/htbin-post/Taxonomy/wgetorg?mode=Info&id=$taxa_id&lvl=3&keep=1&srchmode=1&unlock"}, "<i>$genus $spe</i>" );
    } else {
        $species_link = "<i>".$genus." ".$spe."</i>";
    }

    my $sub_link;
    if( $sub =~ /Indica/i ) {
        $sub_link = $q->a( {-target=>'ncbi', -href=>"http://www.ncbi.nlm.nih.gov/htbin-post/Taxonomy/wgetorg?mode=Info&id=39946&lvl=3&keep=1&srchmode=1&unlock"}, "indica" );
    } elsif( $sub =~ /Japonica/i ) {
        $sub_link = $q->a( {-target=>'ncbi', -href=>"http://www.ncbi.nlm.nih.gov/htbin-post/Taxonomy/wgetorg?mode=Info&id=39947&lvl=3&keep=1&srchmode=1&unlock"}, "japonica" );
    }else {
        $sub_link = $sub;
    }


	    print $q->Tr( $q->td( {-class=>'resultsbody',
			   	   -align=>'CENTER'}, $species_link ),
			  $q->td( {-class=>'resultsbody',
			   	   -align=>'CENTER'}, $sub_link ),
			  $q->td( {-class=>'resultsbody',
			   	   -align=>'CENTER'}, $cul ) );


    ######################
    print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'CENTER',
			   -colspan=>'4'}, 
			   "<a name=\"associations\"></a>Associations" ) );

    my ( $asso_ref, $term_ref, $go_ref, $tid_ref ) = $db->get_associations( $gp_id );
    #if( $asso_ref ) {
        my @assos = @$asso_ref;
	my @terms = @$term_ref;
	my @gos = @$go_ref;
	my @tids = @$tid_ref;
	
    if( @assos ) {
	
	
	print $q->Tr( $q->th( {-class=>'resultstitle',
			       -align=>'CENTER'}, "Term Type" ),
		      $q->th( {-class=>'resultstitle',
			       -align=>'CENTER'}, "GO Term" ),
		      
		      $q->th( {-class=>'resultstitle',
			       -align=>'CENTER'}, "Evidence" ),
		      $q->th( {-class=>'resultstitle',
			       -align=>'CENTER',
			       -width=>'15%'}, "Evidence Code" ) );
	for( my $i=0; $i<=$#assos; $i++ ) {
	  
	    my ( $key_ref, $db_name_ref, $code_ref );
	    ( $key_ref, $db_name_ref, $code_ref ) = $db->get_evidences( $assos[$i] );
	    my @keys = @$key_ref;
	    my @db_names = @$db_name_ref;
	    my @codes = @$code_ref;

	    my ( @new_keys, @new_names, @new_codes );
	    $new_keys[0] = $keys[0];
	    $new_names[0] = $db_names[0];
	    $new_codes[0] = $q->a( {-target=>'term_page', -href=>"/plant_ontology/evidence_codes.html#$codes[0]"}, $codes[0] );
	    for( my $j=1; $j<=$#keys; $j++ ) {
	        my $is_new = 1;
		my $k = 0;
		while( ($is_new) && ($k<=$#new_keys) ) {
		    if( ( $keys[$j] eq $new_keys[$k] ) && ( $db_names[$j] eq $new_names[$k] ) ) {
		        $is_new = 0;
		    }
		    $k++;
		}
		if( $is_new ) {
		    @new_keys = ( @new_keys, $keys[$j] );
		    @new_names = ( @new_names, $db_names[$j] );
		    @new_codes = ( @new_codes, $q->a( {-target=>'term_page', -href=>"/plant_ontology/evidence_codes.html#$codes[$j]"}, $codes[$j] ) );
		} else {
		    $new_codes[$#new_codes] = $new_codes[$#new_codes].", ".$q->a( {-target=>'term_page', -href=>"/plant_ontology/evidence_codes.html#$codes[$j]"}, $codes[$j] );
		}
	    }#End for
		    
	    my $row_number = $#new_keys + 1;
	    my $t_type = $db->get_term_type( $tids[$i] );
	    my $type_name;
	    if( $t_type == 2 ) {
	        $type_name = $q->a( {-target=>'term_page', -href=>"/perl/ontology/search_term?id=GO:0008150"}, "Biological Process" );
	    } elsif( $t_type == 3 ) {
	        $type_name = $q->a( {-target=>'term_page', -href=>"/perl/ontology/search_term?id=GO:0005575"}, "Cellular Component" );
	    } elsif( $t_type == 4 ) {
	        $type_name = $q->a( {-target=>'term_page', -href=>"/perl/ontology/search_term?id=GO:0003674"}, "Molecular Function" );

	    }

	    print start_TR( {-valign=>'TOP'} );
	    print $q->td( {-class=>'resultsbody',
			   -align=>'LEFT',
			   -valign=>'TOP',
			   
			   -rowspan=>"$row_number"}, $type_name );
	    print $q->td( {-class=>'resultsbody',
			   -align=>'LEFT',
			   -valign=>'TOP',
			   
			   -rowspan=>"$row_number"}, 
			  $q->a( {-target=>'term_page', -href=>"/perl/ontology/search_term?id=$gos[$i]"}, $terms[$i] ) );

	    if( $new_names[0] eq "gramene.ontology.reference" ) {
	        my ( $x_key, $title, $source, $year, $volume, $start_page, $end_page ) = $db->get_ref( $new_keys[0] );
		#my $content = $title.", ".$source.", ".$year.", ".$volume.", ".$start_page."-".$end_page;
		print $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'},
			       "Gramene", "&nbsp;",
			       $q->a( {-target=>'reference', -href=>"/perl/pub_search?ref_id=$x_key"}, "Reference&nbsp;", $x_key ) );
	    } elsif( $new_names[0] =~ /interpro/i ) {
	        print $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'},
			       "InterPro", "&nbsp;",
			       $q->a( {-target=>'interpro', -href=>"http://www.ebi.ac.uk/interpro/IEntry?ac=$new_keys[0]"}, $new_keys[0] ) );
	    } else {
	        print $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'},
			       $new_names[0], ": ", $new_keys[0] );
	    }
	    print $q->td( {-class=>'resultsbody',
			   -align=>'LEFT',
			   -valign=>'TOP'}, 
			  $new_codes[0] );
	    print end_TR;

	    for( my $j=1; $j<=$#new_keys; $j++ ) {

	        print start_TR( {-valign=>'TOP'} );
	    
		if( $new_names[$j] eq "gramene.ontology.reference" ) {
	            my ( $x_key, $title, $source, $year, $volume, $start_page, $end_page ) = $db->get_ref( $new_keys[$j] );
		    #my $content = $title.", ".$source.", ".$year.", ".$volume.", ".$start_page."-".$end_page;
		    print $q->td( {-class=>'resultsbody',
				   -align=>'LEFT'},
				   "Gramene", "&nbsp;",
				   $q->a( {-target=>'reference', -href=>"/perl/pub_search?ref_id=$x_key"}, "Reference&nbsp;", $x_key ) );
		} elsif( $new_names[$j] =~ /interpro/i ) {
	            print $q->td( {-class=>'resultsbody',
			           -align=>'LEFT'},
				  "InterPro", "&nbsp;",
				  $q->a( {-target=>'interpro', -href=>"http://www.ebi.ac.uk/interpro/IEntry?ac=$new_keys[$j]"}, $new_keys[$j] ) );
		} else {
		    print $q->td( {-class=>'resultsbody',
				   -align=>'LEFT'},
			           $new_names[$j], ": ", $new_keys[$j] );
		}
		print $q->td( {-class=>'resultsbody',
			       -align=>'LEFT',
			       -valign=>'TOP'}, 
			      $new_codes[$j] );
	        print end_TR;
		
	    }#End for
	        

	}#End for

	#print end_table;

    }#End if



    #####################

  

    ################
    # Associations #
    ################

   # print $q->table( {-border=>'0',
#		      -cellpadding=>'2',
#		      -width=>'100%'},
#		      $q->Tr( $q->th( {-class=>'resultstitle',
#				       -align=>'CENTER'}, 
#				       "Associations" ) ) );

    
    #print start_table( {-width=>'100%', -cellpadding=>'2', -border=>'0'} );

    if( $pfam ) {
        print $q->Tr( $q->th( {-class=>'resultstitle',
			       -align=>'LEFT'}, "Pfam" ),
		      $q->td( {-class=>'resultsbody',
			       -align=>'LEFT',
			       -colspan=>'3'}, 
			      $q->a( {-target=>'cross_reference', -href=>"http://www.sanger.ac.uk/cgi-bin/Pfam/getacc?$pfam"},
				     $pfam, "; ", $pfam_extra ) ) );
    } else {
        print $q->Tr( $q->th( {-class=>'resultstitle',
			       -align=>'LEFT'}, "Pfam" ),
		      $q->td( {-class=>'resultsbody',
			       -align=>'LEFT',
			       -colspan=>'3'}, 
			      "Not available" ) );
    }

    
    my ( $prosite_key_ref, $prosite_desc_ref, $sequence_ref ) = $db->get_prosite( $gp_id );
    my @prosite_keys = @$prosite_key_ref;
    my @prosite_descs = @$prosite_desc_ref;
    my @sequences = @$sequence_ref;

    my $prosite_string;
    if( @prosite_keys ) {


        my $row_number = scalar( @prosite_keys );
        print start_TR();
        print $q->th( {-class=>'resultstitle',
		       -rowspan=>$row_number,
		       -align=>'LEFT'}, "Prosite" );
        my $temp = $q->a( {-target=>'cross_reference', -href=>"http://kr.expasy.org/cgi-bin/nicesite.pl?$prosite_keys[0]"},
			      $prosite_keys[0], "; ", $prosite_descs[0] );
	my $sequence_temp;
	if( $sequences[0] ) {
	    $sequence_temp = "Residues from <b>".$sequences[0]."</b>";
	} else {
	    $sequence_temp = "Sequence info. not available";
	}
	print $q->td( {-class=>'resultsbody',
		       -align=>'LEFT'}, $temp );
        print $q->td( {-class=>'resultsbody',
		       -colspan=>'2',
		       -align=>'LEFT'}, $sequence_temp );		       
        print end_TR();

      
        for( my $i=2; $i<=scalar( @prosite_keys ); $i++ ) {
	    
	    print start_TR();
	    my $temp = $q->a( {-target=>'cross_reference', -href=>"http://kr.expasy.org/cgi-bin/nicesite.pl?$prosite_keys[$i-1]"},
			      $prosite_keys[$i-1], "; ", $prosite_descs[$i-1] );
	    my $sequence_temp;
	    if( $sequences[$i-1] ) {
	        $sequence_temp = "Residues from <b>".$sequences[$i-1]."</b>";
	    } else {
	        $sequence_temp = "Sequence info. not available";
	    }
	    print $q->td( {-class=>'resultsbody',
			   -align=>'LEFT'}, $temp );
	    print $q->td( {-class=>'resultsbody',
			   -colspan=>'2',
			   -align=>'LEFT'}, $sequence_temp );		       
	    print end_TR();
	    
	}
    } else {

        print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'LEFT'}, "Prosite" ),
		  $q->td( {-class=>'resultsbody',
			   -align=>'LEFT',
			   -colspan=>'3'}, 
			   "Not available" ) );

    }
        
    
  
    if( $trembl_new ) {
        print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'LEFT'}, "Physio-chemical features" ),
		  $q->td( {-class=>'resultsbody',
			   -align=>'LEFT',
			   -colspan=>'3'},
			  "Not available" ) );
    } else {
        
    print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'LEFT'}, "Physio-chemical features" ),
		  $q->td( {-class=>'resultsbody',
			   -align=>'LEFT',
			   -colspan=>'3'},
			  $q->a( {-target=>'cross_reference', -href=>"http://www.expasy.ch/cgi-bin/protparam1?$acc"},
                                 $acc ) ) );
    }

    print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'LEFT'}, "ProtoMap" ),
		  $q->td( {-class=>'resultsbody',
			   -align=>'LEFT',
			   -colspan=>'3'},
			  $q->a( {-target=>'cross_reference', -href=>"http://protomap.cornell.edu/Amino/Clusters/1e-0/ByProteinID/$swall"},
                                 $swall ) ) );

    print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'LEFT'}, "Plant Tissue / Cell Type" ),
		  $q->td( {-class=>'resultsbody',
			   -align=>'LEFT',
			   -colspan=>'3'}, $tissue ) );
    print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'LEFT'}, "Keywords" ),
		  $q->td( {-class=>'resultsbody',
			   -align=>'LEFT',
			   -colspan=>'3'}, $keyword ) );
    #print end_table;

    #############################
    # Similarity #
    #############################

    
    print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'CENTER',
			   -colspan=>'4'}, 
			   "<a name=\"similarity\"></a>Similarity to Other Proteins" ) );


    my $structure_link = "3D protein structures&nbsp;&nbsp;";
    if( $gi ) {
        if( $trembl_new ) {
	    $structure_link = $structure_link.":&nbsp;".$q->a( {-target=>'cross_reference', -href=>"http://www.ncbi.nlm.nih.gov:80/cgi-bin/Entrez/blink?pid=$gi&pdb=1"}, "BLink from NCBI" );
	} else {
	    $structure_link = $structure_link.":&nbsp;".$q->a( {-target=>'cross_reference', -href=>"http://www.ncbi.nlm.nih.gov:80/cgi-bin/Entrez/blink?pid=$gi&pdb=1"}, "BLink from NCBI" )."&nbsp;&nbsp;|&nbsp;&nbsp;".$q->a( {-target=>'cross_reference', -href=>"http://www.biochem.ucl.ac.uk/cgi-bin/sas/process_form.cgi?sprotnum=$acc"}, "Sequence Annotated by Structure (SAS)" );
	}
    } else {
        unless( $trembl_new ) {
	    $structure_link = $structure_link.":&nbsp;".$q->a( {-target=>'cross_reference', -href=>"http://www.biochem.ucl.ac.uk/cgi-bin/sas/process_form.cgi?sprotnum=$acc"}, "Sequence Annotated by Structure (SAS)" );
	}
    }




    if( $gi ) {

        print $q->Tr( $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'},
			      $q->a( {-target=>'cross_reference', -href=>"http://www.ncbi.nlm.nih.gov/cgi-bin/Entrez/blink?pid=$gi&tax=4527&org=0&pdb=0&sort=1&cut=100&all=0"}, "Rice" ) ),
		      $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'},
			      $q->a( {-target=>'cross_reference', -href=>"http://www.ncbi.nlm.nih.gov/cgi-bin/Entrez/blink?pid=$gi&tax=3701&org=0&pdb=0&sort=1&cut=100&all=0"}, "Arabidopsis" ) ),
		      $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'},
			      $q->a( {-target=>'cross_reference', -href=>"http://www.ncbi.nlm.nih.gov/cgi-bin/Entrez/blink?pid=$gi&tax=4447&org=0&pdb=0&sort=1&cut=100&all=0"}, "All monocots" ) ),
		      $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'},
			      $q->a( {-target=>'cross_reference', -href=>"http://www.ncbi.nlm.nih.gov/cgi-bin/Entrez/blink?pid=$gi&tax=4751&org=0&pdb=0&sort=1&cut=100&all=0"}, "Fungi" ) ) );

	print $q->Tr( $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'},
			      $q->a( {-target=>'cross_reference', -href=>"http://www.ncbi.nlm.nih.gov/cgi-bin/Entrez/blink?pid=$gi&tax=4479&org=0&pdb=0&sort=1&cut=100&all=0"}, "Grasses" ) ),
		      $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'},
			      $q->a( {-target=>'cross_reference', -href=>"http://www.ncbi.nlm.nih.gov/cgi-bin/Entrez/blink?pid=$gi&tax=33090&org=0&pdb=0&sort=1&cut=100&all=0"}, "Green plants" ) ),
		      $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'},
			      $q->a( {-target=>'cross_reference', -href=>"http://www.ncbi.nlm.nih.gov/cgi-bin/Entrez/blink?pid=$gi&tax=71240&org=0&pdb=0&sort=1&cut=100&all=0"}, "All dicots" ) ),
		      $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'},
			      $q->a( {-target=>'cross_reference', -href=>"http://www.ncbi.nlm.nih.gov/cgi-bin/Entrez/blink?pid=$gi&tax=33208&org=0&pdb=0&sort=1&cut=100&all=0"}, "Metazoa" ) ) );
    
	#print $q->Tr( $q->td( {-class=>'resultsbody',
		#	       -align=>'LEFT',
			#       -colspan=>'4'},
			 #     $q->a( {-href=>"http://www.ncbi.nlm.nih.gov:80/cgi-bin/Entrez/blink?pid=$gi&pdb=1"}, "3D Structural Alignment" ) ) );

	print $q->Tr( $q->td( {-class=>'resultsbody',
			       -align=>'LEFT',
			       -colspan=>'4'},
			      $structure_link ) );

    } else {

        print $q->Tr( $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'}, "Rice" ),
		      $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'}, "Arabidopsis" ),
		      $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'}, "All monocots" ),
		      $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'}, "Fungi" ) );

	print $q->Tr( $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'}, "Grasses" ),
		      $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'}, "Green plants" ),
		      $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'}, "All dicots" ),
		      $q->td( {-class=>'resultsbody',
			       -align=>'LEFT'}, "Metazoa" ) );
    
	print $q->Tr( $q->td( {-class=>'resultsbody',
			       -align=>'LEFT',
			       -colspan=>'4'}, $structure_link ) );
    }

    ############ Features section starts #####################################################################

    my ( $feature_ref, $from_ref, $to_ref ) = $db->get_features( $gp_id );
    my @features = @$feature_ref;
    my @froms = @$from_ref;
    my @tos = @$to_ref;

	
    if( @features ) {
	
	print $q->Tr( $q->th( {-class=>'resultstitle',
			       -align=>'CENTER',
			       -colspan=>'4'}, 
			      "<a name=\"features\"></a>Protein Features" ) );
	print $q->Tr( $q->th( {-class=>'resultstitle',
			       -align=>'CENTER'}, "<b>Feature Type</b>" ),
		      $q->th( {-class=>'resultstitle',
			       -align=>'CENTER'}, "<b>Residues (From - To)</b>" ),
		      $q->th( {-class=>'resultstitle',
			       -align=>'CENTER'}, "<b>Evidence</b>" ),
		      $q->th( {-class=>'resultstitle',
			       -align=>'CENTER',
			       -width=>'15%'}, "<b>Evidence Code</b>" ) );

	my $evidence_string = $q->a( {-target=>'evidence', -href=>"ftp://www.gramene.org/pub/gramene/protein/feature/Oryza_TMHMM_result.txt"}, "Gramene" );
	my $code_string = $q->a( {-target=>'evidence', -href=>"http://brie2.cshl.org:8082/plant_ontology/evidence_codes.html#IEA"}, "IEA" );
	for( my $i=1; $i<=scalar( @features ); $i++ ) {

	    print $q->Tr( $q->td( {-class=>'resultsbody',
				   -align=>'CENTER'}, $features[$i-1] ),
			  $q->td( {-class=>'resultsbody',
				   -align=>'CENTER'}, $froms[$i-1], " - ", $tos[$i-1] ),
			  $q->td( {-class=>'resultsbody',
				   -align=>'CENTER'}, $evidence_string ),
			  $q->td( {-class=>'resultsbody',
				   -align=>'CENTER',
				   -width=>'15%'}, $code_string ) );
	}
    }
	    
    ############ Features section ends #####################################################################

    
    ################### References section starts ####################################################

    my @ref_ids = $db->get_ref_ids( $gp_id );
    print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'CENTER',
			   -colspan=>'4'}, 
			   "<a name=\"references\"></a>References" ) );
    if( @ref_ids ) {
        
	
	print ( "<tr><td class=\"resultsbody\" align=\"LEFT\" colspan=4>" );
	my $index = 0;
	foreach my $lit_id( @ref_ids ) {

	    my ( $title, $source, $year, $volume, $start_page, $end_page, $author ) = $db->get_ref_detail( $lit_id );
            $index++;
	    $author = $q->a( {-target=>'reference', -class=>'gopage', -href=>"/perl/pub_search?ref_id=$lit_id"}, $author );
	    #$title = $q->a( {-target=>'reference', -class=>'gopage', -href=>"/perl/pub_search?ref_id=$lit_id"}, $title );

	    my $source_string;
	    if( $source ) {
	        $source_string = $source.", ".$year;
	
	    } else {
	        $source_string = $year;
	    }
	
	    if( $volume ) {
		$source_string = $source_string.", "."vol.".$volume;
	    }

	    if( $start_page ) {
		$source_string = $source_string.", "."pp".$start_page;
		if( $end_page ) {
		    $source_string = $source_string."-".$end_page;
		} else {
		    $source_string = $source_string."-".$start_page;
		}
	    }

print <<ITEM;
	    <dl>
	      <dt>
		<table cellspacing="0" cellpadding="0">
		  <tr>
		    <td align="CENTER" valign="CENTER">&nbsp;
		      </td><td align="CENTER" valign="CENTER"><span class="reftitle"><b>$index.<b></span>&nbsp;
	            </td>
		    <td align="LEFT" valign="CENTER">
		      $author
		    </td>
		  </tr>
		</table>
	      </dt>
ITEM

            print( "<dd>" );
	    
	    print( "<table cellspacing=\"0\" cellpadding=\"0\"><tr><td><span class=\"reftitle\">$title</span></td></tr>" );
	    
	    
	    print( "<tr><td>$source_string</td></tr>" );
	    print( "</table>" );
	   
	    print( "</dl>" );

	} #End foreach
	print ( "</tr></td>" );
    } else {
        print ( "<tr><td class=\"resultsbody\" align=\"LEFT\" colspan=4>&nbsp;&nbsp;Not available</tr></td>" );
    }
        

    my @related_refs = $db->get_all_refs( $gp_id );
    if( @related_refs ) {

        my $ref_string = join( ",", @related_refs ); 

	print ( "<tr><td class=\"resultsbody\" align=\"CENTER\" colspan=4>" );
        print $q->start_form(-action=>'/perl/pub_search');
	print $q->hidden( -name=>'all_ids', -value=>$ref_string );
	print $q->submit( -name=>'lit_search',
			  -value=>'Search the Literature Database' );
	print $q->end_form();

	print ( "</tr></td>" );
    
        
    }
        
    ################### References section ends ####################################################

    ################## Comments section starts ############################################################
       
    print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'CENTER',
			   -colspan=>'4'}, 
			   "<a name=\"comments\"></a>Comments" ) );
	
	
    print $q->Tr( $q->th( {-class=>'resultstitle',
			   -align=>'LEFT'}, "Expression" ),
		  $q->td( {-class=>'resultsbody',
			   -align=>'LEFT',
			   -colspan=>'3'}, $exp ) );

    #print $q->Tr( $q->th( {-class=>'resultstitle',
	#		   -align=>'LEFT'}, "Curator's Comments" ),
	#	  $q->td( {-class=>'resultsbody',
	#		   -align=>'LEFT',
	#		   -colspan=>'3'}, "Not available" ) );
    #print $q->Tr( $q->th( {-class=>'resultstitle',
	#		   -align=>'LEFT'}, "Alleles" ),
	#	  $q->td( {-class=>'resultsbody',
	#		   -align=>'LEFT',
	#		   -colspan=>'3'}, "Not available" ) );
    #print $q->Tr( $q->th( {-class=>'resultstitle',
	#		   -align=>'LEFT'}, "Interacting Proteins" ),
	#	  $q->td( {-class=>'resultsbody',
	#		   -align=>'LEFT',
	#		   -colspan=>'3'}, "Not available" ) );

    ################## Comments section ends ############################################################

    
    print end_table;


}
		



