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

View of /FigWebServices/anno_server.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.17 - (download) (annotate)
Tue Sep 27 22:00:19 2011 UTC (8 years, 4 months ago) by olson
Branch: MAIN
CVS Tags: rast_rel_2014_0912, mgrast_version_3_2, mgrast_dev_12152011, rast_rel_2014_0729, mgrast_release_3_1_2, rast_rel_2011_0928, mgrast_dev_10262011, HEAD
Changes since 1.16: +18 -424 lines
Move inline code out of anno_server.cgi to ANNO.pm (well the code was already moved; remove
the inline invocations).
Add tests.

use strict;
use ANNO;
use File::Basename;
use FIG;
use ServerThing;

=head1 Annotation Support Server 

For documentation of this server's functions, see L<ANNOserver>.

=cut

my $have_fcgi;
eval {
    require CGI::Fast;
    $have_fcgi = 1;
};

use Data::Dumper;
use FFs;
use FF;
use FIG_Config;

use YAML;

my $annoServer = new ANNO();

our $error_return = {};

$| = 1;

my $clean_up = 0;

my $header = "Content-type: text/plain\n\n";

my $max_requests = 50;

my %raw_methods = map { $_ => 1 } @{$annoServer->raw_methods};

#
# If no CGI vars, assume we are invoked as a fastcgi service.
#
my $n_requests = 0;
if ($have_fcgi && $ENV{REQUEST_METHOD} eq '')
{
    #
    # Make mysql autoreconnect.
    #

    while (($max_requests == 0 || $n_requests++ < $max_requests) &&
	   (my $cgi = new CGI::Fast()))
    {
	eval {
	    &process_request($cgi);
	};
	if ($@)
	{
	    if ($@ == $error_return)
	    {
		warn "Got error return\n";
	    }
	    elsif (ref($@) ne 'ARRAY')
	    {
		warn "code died, cgi=$cgi returning error\n";
		print $cgi->header(-status => '500 error in body of cgi processing');
		print $@;
	    }
	}

    }
}
else
{
    my $cgi = new CGI();
    &process_request($cgi);
}

exit;


sub process_request
{
    my($cgi) = @_;

    my $function = $cgi->param('function');

    $function or myerror($cgi, "500 missing argument", "missing function argument");
    
    #
    # The bulk annotation services take a raw CGI object as an argument.
    #

    if ($raw_methods{$function})
    {
	print $cgi->header;
	my @res = $annoServer->$function($cgi);
	print YAML::Dump(@res);
    } else {
	ServerThing::RunRequest($cgi, $annoServer);
    }
}

exit;

sub get_string_param
{
    my($cgi, $name) = @_;

    my $str = $cgi->param($name);
    if ($str =~ /^(\S+)/)
    {
	return $1;
    }
    else
    {
	return undef;
    }
    
}

#
#The FIGfam server processes requests of the form:
#
#    1. PLACE-IN-FAMILY takes as input a list of protein sequences.  It
#       returns a list where each element describes the outcome of
#       trying to place the corresponding input sequence into a
#       FIGfam.  Each output can be either
#
#                COULD-NOT-PLACE-IN-FAMILY
#       or
#                ID FUNCTION
#
#       where ID is of the form FIGxxxxxx and FUNCTION is the family
#       function. 
#
#    2. MEMBERS-OF-FAMILIES takes as input a list of FIGfam IDs.  The
#       output is a list of functions for those families
#       (INVALID-FAMILY will be returned for IDs that do not correspond
#       to an active family), as well as a list of the IDs in each family.
#
#    3. SHOULD-BE-MEMBER takes as input a list of 2-tuples
#
#             [FIGfam-ID,protein sequence]
#
#       It returns a list of boolean values indicating whether or not
#       the indicated protein sequence can be placed in the designated
#       family.
#
#    4. ALL-FAMILIES returns a list of [FIGfam-ID,function] tuples.
#
#
#    5. ASSIGN-FUNCTION-TO-PROT is similar to PLACE-IN-FAMILY, except
#       that the returned list contains either
#
#                COULD-NOT-PLACE-IN-FAMILY
#       or
#                ID FUNCTION
#
#       That is, it does not indicate which FIGfam was used to
#       determine the function.  This allows higher-performance
#       alternatives for cases in which multiple FIGfams implement the
#       same function.  The algorithm supported utilizes the underlying
#       FIGfams, but characterizes sets that implement the same
#       function and does not support distinguishing which FIGfam
#       is actually the right subgrouping.
#
#	6. ASSIGN-FUNCTIONS-TO-DNA takes as input a list of DNA
#       sequences.  It returns a list where each element describes 
#       a region of DNA that is believed to be part of a gene encoding
#       a protein sequence that would be placed into a FIGfam
#       successfully, if the whole protein sequence could be
#       determined.  That is, the returned list will contain entrties
#       of either the form
#
#                COULD-NOT-PLACE-ANY-REGIONS-IN-FAMILIES
#       or
#                BEGIN1 END1 FUNCTION1 BEGIN2 END2 FUNCTION2 ...
#
#       where BEGIN and END specify a region (if BEGIN is greater than
#       END, the region described is on the reverse strand) and
#       FUNCTION is the family function of the protein sequence that is
#       believed to be encoded by DNA including the embedded region.
#       Each input sequence can produce an arbitrary number of matched
#       regions, there will be 3 fields for each matched region.  Note
#       that the described region may include frameshifts and embedded
#       stop codons.  The algorithm seeking meaningful sections of DNA
#       assumes that it may have an incomplete, low-quality sequence
#       (and uses an algorithm that attempts to locate meaningful
#       matches even so).

sub myerror
{
    my($cgi, $stat, $msg) = @_;
    print $cgi->header(-status =>  $stat);
    print "$msg\n";
    die $error_return;
}





MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3