# # Copyright (c) 2003-2006 University of Chicago and Fellowship # for Interpretations of Genomes. All Rights Reserved. # # This file is part of the SEED Toolkit. # # The SEED Toolkit is free software. You can redistribute # it and/or modify it under the terms of the SEED Toolkit # Public License. # # You should have received a copy of the SEED Toolkit Public License # along with this program; if not write to the University of Chicago # at info@ci.uchicago.edu or the Fellowship for Interpretation of # Genomes at veronika@thefig.info or download a copy from # http://www.theseed.org/LICENSE.TXT. # use FIG; my $fig = new FIG; use HTML; use strict; use GenoGraphics; use CGI; my $cgi = new CGI; if (0) { print $cgi->header; my @params = $cgi->param; print "
\n";
    foreach $_ (@params)
    {
	print "$_\t:",join(",",$cgi->param($_)),":\n";
    }
    exit;
}

my(@output,@ecs_hit,@table);

my $map = $cgi->param('map');
my $org = $cgi->param('org');
@ecs_hit = ();
@table = ();

if ($org)
{
    my @ecs = $fig->map_to_ecs($map);
    my $user = $cgi->param('user');
    if (! $user) { $user = "" }
    my $hits = $fig->seqs_with_roles_in_genomes([$org],[@ecs],$user);
    if ($hits = $hits->{$org})
    {
	@ecs_hit = keys(%$hits);
	my $col_hdrs = ["EC","name","genes"];
	my $tab         = [];
	my($x,$ec);
	foreach $ec (sort @ecs_hit)
	{
	    if ($x = $hits->{$ec})
	    {
		push(@$tab,[$ec,$fig->ec_name($ec),join(",",map { &HTML::fid_link($cgi,$_->[0],1,0,1) } @$x)]);
	    }
	}
	my $gs = $fig->genus_species($org);
	@table = &HTML::make_table($col_hdrs,$tab,"Relevant Sequences for $gs");
	push(@table,$cgi->hr);
    }
}

my $url = "http://www.genome.ad.jp/dbget-bin/show_pathway?$map" . join("",map { "+" . $_ } @ecs_hit);
@output = &HTML::get_html($url,"get",[]);
    
my $i;
for ($i=0; ($i < @output) && ($output[$i] !~ /\/i); $i++) {}
if ($i == @output)
{
    for ($i=0; ($i < @output) && ($output[$i] !~ /\/i); $i++) {}
    if ($i == @output)
    {
	$i = -1;
    }
}

splice(@output,$i+1,0,@table);
# &HTML::show_page($cgi,\@output);
print @output;