#!/usr/bin/perl
# -*- Mode: perl -*-
# file: sequence

use lib '/usr/local/gramene/lib/perl/';
use strict;
use vars qw($DB);
use Ace 1.51;
use Ace::Browser::AceSubs qw(:DEFAULT Toggle);
use GrameneSubs;
use CGI 2.42 qw/:standard :html3 escape *table *blockquote/;

use constant CLASS   => 'Sequence';
#use constant EXAMPLE => 'AA231638';

# open the database
$DB = OpenDatabase() || AceError("Couldn't open database.");

my ($obj_name, $obj);
$obj_name = param('name');
$obj = get_obj($obj_name) if $obj_name;

PrintTop($obj,CLASS,$obj ? CLASS . ": $obj" : CLASS . " Search");
PrintWarning($obj_name,CLASS) if $obj_name && !$obj;
print_report($obj) if $obj;
PrintBottom();

sub get_obj {
  my $name = shift;
  my ($obj) = $DB->fetch(-class =>CLASS,
			 -name  => $name);
  return $obj;
}

sub print_report {
  my $obj = shift;

  print start_table({-border=>1});

  if ($obj->DNA) {
    print TR(
	   th({-class=>'datatitle'},'DNA'),
	   td({-class=>'databody'},ObjectLink($obj->DNA))
	   );
  }
  if ($obj->Raw_seq) {
    print TR(
	   th({-class=>'datatitle'},'Raw Sequence'),
	   td({-class=>'databody'},ObjectLink($obj->Raw_seq))
	   );
  }
  if ($obj->Marker) {
    print TR(
	   th({-class=>'datatitle'},'Marker'),
	   td({-class=>'databody'},ObjectLink($obj->Marker))
	   );
  }
  if ($obj->External_DB_Key) {
    print TR(
	   th({-class=>'datatitle'},'External DB Key'),
 	   td({-class=>'databody'},$obj->External_DB_key)
	   );
  }
  if ($obj->Reference) {
    print TR(
	   th({-class=>'datatitle'},'Reference'),
	   td({-class=>'databody'},ObjectLink($obj->Reference))
	   );
  }
  print end_table;
   
  my $remark = $obj->Remarks;
  if ( $remark ) {
    print br, br;
    if ( Toggle('remarks','Remarks on sequence') ) {
      print $remark;
    }
  }  

  my $info = $obj->Help->Info;
  if ( $info ) {
    print br, br; 
    if ( Toggle('help','Help on sequence') ) {
     print pre($info->right);
   }
  }
}
  
  


