#!/usr/bin/perl

our $VERSION = '0.02';

# $Id: display_ref_seq,v 1.7.2.2 2007/06/14 19:04:09 kclark Exp $

use warnings;
use strict;

use FindBin::Real qw(Bin);
use HTML::SearchPage;
use HTML::SearchPage::Param;
use Panzea::FormModifier;
use Panzea::FormConfig;

my $config_file = '/usr/local/gramene-25/conf//html-searchpage.conf'; # MKFILE:Q:CONF_FILE

my $config = Panzea::FormConfig->new($config_file);

# Search page object
my $sp = HTML::SearchPage->new(
    page_title      => 'Not Set',
    header          => $config->cfg('form_header'),
    css             => $config->cfg('form_css'),
    temp_dir        => $config->cfg('temp_dir'),
    temp_dir_eq     => $config->cfg('temp_dir_eq'),
    footer          => $config->cfg('form_footer'),
    base_sql_table  => qq[cdv_marker],
    base_sql_fields => [
        'name',
        'ref_seq',
    ],
    base_output_headers => [
        'Marker Name',
        'Not Set',
    ],
    base_identifier  => 'name',
    method           => $config->cfg('form_method'),
    page_size        => $config->cfg('form_page_size'),
    db_access_params => $config->cfg('db_access_params'),
    debug_level      => $config->cfg('form_debug_level'),
    modifier         => Panzea::FormModifier->new(),
);    # Displays error page if fails

# Change title/header based on marker type
my $marker_type;

eval {
    my $identifier = $sp->cgi_params->{'identifier'};

    my $dbh = $sp->dbh;

    my $statement =
      qq[SELECT marker_type FROM aux_marker_annotations ama JOIN cdv_marker cm USING (cdv_marker_id) WHERE cm.name = ?];
    my $sth = $dbh->prepare($statement);
    $sth->bind_param(1, $identifier);
    $sth->execute;

    ($marker_type) = $sth->fetchrow_array;
};

$sp->display_error_page($@) if $@;

my ($page_title, $header) =
  $marker_type eq 'Sequencing'
  ? ("Reference Sequence for Marker", "Reference Sequence")
  : ("Context Sequence for Marker", "Context Sequence");

$sp->page_title($page_title);
$sp->base_output_headers(['Marker Name', $header]);

# Modifications
$sp->add_modification(
    -action => 'format_sequence',
    -column => 1,
    -type   => 'display_ref_seq'
);

# Call display method
$sp->display_info;

=head1 NAME

display_ref_seq

=head1 DESCRIPTION

Panzea web display script.

Please refer to documentation of HTML::SearchPage and
HTML::SearchPage::Param for information on script structure.

=head1 AUTHOR

Payan Canaran <canaran@cshl.edu>

=head1 BUGS

=head1 VERSION

Version 0.02

=head1 ACKNOWLEDGEMENTS

=head1 COPYRIGHT & LICENSE

Copyright (c) 2005-2007 Cold Spring Harbor Laboratory

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself. See DISCLAIMER.txt for
disclaimers of warranty.

=cut

