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

Annotation of /FigWebServices/rast_submit_server.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download)

1 : olson 1.1 use strict;
2 :     use FIG;
3 :    
4 :     my $have_fcgi;
5 :     eval {
6 :     require CGI::Fast;
7 :     $have_fcgi = 1;
8 :     };
9 :    
10 :     use Data::Dumper;
11 :     use DBMaster;
12 :     use FIG_Config;
13 :     use RAST_submission;
14 :    
15 :     #
16 :     # This is the list of supported methods.
17 :     #
18 :    
19 :     my @methods = qw(submit_RAST_job status_of_RAST_job);
20 :     my %methods = map { $_ => 1 } @methods;
21 :    
22 :     use YAML;
23 :    
24 :     my $ffdir = $FIG_Config::FigfamsData;
25 :    
26 :     $| = 1;
27 :    
28 :     my $header = "Content-type: text/plain\n\n";
29 :    
30 :     my $max_requests = 5000;
31 :    
32 :     #
33 :     # If no CGI vars, assume we are invoked as a fastcgi service.
34 :     #
35 :     my $n_requests = 0;
36 :     if ($have_fcgi && $ENV{REQUEST_METHOD} eq '')
37 :     {
38 :     while ((my $cgi = new CGI::Fast()) &&
39 :     ($max_requests == 0 || $n_requests++ < $max_requests))
40 :     {
41 :     eval {
42 :     &process_request($cgi);
43 :     };
44 :     if ($@)
45 :     {
46 :     if (ref($@) ne 'ARRAY')
47 :     {
48 :     warn "code died, cgi=$cgi returning error\n";
49 :     print $cgi->header(-status => '500 error in body of cgi processing');
50 :     print $@;
51 :     }
52 :     }
53 :     endloop:
54 :     }
55 :     }
56 :     else
57 :     {
58 :     my $cgi = new CGI();
59 :     &process_request($cgi);
60 :     }
61 :    
62 :     exit;
63 :    
64 :     sub process_request
65 :     {
66 :     my($cgi) = @_;
67 :    
68 :     my $function = $cgi->param('function');
69 :     # print STDERR "got function=$function\n";
70 :    
71 :     my $arg_str = $cgi->param('args');
72 :     my @args;
73 :     if ($arg_str)
74 :     {
75 :     eval {
76 :     @args = YAML::Load($arg_str);
77 :     };
78 :     if ($@)
79 :     {
80 :     myerror($cgi, "500 bad YAML parse", "YAML parse failed");
81 :     next;
82 :     }
83 :     }
84 :    
85 :     $function or myerror($cgi, "500 missing argument", "missing function argument");
86 :    
87 :     #
88 :     # Pull username & password from the arguments and authenticate.
89 :     #
90 :    
91 :     my $rast_user = $cgi->param('username');
92 :     my $rast_password = $cgi->param('password');
93 :    
94 :     if ($rast_user eq '')
95 :     {
96 :     &myerror($cgi, '500 missing username', 'RAST username is missing');
97 :     }
98 :    
99 :     #
100 :     # Connect to the authentication database.
101 :     #
102 :    
103 :     my $dbmaster;
104 :     eval {
105 :     $dbmaster = DBMaster->new(-database => $FIG_Config::webapplication_db || "WebAppBackend",
106 :     -host => $FIG_Config::webapplication_host || "localhost",
107 :     -user => $FIG_Config::webapplication_user || "root",
108 :     -password => $FIG_Config::webapplication_password || "");
109 :     };
110 :    
111 :     #
112 :     # And evaluate username and password.
113 :     #
114 :    
115 :     my $user_obj = $dbmaster->User->init( { login => $rast_user });
116 :     if (!ref($user_obj) || !$user_obj->active)
117 :     {
118 :     &myerror($cgi, '500 invalid login', 'Invalid RAST login');
119 :     }
120 :    
121 :     if (crypt($rast_password, $user_obj->password) ne $user_obj->password)
122 :     {
123 :     &myerror($cgi, '500 invalid login', 'Invalid RAST login');
124 :     }
125 :     warn "Authenticated $rast_user\n";
126 :    
127 :     # Connect to the RAST job cache
128 :     my $rast_dbmaster = DBMaster->new(-backend => 'MySQL',
129 :     -database => $FIG_Config::rast_jobcache_db,
130 :     -host => $FIG_Config::rast_jobcache_host,
131 :     -user => $FIG_Config::rast_jobcache_user,
132 :     -password => $FIG_Config::rast_jobcache_password );
133 :    
134 :     my $rast_obj = new RAST_submission($rast_dbmaster, $dbmaster, $user_obj);
135 :    
136 :     if ($methods{$function})
137 :     {
138 :    
139 :     my @results;
140 :     eval {
141 :     @results = $rast_obj->$function(@args);
142 :     };
143 :    
144 :     if ($@)
145 :     {
146 :     myerror($cgi, '500 error in method invocation', $@);
147 :     }
148 :    
149 :     print $cgi->header();
150 :     print YAML::Dump(@results);
151 :    
152 :     } else {
153 :     myerror($cgi, "500 invalid function", "invalid function $function\n");
154 :     }
155 :     }
156 :    
157 :     exit;
158 :    
159 :     sub get_string_param
160 :     {
161 :     my($cgi, $name) = @_;
162 :    
163 :     my $str = $cgi->param($name);
164 :     if ($str =~ /^(\S+)/)
165 :     {
166 :     return $1;
167 :     }
168 :     else
169 :     {
170 :     return undef;
171 :     }
172 :    
173 :     }
174 :    
175 :     #
176 :     #The FIGfam server processes requests of the form:
177 :     #
178 :     # 1. PLACE-IN-FAMILY takes as input a list of protein sequences. It
179 :     # returns a list where each element describes the outcome of
180 :     # trying to place the corresponding input sequence into a
181 :     # FIGfam. Each output can be either
182 :     #
183 :     # COULD-NOT-PLACE-IN-FAMILY
184 :     # or
185 :     # ID FUNCTION
186 :     #
187 :     # where ID is of the form FIGxxxxxx and FUNCTION is the family
188 :     # function.
189 :     #
190 :     # 2. MEMBERS-OF-FAMILIES takes as input a list of FIGfam IDs. The
191 :     # output is a list of functions for those families
192 :     # (INVALID-FAMILY will be returned for IDs that do not correspond
193 :     # to an active family), as well as a list of the IDs in each family.
194 :     #
195 :     # 3. SHOULD-BE-MEMBER takes as input a list of 2-tuples
196 :     #
197 :     # [FIGfam-ID,protein sequence]
198 :     #
199 :     # It returns a list of boolean values indicating whether or not
200 :     # the indicated protein sequence can be placed in the designated
201 :     # family.
202 :     #
203 :     # 4. ALL-FAMILIES returns a list of [FIGfam-ID,function] tuples.
204 :     #
205 :     #
206 :     # 5. ASSIGN-FUNCTION-TO-PROT is similar to PLACE-IN-FAMILY, except
207 :     # that the returned list contains either
208 :     #
209 :     # COULD-NOT-PLACE-IN-FAMILY
210 :     # or
211 :     # ID FUNCTION
212 :     #
213 :     # That is, it does not indicate which FIGfam was used to
214 :     # determine the function. This allows higher-performance
215 :     # alternatives for cases in which multiple FIGfams implement the
216 :     # same function. The algorithm supported utilizes the underlying
217 :     # FIGfams, but characterizes sets that implement the same
218 :     # function and does not support distinguishing which FIGfam
219 :     # is actually the right subgrouping.
220 :     #
221 :     # 6. ASSIGN-FUNCTIONS-TO-DNA takes as input a list of DNA
222 :     # sequences. It returns a list where each element describes
223 :     # a region of DNA that is believed to be part of a gene encoding
224 :     # a protein sequence that would be placed into a FIGfam
225 :     # successfully, if the whole protein sequence could be
226 :     # determined. That is, the returned list will contain entrties
227 :     # of either the form
228 :     #
229 :     # COULD-NOT-PLACE-ANY-REGIONS-IN-FAMILIES
230 :     # or
231 :     # BEGIN1 END1 FUNCTION1 BEGIN2 END2 FUNCTION2 ...
232 :     #
233 :     # where BEGIN and END specify a region (if BEGIN is greater than
234 :     # END, the region described is on the reverse strand) and
235 :     # FUNCTION is the family function of the protein sequence that is
236 :     # believed to be encoded by DNA including the embedded region.
237 :     # Each input sequence can produce an arbitrary number of matched
238 :     # regions, there will be 3 fields for each matched region. Note
239 :     # that the described region may include frameshifts and embedded
240 :     # stop codons. The algorithm seeking meaningful sections of DNA
241 :     # assumes that it may have an incomplete, low-quality sequence
242 :     # (and uses an algorithm that attempts to locate meaningful
243 :     # matches even so).
244 :    
245 :     sub myerror
246 :     {
247 :     my($cgi, $stat, $msg) = @_;
248 :     print $cgi->header(-status => $stat);
249 :     print "$msg\n";
250 :     goto endloop;
251 :     }
252 :    
253 :    
254 :    
255 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3