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

Diff of /FigWebServices/rast_submit_server.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Mon Oct 19 20:12:40 2009 UTC revision 1.9, Fri Nov 20 17:54:21 2009 UTC
# Line 1  Line 1 
1  use strict;  use strict;
2  use FIG;  use FIG;
3    use POSIX;
4    
5  my $have_fcgi;  my $have_fcgi;
6  eval {  eval {
# Line 12  Line 13 
13  use FIG_Config;  use FIG_Config;
14  use RAST_submission;  use RAST_submission;
15    
16    $YAML::CompressSeries = 0;
17    
18  #  #
19  # This is the list of supported methods.  # This is the list of supported methods.
20  #  #
21    
22  my @methods = qw(submit_RAST_job status_of_RAST_job);  my @methods = qw(
23                     get_contig_ids_in_project_from_entrez
24                     get_contigs_from_entrez
25                     submit_RAST_job
26                     status_of_RAST_job
27                     kill_RAST_job
28                     delete_RAST_job
29                     get_job_metadata
30                    );
31    
32  my %methods = map { $_ => 1 } @methods;  my %methods = map { $_ => 1 } @methods;
33    
34  use YAML;  use YAML;
35    
 my $ffdir = $FIG_Config::FigfamsData;  
   
36  $| = 1;  $| = 1;
37    
38  my $header = "Content-type: text/plain\n\n";  my $header = "Content-type: text/plain\n\n";
# Line 38  Line 48 
48      while ((my $cgi = new CGI::Fast()) &&      while ((my $cgi = new CGI::Fast()) &&
49             ($max_requests == 0 || $n_requests++ < $max_requests))             ($max_requests == 0 || $n_requests++ < $max_requests))
50      {      {
51            &log("fcgi request received");
52          eval {          eval {
53              &process_request($cgi);              &process_request($cgi);
54          };          };
55          if ($@)          my $had_error = $@;
56            &log("fcgi request completed $had_error");
57            if ($had_error)
58          {          {
59              if (ref($@) ne 'ARRAY')              if (ref($had_error) ne 'ARRAY')
60              {              {
61                  warn "code died, cgi=$cgi returning error\n";                  warn "code died, cgi=$cgi returning error\n";
62                  print $cgi->header(-status => '500 error in body of cgi processing');                  print $cgi->header(-status => '500 error in body of cgi processing');
# Line 56  Line 69 
69  else  else
70  {  {
71      my $cgi = new CGI();      my $cgi = new CGI();
72        &log("request received");
73      &process_request($cgi);      &process_request($cgi);
74        &log("request completed");
75  }  }
76    
77  exit;  exit;
78    
79    sub log
80    {
81        my($msg) = @_;
82        print STDERR strftime("%D %T: $msg\n", localtime);
83    }
84    
85    
86  sub process_request  sub process_request
87  {  {
88      my($cgi) = @_;      my($cgi) = @_;
89    
90      my $function = $cgi->param('function');      my $function = $cgi->param('function');
91  #    print STDERR "got function=$function\n";  #    print STDERR "got function=$function\n";
92        &log("handle $function");
93    
94      my $arg_str = $cgi->param('args');      my $arg_str = $cgi->param('args');
95      my @args;      my @args;
# Line 133  Line 156 
156    
157      my $rast_obj = new RAST_submission($rast_dbmaster, $dbmaster, $user_obj);      my $rast_obj = new RAST_submission($rast_dbmaster, $dbmaster, $user_obj);
158    
159      if ($methods{$function})  
160        #
161        # We handle retrieve in a different manner.
162        #
163        if ($function eq 'retrieve_RAST_job')
164        {
165            my $res;
166            eval {
167                $res = $rast_obj->retrieve_RAST_job(@args);
168            };
169    
170            if ($@)
171            {
172                myerror($cgi, '500 error in method invocation', $@);
173            }
174    
175            if ($res->{status} ne 'ok')
176            {
177                myerror($cgi, "501 retrieve failed: $res->{error_msg}");
178            }
179    
180            if (!open(F, "<", $res->{file}))
181            {
182                myerror($cgi, "501 could not open output file");
183            }
184    
185            print $cgi->header();
186    
187            my $buf;
188    
189            while (read(F, $buf, 4096))
190            {
191                print $buf;
192            }
193            close(F);
194        }
195        elsif ($methods{$function})
196      {      {
197    
198          my @results;          my @results;
# Line 147  Line 206 
206          }          }
207    
208          print $cgi->header();          print $cgi->header();
209          print YAML::Dump(@results);          my $res =  YAML::Dump(@results);
210            #print STDERR $res;
211            print $res;
212    
213      } else {      } else {
214          myerror($cgi,  "500 invalid function", "invalid function $function\n");          myerror($cgi,  "500 invalid function", "invalid function $function\n");
# Line 172  Line 233 
233    
234  }  }
235    
 #  
 #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).  
236    
237  sub myerror  sub myerror
238  {  {

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.9

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3