[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.10, Tue Mar 30 21:50:10 2010 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                     copy_to_RAST_dir
30                     get_job_metadata
31                    );
32    
33  my %methods = map { $_ => 1 } @methods;  my %methods = map { $_ => 1 } @methods;
34    
35  use YAML;  use YAML;
36    
 my $ffdir = $FIG_Config::FigfamsData;  
   
37  $| = 1;  $| = 1;
38    
39  my $header = "Content-type: text/plain\n\n";  my $header = "Content-type: text/plain\n\n";
# Line 38  Line 49 
49      while ((my $cgi = new CGI::Fast()) &&      while ((my $cgi = new CGI::Fast()) &&
50             ($max_requests == 0 || $n_requests++ < $max_requests))             ($max_requests == 0 || $n_requests++ < $max_requests))
51      {      {
52            &log("fcgi request received");
53          eval {          eval {
54              &process_request($cgi);              &process_request($cgi);
55          };          };
56          if ($@)          my $had_error = $@;
57            &log("fcgi request completed $had_error");
58            if ($had_error)
59          {          {
60              if (ref($@) ne 'ARRAY')              if (ref($had_error) ne 'ARRAY')
61              {              {
62                  warn "code died, cgi=$cgi returning error\n";                  warn "code died, cgi=$cgi returning error\n";
63                  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 70 
70  else  else
71  {  {
72      my $cgi = new CGI();      my $cgi = new CGI();
73        &log("request received");
74      &process_request($cgi);      &process_request($cgi);
75        &log("request completed");
76  }  }
77    
78  exit;  exit;
79    
80    sub log
81    {
82        my($msg) = @_;
83        print STDERR strftime("%D %T: $msg\n", localtime);
84    }
85    
86    
87  sub process_request  sub process_request
88  {  {
89      my($cgi) = @_;      my($cgi) = @_;
90    
91      my $function = $cgi->param('function');      my $function = $cgi->param('function');
92  #    print STDERR "got function=$function\n";  #    print STDERR "got function=$function\n";
93        &log("handle $function");
94    
95      my $arg_str = $cgi->param('args');      my $arg_str = $cgi->param('args');
96      my @args;      my @args;
# Line 133  Line 157 
157    
158      my $rast_obj = new RAST_submission($rast_dbmaster, $dbmaster, $user_obj);      my $rast_obj = new RAST_submission($rast_dbmaster, $dbmaster, $user_obj);
159    
160      if ($methods{$function})      if ($function eq 'copy_to_RAST_dir')
161        {
162            #
163            # For the copy, we pluck the file upload
164            # from the CGI and give it to the handler as well.
165            #
166            my $file = $cgi->upload('file');
167    
168            my $params = $args[0];
169            $params->{-from} = $file if ref($params) eq 'HASH';
170        }
171    
172        #
173        # We handle retrieve in a different manner.
174        #
175        if ($function eq 'retrieve_RAST_job')
176        {
177            my $res;
178            eval {
179                $res = $rast_obj->retrieve_RAST_job(@args);
180            };
181    
182            if ($@)
183            {
184                myerror($cgi, '500 error in method invocation', $@);
185            }
186    
187            if ($res->{status} ne 'ok')
188            {
189                myerror($cgi, "501 retrieve failed: $res->{error_msg}");
190            }
191    
192            if (!open(F, "<", $res->{file}))
193            {
194                myerror($cgi, "501 could not open output file");
195            }
196    
197            print $cgi->header();
198    
199            my $buf;
200    
201            while (read(F, $buf, 4096))
202            {
203                print $buf;
204            }
205            close(F);
206        }
207        elsif ($methods{$function})
208      {      {
209    
210          my @results;          my @results;
# Line 147  Line 218 
218          }          }
219    
220          print $cgi->header();          print $cgi->header();
221          print YAML::Dump(@results);          my $res =  YAML::Dump(@results);
222            #print STDERR $res;
223            print $res;
224    
225      } else {      } else {
226          myerror($cgi,  "500 invalid function", "invalid function $function\n");          myerror($cgi,  "500 invalid function", "invalid function $function\n");
# Line 172  Line 245 
245    
246  }  }
247    
 #  
 #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).  
248    
249  sub myerror  sub myerror
250  {  {

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3