[Bio] / FigWebServices / co_occurs_server.cgi Repository:
ViewVC logotype

View of /FigWebServices/co_occurs_server.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (download) (annotate)
Mon May 11 20:36:16 2009 UTC (10 years, 11 months ago) by olson
Branch: MAIN
Changes since 1.3: +112 -65 lines
updates for fastcgi.

use strict;
use Data::Dumper;
use CGI::Fast;
use CGI;
use ERDB;
use FC;


use YAML;

use FIG;

my $fig = new FIG;

my $db = ERDB::GetDatabase('Sapling');

#
# If no CGI vars, assume we are invoked as a fastcgi service.
#
if ($ENV{REQUEST_METHOD} eq '')
{
    while (my $cgi = new CGI::Fast())
    {
	eval {
	    &process($cgi);
	};
	if ($@)
	{
	    if (ref($@) ne 'ARRAY')
	    {
		warn "code died, returning error\n";
		print $cgi->header(-status => '500 error in body of cgi processing');
		print $@;
	    }
	}
    }
}
else
{
    my $cgi = new CGI();
    print $cgi->header();
    &process($cgi);
}

exit;

sub myerror
{
    my($cgi, $stat, $msg) = @_;
    print $cgi->header(-status =>  $stat);
    print "$msg\n";
    die ['cgi error returned'];
}
	    
sub process
{
    my($cgi) = @_;
    
    my $function = $cgi->param('function');
    $function || myerror($cgi, "500 missing function", "Missing a function in call to co_occurs_server.cgi");
    
    if ($function eq "conserved_in_neighborhood")
    {
	my $pegs = &YAML::Load($cgi->param('args'));
	my $tuples = [];
	foreach my $peg (@$pegs)
	{
	    my $group = [];
	    my @co_occurs = &FC::co_occurs($db,$peg);
	    foreach my $tuple (@co_occurs)
	    {
		my($sc,$fid,$pairset) = @$tuple;
		push(@$group,[$sc,$fid,scalar $fig->function_of($fid),$pairset]);
	    }
	    push(@$tuples,$group);
	}

	print $cgi->header();
	my $str = &YAML::Dump($tuples);
	print $str;
    }
    elsif ($function eq "pairsets")
    {
	my $pairsets = &YAML::Load($cgi->param('args'));
	my $ans = [];
	foreach my $pairset (@$pairsets)
	{
	    push(@$ans,[$pairset,[&FC::co_occurrence_set($db,$pairset)]]);
	}
	print $cgi->header();
	print &YAML::Dump($ans);
    }
    elsif ($function eq "clusters_containing")
    {
	my $pegs = &YAML::Load($cgi->param('args'));
	my $ans = [];
	foreach my $peg (@$pegs)
	{
	    my $cluster = &FC::in_co_occurrence_cluster($db,$peg);
	    if ($cluster)
	    {
		my $func = scalar $fig->function_of($peg);
		push(@$ans,[$peg,$func,[map { [$_,scalar $fig->function_of($_)] } @$cluster]]);
	    }
	}
	print $cgi->header();
	print &YAML::Dump($ans);
    }
    elsif ($function eq "related_clusters")
    {
	my $pegs = &YAML::Load($cgi->param('args'));
	my $ans = [];
	foreach my $peg (@$pegs)
	{
	    my $one_set = [];
	    my @clusters = &FC::largest_co_occurrence_clusters($db,$peg);
	    foreach my $cluster (@clusters)
	    {
		my($peg1,$sc,$other_pegs) = @$cluster;
		my $func1 = $fig->function_of($peg1);
		my $others = [ map { [$_,scalar $fig->function_of($_)] } @$other_pegs];
		push(@$one_set,[$peg1,$sc,$others]);
	    }
	    push(@$ans,$one_set);
	}
	print $cgi->header();
	print &YAML::Dump($ans);
    }
    elsif ($function eq "related_figfams")
    {
	my $ffs = &YAML::Load($cgi->param('args'));
	my $ans = [];
	foreach my $ff (@$ffs)
	{
	    push(@$ans,[$ff,[&FC::co_occurring_FIGfams($db,$ff)]]);
	}
	print $cgi->header();
	print &YAML::Dump($ans);
    }
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3