#!/usr/local/bin/perl

our $VERSION = '0.01';

# $Id: look-align,v 1.1.2.1 2007/06/19 14:53:14 kclark Exp $

use warnings;
use strict;

use Carp;
use CGI qw(:standard);

use lib '/usr/local/gramene-25/lib/perl/'; # MKFILE:Q:LIB

use LookAlign::Alignment::Container;
use LookAlign::Alignment::Container::Sq;
use LookAlign::Alignment::Renderer;
use LookAlign::Interface::GDPDM;
use LookAlign::Interface::Flatfile;

my $config_file = '/usr/local/gramene-25/conf//look-align-viewer.conf'; # MKFILE:Q:CONF_FILE

# Manually parse config file
my $config_obj = new Config::General(
    -ConfigFile        => $config_file,
    -InterPolateVars   => 1,
    -AllowMultiOptions => 1
);
my %pre_config = $config_obj->getall;
my %config; # lower-case params
foreach my $key (keys %pre_config) {
    $config{lc($key)} = $pre_config{$key};
}

# Check immediately required config options
defined $config{debug}     or croak("No debug param defined!");
defined $config{interface} or croak("No interface param defined!");
defined $config{tmp_dir}   or croak("No tmp_dir param defined!");
defined $config{cookie}    or croak("No cookie param defined!");

# Set Carp::Verbose based on debug level
$Carp::Verbose = 1 if $config{debug} > 1;

# Determine interface module to use
my ($interface, $subtype) = split(':', $config{interface});
my $module;
if    ($interface eq 'GDPDM')    { $module = 'LookAlign::Interface::GDPDM'; }
elsif ($interface eq 'Flatfile') { $module = 'LookAlign::Interface::Flatfile'; }
else { croak("Unknown interface: $interface!"); }

# Instantiate interface obj and display page
my $interface_obj = $module->new(
    session_id  => param('session_id') || cookie($config{cookie}) || undef,
    db_selected => param('database') || undef,
    session_dir => $config{tmp_dir},
    config_file => $config_file,
    subtype     => $subtype,
);

$interface_obj->display_page;

=head1 NAME

look-align

=head1 DESCRIPTION

Look-Align Alignment Viewer CGI script.

=head1 AUTHOR

Payan Canaran <canaran@cshl.edu>

=head1 BUGS

=head1 VERSION

Version 0.01

=head1 ACKNOWLEDGEMENTS

=head1 COPYRIGHT & LICENSE

Copyright (c) 2004-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

