Class | Bio::KEGG::API |
In: |
lib/bio/io/keggapi.rb
|
Parent: | Bio::SOAPWSDL |
KEGG API is a web service to use KEGG system via SOAP/WSDL.
For more informations on KEGG API, see the following site and read the reference manual.
In BioRuby, returned values are added filter method to pick up values in a complex data type as an array.
#!/usr/bin/env ruby require 'bio' serv = Bio::KEGG::API.new results = serv.get_best_neighbors_by_gene("eco:b0002", "bsu") # case 0 : without filter results.each do |hit| print hit.genes_id1, "\t", hit.genes_id2, "\t", hit.sw_score, "\n" end # case 1 : select gene names and SW score only fields = [:genes_id1, :genes_id2, :sw_score] results.each do |hit| puts hit.filter(fields).join("\t") end # case 2 : also uses aligned position in each amino acid sequence etc. fields1 = [:genes_id1, :start_position1, :end_position1, :best_flag_1to2] fields2 = [:genes_id2, :start_position2, :end_position2, :best_flag_2to1] results.each do |hit| print "> score: ", hit.sw_score, ", identity: ", hit.identity, "\n" print "1:\t", hit.filter(fields1).join("\t"), "\n" print "2:\t", hit.filter(fields2).join("\t"), "\n" end
Using filter method will make it easy to change fields to select and keep the script clean.
These methods are wrapper for the methods without all in its name and internally iterate to retrive all the results using start/max_results value pairs described above. For example,
#!/usr/bin/env ruby require 'soap/wsdlDriver' wsdl = "http://soap.genome.jp/KEGG.wsdl" serv = SOAP::WSDLDriverFactory.new(wsdl).create_driver serv.generate_explicit_type = true start = 1 max_results = 100 loop do results = serv.get_best_neighbors_by_gene('eco:b0002', start, max_results) break unless results # when no more results returned results.each do |hit| print hit.genes_id1, "\t", hit.genes_id2, "\t", hit.sw_score, "\n" end start += max_results end
can be witten as
#!/usr/bin/env ruby require 'bio' serv = Bio::KEGG::API.new results = serv.get_all_best_neighbors_by_gene('eco:b0002') results.each do |hit| print hit.genes_id1, "\t", hit.genes_id2, "\t", hit.sw_score, "\n" end
Some methods of the KEGG API will return a URL of the generated image. This method save an image specified by the URL. The filename can be specified by its second argument, otherwise basename of the URL will be used.
#!/usr/bin/env ruby require 'bio' serv = Bio::KEGG::API.new("http://soap.genome.jp/v3.0/KEGG.wsdl") list = ["eco:b1002", "eco:b2388"] url = serv.mark_pathway_by_objects("path:eco00010", list) # Save with the original filename (eco00010.gif in this case) serv.save_image(url) # or save as "save_image.gif" serv.save_image(url, "save_image.gif")
These methods are for the shortcut and backward compatibility (these methods existed in the older version of the KEGG API).
SERVER_URI | = | "http://soap.genome.jp/KEGG.wsdl" |
max_results | [RW] | Returns current value for the ‘max_results’ number for the methods having start/max_results argument pairs or changes the default value for the ‘max_results’ count. If your request timeouts, try smaller value for the max_results. |
start | [RW] | Returns current value for the ‘start’ count for the methods having start/max_results argument pairs or changes the default value for the ‘start’ count. |
Connect to the KEGG API‘s SOAP server. A WSDL file will be automatically downloaded and parsed to generate the SOAP client driver. The default URL for the WSDL is soap.genome.jp/KEGG.wsdl but it can be changed by the argument or by wsdl= method.
# File lib/bio/io/keggapi.rb, line 196 196: def initialize(wsdl = nil) 197: @wsdl = wsdl || SERVER_URI 198: @log = nil 199: @start = 1 200: @max_results = 100 201: create_driver 202: end
# File lib/bio/io/keggapi.rb, line 292 292: def get_aaseqs(ary = []) 293: result = '' 294: step = [@max_results, 50].min 295: 0.step(ary.length, step) do |i| 296: str = "-f -n a " + ary[i, step].join(" ") 297: if entry = @driver.send(:bget, str) 298: result << entry.to_s 299: end 300: end 301: return result 302: end
def get_all_neighbors_by_gene(genes_id, org)
get_all(:get_neighbors_by_gene, genes_id, org)
end
# File lib/bio/io/keggapi.rb, line 230 230: def get_all_best_best_neighbors_by_gene(genes_id) 231: get_all(:get_best_best_neighbors_by_gene, genes_id) 232: end
# File lib/bio/io/keggapi.rb, line 234 234: def get_all_best_neighbors_by_gene(genes_id) 235: get_all(:get_best_neighbors_by_gene, genes_id) 236: end
# File lib/bio/io/keggapi.rb, line 246 246: def get_all_genes_by_motifs(motif_id_list) 247: get_all(:get_genes_by_motifs, motif_id_list) 248: end
# File lib/bio/io/keggapi.rb, line 258 258: def get_all_genes_by_organism(org) 259: get_all(:get_genes_by_organism, org) 260: end
# File lib/bio/io/keggapi.rb, line 262 262: def get_all_linkdb_by_entry(entry_id, db) 263: get_all(:get_linkdb_by_entry, entry_id, db) 264: end
# File lib/bio/io/keggapi.rb, line 250 250: def get_all_oc_members_by_gene(genes_id) 251: get_all(:get_oc_members_by_gene, genes_id) 252: end
# File lib/bio/io/keggapi.rb, line 242 242: def get_all_paralogs_by_gene(genes_id) 243: get_all(:get_paralogs_by_gene, genes_id) 244: end
# File lib/bio/io/keggapi.rb, line 254 254: def get_all_pc_members_by_gene(genes_id) 255: get_all(:get_pc_members_by_gene, genes_id) 256: end
# File lib/bio/io/keggapi.rb, line 238 238: def get_all_reverse_best_neighbors_by_gene(genes_id) 239: get_all(:get_reverse_best_neighbors_by_gene, genes_id) 240: end
# File lib/bio/io/keggapi.rb, line 316 316: def get_definitions(ary = []) 317: result = '' 318: step = [@max_results, 50].min 319: 0.step(ary.length, step) do |i| 320: str = ary[i, step].join(" ") 321: if entry = @driver.send(:btit, str) 322: result << entry.to_s 323: end 324: end 325: return result 326: end
# File lib/bio/io/keggapi.rb, line 280 280: def get_entries(ary = []) 281: result = '' 282: step = [@max_results, 50].min 283: 0.step(ary.length, step) do |i| 284: str = ary[i, step].join(" ") 285: if entry = @driver.send(:bget, str) 286: result << entry.to_s 287: end 288: end 289: return result 290: end
# File lib/bio/io/keggapi.rb, line 304 304: def get_naseqs(ary = []) 305: result = '' 306: step = [@max_results, 50].min 307: 0.step(ary.length, step) do |i| 308: str = "-f -n n " + ary[i, step].join(" ") 309: if entry = @driver.send(:bget, str) 310: result << entry.to_s 311: end 312: end 313: return result 314: end
# File lib/bio/io/keggapi.rb, line 215 215: def method_missing(*arg) 216: begin 217: results = @driver.send(*arg) 218: rescue Timeout::Error 219: retry 220: end 221: results = add_filter(results) 222: return results 223: end
# File lib/bio/io/keggapi.rb, line 267 267: def save_image(url, filename = nil) 268: schema, user, host, port, reg, path, = URI.split(url) 269: filename ||= File.basename(path) 270: 271: http = Bio::Command.new_http(host, port) 272: response = http.get(path) 273: File.open(filename, "w+") do |f| 274: f.print response.body 275: end 276: return filename 277: end