#!/usr/bin/perl -s
#use strict;
use MBGD::WWW;
use PhylopatImage;
use RECOG::MBGD::OutputDomClust;

require 'libCGI.pl';
require 'libMBGDaxes.pl';

$MIN_WIDTH = 2;
$BAR_WIDTH = 600;
$BAR_HEIGHT = 15;

%Args = &CGI_GetArgs;
$spcolor = $Args{'spcolor'};
$tabid = $Args{'tabid'};
$xlen = $Args{'xlen'};
$ylen = $Args{'ylen'};
$scale = $Args{'scale'};
$color = $Args{'color'};
$phylopat = $Args{'phylopat'};
$color_off = $Args{'color_off'};

$xlen = $BAR_WIDTH if (! $xlen);
$ylen = $BAR_HEIGHT if (! $ylen);

my($phylo) = PhylopatImageGif->new();
$phylo->set_size($xlen, $ylen);
$phylo->set_scale($scale);
$phylo->set_spcolor($spcolor);
$phylo->set_border(1);
$phylo->set_patterm($phylopat);

if ($color) {
    $color = join(',', '#ccffcc', $color);
}
else {
    $color = "#ccffcc,#009900";
}
$phylo->set_color(join(/,/, $color));

$patlen = $phylo->get_pattern_length();
$cell_width = int($xlen / $patlen);
$cell_width = $MIN_WIDTH if ($cell_width < $MIN_WIDTH);
$phylo->set_cell($cell_width);

##my($tabid) = $tabid;
##my($splist_cluster) = main::MBGD_GetSpecListByTabid($tabid);

#$db = MBGD::DB->new($MYSQL_DBRECOG);
#my($clustInfo) = RECOG::MBGD::OutputDomClust->clusterIDtoInfo($db, $tabid);
#$splist_cluster = $clustInfo->{spec};
#print "ss>>@$splist_cluster\n";

print "content-type: image/gif\n";
print "\n";
#$phylo->print_phylopat(@{$splist_cluster});
$phylo->print_phylopat;
