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

Annotation of /FigWebServices/kernel_xmlrpc.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (view) (download)

1 : olson 1.9 #
2 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
3 :     # for Interpretations of Genomes. All Rights Reserved.
4 :     #
5 :     # This file is part of the SEED Toolkit.
6 :     #
7 :     # The SEED Toolkit is free software. You can redistribute
8 :     # it and/or modify it under the terms of the SEED Toolkit
9 :     # Public License.
10 :     #
11 :     # You should have received a copy of the SEED Toolkit Public License
12 :     # along with this program; if not write to the University of Chicago
13 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
14 :     # Genomes at veronika@thefig.info or download a copy from
15 :     # http://www.theseed.org/LICENSE.TXT.
16 :     #
17 :    
18 : mkubal 1.1 use Frontier::RPC2;
19 :    
20 :     use FIG;
21 :    
22 :     use strict;
23 :    
24 :    
25 :     package FrontierXMLRPCWrapper;
26 :    
27 :     #
28 :     # We'll make a class to hold the fig instance and the
29 :     # XMLRPC server instance; this will make it easier to invoke the
30 :     # wrapping functions (since each one will need these values).
31 :     #
32 :    
33 :    
34 :     #
35 :     # Constructor.
36 :     #
37 :     sub new
38 :     {
39 :     my($class, $fig, $xmlrpc) = @_;
40 :    
41 :     my $self = {
42 :     fig => $fig,
43 :     xmlrpc => $xmlrpc,
44 :     };
45 :    
46 :     return bless $self, $class;
47 :     }
48 :    
49 :    
50 :     #
51 :     # Return a value properly coerced to a string for passing
52 :     # as an XMLRPC return. Use the string() method on the
53 :     # xmlrpc instance variable.
54 :     #
55 :     sub coerce_to_string
56 :     {
57 :     my($self, $value) = @_;
58 :    
59 :     return $self->{xmlrpc}->string($value);
60 :     }
61 :    
62 :     #
63 :     # Wrap a FIG method that returns a scalar.
64 :     #
65 :    
66 :     sub wrap_scalar_return
67 :     {
68 :     my($self, $func) = @_;
69 :    
70 :     #
71 :     # We return a new anonymous subroutine that invokes the
72 :     # routine thru the $fig instance saved in our instance variables.
73 :     #
74 :    
75 :     return sub {
76 :     my $ret;
77 :    
78 :     $ret = $self->{fig}->$func(@_);
79 :    
80 :     #
81 :     # Coerce to string if we need to.
82 :     #
83 :    
84 :     if (!ref($ret))
85 :     {
86 :     $ret = $self->coerce_to_string($ret);
87 :     }
88 :    
89 :     return $ret;
90 :     }
91 :     }
92 :    
93 :     #
94 :     # Wrap a FIG method that returns a list. The list needs to be
95 :     # converted into a list reference instead of a plain list.
96 :     #
97 :    
98 :     sub wrap_array_return
99 :     {
100 :     my($self, $func) = @_;
101 :    
102 :     #
103 :     # We return a new anonymous subroutine that invokes the
104 :     # routine thru the $fig instance saved in our instance variables.
105 :     #
106 :    
107 :     return sub {
108 :     my $ret;
109 :     my @func_ret;
110 :    
111 :     $ret = [];
112 :    
113 :     #
114 :     # Invoke the function.
115 :     #
116 :     @func_ret = $self->{fig}->$func(@_);
117 :    
118 :     #
119 :     # For each value returned, if it isn't a reference (to a list, for instance),
120 :     # coerce it to a string.
121 :     #
122 :     # Push each value to the list we're creating.
123 :     #
124 :     for $_ (@func_ret)
125 :     {
126 :     if (ref($_))
127 :     {
128 :     push(@$ret, $_);
129 :     }
130 :     else
131 :     {
132 :     push(@$ret, $self->coerce_to_string($_));
133 :     }
134 :     }
135 :     return $ret;
136 :     }
137 :     }
138 :    
139 :     #
140 :     # back in the main package, finished with class definition.
141 :     #
142 :    
143 :     package main;
144 :    
145 :     $| = 1; # Perl magic to use unbuffered output on standard output
146 :    
147 :     my $xml_rpc_server = Frontier::RPC2->new;
148 :    
149 :     my $fig = new FIG;
150 :    
151 :     #
152 :     # Create a wrapper-helper object.
153 :     #
154 :    
155 :     my $wrapper = new FrontierXMLRPCWrapper($fig, $xml_rpc_server);
156 :    
157 :     #
158 :     # Create a list of the methods to be served
159 :     #
160 :    
161 :     my $methods = {
162 :     'abbrev' => $wrapper->wrap_scalar_return("abbrev"),
163 :     'add_chromosomal_clusters' => $wrapper->wrap_scalar_return("add_chromosomal_clusters"),
164 :     'add_genome' => $wrapper->wrap_scalar_return("add_genome"),
165 :     'add_pch_pins' => $wrapper->wrap_scalar_return("add_pch_pins"),
166 :     'all_compounds' => $wrapper->wrap_array_return("all_compounds"),
167 : olson 1.3 'all_constructs' => $wrapper->wrap_array_return("all_constructs"),
168 : mkubal 1.1 'all_exchangable_subsystems' => $wrapper->wrap_array_return("all_exchangable_subsystems"),
169 :     'all_features' => $wrapper->wrap_array_return("all_features"),
170 :     'all_maps' => $wrapper->wrap_array_return("all_maps"),
171 :     'all_protein_families' => $wrapper->wrap_array_return("all_protein_families"),
172 :     'all_reactions' => $wrapper->wrap_array_return("all_reactions"),
173 :     'all_roles' => $wrapper->wrap_array_return("all_roles"),
174 :     'all_sets' => $wrapper->wrap_array_return("all_sets"),
175 : olson 1.2 'all_subsystems' => $wrapper->wrap_array_return("all_subsystems"),
176 : mkubal 1.1 'assign_function' => $wrapper->wrap_scalar_return("assign_function"),
177 :     'assign_functionF' => $wrapper->wrap_scalar_return("assign_functionF"),
178 : mkubal 1.7 'assigned_pegs' => $wrapper->wrap_array_return("assigned_pegs"),
179 :     'assigned_pegs_in_ss' => $wrapper->wrap_array_return("assigned_pegs_in_ss"),
180 :     'assigned_pegs_not_in_ss' => $wrapper->wrap_array_return("assigned_pegs_not_in_ss"),
181 : mkubal 1.1 'assignments_made' => $wrapper->wrap_array_return("assignments_made"),
182 :     'auto_assign' => $wrapper->wrap_scalar_return("auto_assign"),
183 :     'auto_assignF' => $wrapper->wrap_scalar_return("auto_assignF"),
184 :     'auto_assignG' => $wrapper->wrap_scalar_return("auto_assignG"),
185 :     'between' => $wrapper->wrap_scalar_return("between"),
186 :     'blast' => $wrapper->wrap_array_return("blast"),
187 :     'blastit' => $wrapper->wrap_array_return("blastit"),
188 :     'boundaries_of' => $wrapper->wrap_scalar_return("boundaries_of"),
189 :     'build_tree_of_complete' => $wrapper->wrap_array_return("build_tree_of_complete"),
190 : efrank 1.10 'by_alias' => $wrapper->wrap_array_return("by_alias"),
191 : mkubal 1.1 'by_fig_id' => $wrapper->wrap_scalar_return("by_fig_id"),
192 :     'cas' => $wrapper->wrap_scalar_return("cas"),
193 :     'cas_to_cid' => $wrapper->wrap_scalar_return("cas_to_cid"),
194 :     'catalyzed_by' => $wrapper->wrap_array_return("catalyzed_by"),
195 :     'catalyzes' => $wrapper->wrap_array_return("catalyzes"),
196 :     'cgi_url' => $wrapper->wrap_scalar_return("cgi_url"),
197 :     'clean_tmp' => $wrapper->wrap_scalar_return("clean_tmp"),
198 :     'close_genes' => $wrapper->wrap_array_return("close_genes"),
199 :     'comp2react' => $wrapper->wrap_scalar_return("comp2react"),
200 :     'contig_ln' => $wrapper->wrap_scalar_return("contig_ln"),
201 :     'coupling_and_evidence' => $wrapper->wrap_array_return("coupling_and_evidence"),
202 :     'crude_estimate_of_distance' => $wrapper->wrap_scalar_return("crude_estimate_of_distance"),
203 :     'delete_genomes' => $wrapper->wrap_scalar_return("delete_genomes"),
204 :     'displayable_reaction' => $wrapper->wrap_scalar_return("displayable_reaction"),
205 :     'dna_seq' => $wrapper->wrap_scalar_return("dna_seq"),
206 :     'dsims' => $wrapper->wrap_array_return("dsims"),
207 :     'ec_to_maps' => $wrapper->wrap_array_return("ec_to_maps"),
208 :     'ec_name' => $wrapper->wrap_scalar_return("ec_name"),
209 :     'expand_ec' => $wrapper->wrap_scalar_return("expand_ec"),
210 :     'epoch_to_readable' => $wrapper->wrap_scalar_return("epoch_to_readable"),
211 :     'export_chromosomal_clusters' => $wrapper->wrap_scalar_return("export_chromosomal_clusters"),
212 :     'export_pch_pins' => $wrapper->wrap_scalar_return("export_pch_pins"),
213 :     'export_set' => $wrapper->wrap_scalar_return("export_set"),
214 :     'exportable_subsystem' => $wrapper->wrap_scalar_return("exportable_subsystem"),
215 :     'extract_seq' => $wrapper->wrap_scalar_return("extract_seq"),
216 :     'family_function' => $wrapper->wrap_scalar_return("family_function"),
217 :     'fast_coupling' => $wrapper->wrap_array_return("fast_coupling"),
218 :     'feature_aliases' => $wrapper->wrap_array_return("feature_aliases"),
219 :     'feature_annotations' => $wrapper->wrap_array_return("feature_annotations"),
220 :     'feature_location' => $wrapper->wrap_scalar_return("feature_location"),
221 :     'file2N' => $wrapper->wrap_scalar_return("file_2N"),
222 :     'ftype' => $wrapper->wrap_scalar_return("ftype"),
223 :     'function_of' => $wrapper->wrap_scalar_return("function_of"),
224 :     'genes_in_region' => $wrapper->wrap_array_return("genes_in_region"),
225 :     'genome_of' => $wrapper->wrap_scalar_return("genome_of"),
226 :     'genomes' => $wrapper->wrap_array_return("genomes"),
227 :     'genome_counts' => $wrapper->wrap_scalar_return("genome_counts"),
228 :     'genome_version' => $wrapper->wrap_scalar_return("genome_version"),
229 :     'genus_species' => $wrapper->wrap_scalar_return("genus_species"),
230 :     'get_translation' => $wrapper->wrap_scalar_return("get_translation"),
231 :     'get_translations' => $wrapper->wrap_array_return("get_translations"),
232 :     'hypo' => $wrapper->wrap_scalar_return("hypo"),
233 :     'ids_in_family' => $wrapper->wrap_array_return("ids_in_family"),
234 :     'ids_in_set' => $wrapper->wrap_array_return("ids_in_set"),
235 :     'in_cluster_with' => $wrapper->wrap_array_return("in_cluster_with"),
236 :     'in_family' => $wrapper->wrap_scalar_return("in_family"),
237 :     'in_pch_pin_with' => $wrapper->wrap_array_return("in_pch_pin_with"),
238 :     'in_sets' => $wrapper->wrap_array_return("in_sets"),
239 :     'is_archaeal' => $wrapper->wrap_scalar_return("is_archaeal"),
240 :     'is_bacterial' => $wrapper->wrap_scalar_return("is_bacterial"),
241 :     'is_eukaryotic' => $wrapper->wrap_scalar_return("is_eukaryotic"),
242 :     'is_prokaryotic' => $wrapper->wrap_scalar_return("is_prokaryotic"),
243 :     'is_exchangable_subsytem' => $wrapper->wrap_scalar_return("is_exchangable_subsystem"),
244 :     'is_real_feature' => $wrapper->wrap_scalar_return("is_real_feature"),
245 :     'largest_clusters' => $wrapper->wrap_array_return("largest_clusters"),
246 :     'load_all' => $wrapper->wrap_scalar_return("load_all"),
247 :     'map_to_ecs' => $wrapper->wrap_array_return("map_to_ecs"),
248 :     'map_name' => $wrapper->wrap_scalar_return("map_name"),
249 :     'mapped_prot_ids' => $wrapper->wrap_array_return("mapped_prot_ids"),
250 :     'maps_to_id' => $wrapper->wrap_array_return("maps_to_id"),
251 :     'max' => $wrapper->wrap_scalar_return("max"),
252 :     'merged_related_annotations' => $wrapper->wrap_scalar_return("merged_related_annotations"),
253 :     'min' => $wrapper->wrap_scalar_return("min"),
254 :     'names_of_compound' => $wrapper->wrap_array_return("names_of_compund"),
255 :     'neighborhood_of_role' => $wrapper->wrap_scalar_return("neighborhood_of_role"),
256 :     'org_of' => $wrapper->wrap_scalar_return("org_of"),
257 :     'pegs_of' => $wrapper->wrap_array_return("pegs_of"),
258 : efrank 1.10 'pegs_in_subsystem_cell' => $wrapper->wrap_array_return("pegs_in_subsystem_cell"),
259 : mkubal 1.1 'possibly_truncated' => $wrapper->wrap_scalar_return("possibly_truncated"),
260 :     'reaction2comp' => $wrapper->wrap_scalar_return("reaction2comp"),
261 :     'related_by_func_sim' => $wrapper->wrap_array_return("related_by_func_sim"),
262 :     'reversible' => $wrapper->wrap_scalar_return("reversible"),
263 :     'rnas_of' => $wrapper->wrap_array_return("rnas_of"),
264 :     'roles_of_function' => $wrapper->wrap_array_return("roles_of_function"),
265 :     'search_index' => $wrapper->wrap_array_return("search_index"),
266 :     'seqs_with_role' => $wrapper->wrap_array_return("seqs_with_role"),
267 :     'seqs_with_roles_in_genome' => $wrapper->wrap_scalar_return("seqs_with_roles_in_genomes"),
268 :     'sims' => $wrapper->wrap_array_return("sims"),
269 :     'sort_fids_by_taxonomy' => $wrapper->wrap_array_return("sort_fids_by_taxonomy"),
270 :     'sort_genomes_by_taxonomy' => $wrapper->wrap_array_return("sort_genomes_by_taxonomy"),
271 : efrank 1.10 'subsystem_genomes' => $wrapper->wrap_array_return("subsystem_genomes"),
272 :     'subsystems_for_genome' => $wrapper->wrap_array_return("subsystems_for_genome"),
273 : olson 1.2 'subsystem_info' => $wrapper->wrap_array_return("subsystem_info"),
274 : efrank 1.8 'subsystem_to_roles' => $wrapper->wrap_array_return("subsystem_to_roles"),
275 : mkubal 1.4 'subsystems_for_peg' => $wrapper->wrap_array_return("subsystems_for_peg"),
276 : mkubal 1.1 'sz_family' => $wrapper->wrap_scalar_return("sz_family"),
277 :     'taxonomic_groups_of_complete' => $wrapper->wrap_array_return("taxonomic_groups_of_complete"),
278 :     'taxonomy_of' => $wrapper->wrap_scalar_return("taxonomy_of"),
279 :     'translatable' => $wrapper->wrap_scalar_return("translatable"),
280 :     'translate_function' => $wrapper->wrap_scalar_return("translate_function"),
281 :     'translated_function_of' => $wrapper->wrap_scalar_return("translated_function_of"),
282 :     'translation_length' => $wrapper->wrap_scalar_return("translation_length"),
283 :     'unique_functions' => $wrapper->wrap_array_return("unique_functions"),
284 :     'verify_directory' => $wrapper->wrap_scalar_return("verify_directory"),
285 :    
286 :     };
287 :    
288 :     process_cgi_call($methods);
289 :    
290 :     #==========================================================================
291 :     # CGI Support
292 :     #==========================================================================
293 :     # Simple CGI support for Frontier::RPC2. You can copy this into your CGI
294 :     # scripts verbatim, or you can package it into a library.
295 :     # (Based on xmlrpc_cgi.c by Eric Kidd <http://xmlrpc-c.sourceforge.net/>.)
296 :    
297 :     # Process a CGI call.
298 :     sub process_cgi_call ($) {
299 :     my ($methods) = @_;
300 :    
301 :     # Get our CGI request information.
302 :     my $method = $ENV{'REQUEST_METHOD'};
303 :     my $type = $ENV{'CONTENT_TYPE'};
304 :     my $length = $ENV{'CONTENT_LENGTH'};
305 :    
306 :     # Perform some sanity checks.
307 :     http_error(405, "Method Not Allowed") unless $method eq "POST";
308 :     http_error(400, "Bad Request") unless $type eq "text/xml";
309 :     http_error(411, "Length Required") unless $length > 0;
310 :    
311 :     # Fetch our body.
312 :     my $body;
313 :     my $count = read STDIN, $body, $length;
314 :     http_error(400, "Bad Request") unless $count == $length;
315 :    
316 :     # Serve our request.
317 :     my $coder = Frontier::RPC2->new;
318 :     send_xml($coder->serve($body, $methods));
319 :     }
320 :    
321 :     # Send an HTTP error and exit.
322 :     sub http_error ($$) {
323 :     my ($code, $message) = @_;
324 :     print <<"EOD";
325 :     Status: $code $message
326 :     Content-type: text/html
327 :    
328 :     <title>$code $message</title>
329 :     <h1>$code $message</h1>
330 :     <p>Unexpected error processing XML-RPC request.</p>
331 :     EOD
332 :     exit 0;
333 :     }
334 :    
335 :     # Send an XML document (but don't exit).
336 :     sub send_xml ($) {
337 :     my ($xml_string) = @_;
338 :     my $length = length($xml_string);
339 :     print <<"EOD";
340 :     Status: 200 OK
341 :     Content-type: text/xml
342 :     Content-length: $length
343 :    
344 :     EOD
345 :     # We want precise control over whitespace here.
346 :     print $xml_string;
347 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3