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

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   => 'Map';
#use constant EXAMPLE => '1MW99';

# 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->get('Species')) {
    print TR(
	   th({-class=>'datatitle'},'Species'),
	   td({-class=>'databody'},$obj->Species)
	   );
  }
  if ($obj->Chromosome) {
    print TR(
	   th({-class=>'datatitle'},'Chromosome'),
	   td({-class=>'databody'},$obj->Chromosome)
	   );
  }
  if ($obj->Type) {
    print TR(
	   th({-class=>'datatitle'},'Type'),
	   td({-class=>'databody'},$obj->Type)
	   );
  }
  PrintMultiple('Clones/Contigs',$obj->get('Clone'));
  PrintMultiple('Homoeologous Segments',$obj->Homoeologous_segment);
  PrintMultiple('Loci',$obj->Locus);
  PrintMultiple('QTLs',$obj->QTL);
  print TR(
	   th({-class=>'datatitle'},'Map Study'),
 	   td({-class=>'databody'},ObjectLink($obj->Map_study))
	   );

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


