Class: UniprotMapper
- Inherits:
-
Object
- Object
- UniprotMapper
- Defined in:
- lib/protk/uniprot_mapper.rb
Overview
Provides access to uniprot.org via its API See docs and examples here www.uniprot.org/faq/28#id_mapping_examples
Instance Method Summary collapse
-
#initialize ⇒ UniprotMapper
constructor
A new instance of UniprotMapper.
- #map(from_id_type, from_ids, output_id) ⇒ Object
Constructor Details
#initialize ⇒ UniprotMapper
Returns a new instance of UniprotMapper.
10 11 12 |
# File 'lib/protk/uniprot_mapper.rb', line 10 def initialize @genv = Constants.new end |
Instance Method Details
#map(from_id_type, from_ids, output_id) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/protk/uniprot_mapper.rb', line 14 def map(from_id_type,from_ids,output_id) from_query = from_ids.join(" ") base = 'www.uniprot.org' tool = 'mapping' params = { 'from' => from_id_type, 'to' => output_id, 'format' => 'tab', 'query' => from_query } http = Net::HTTP.new base @genv.log "Mapping to #{output_id}" ,:info response = http.request_post '/' + tool + '/', params.keys.map {|key| key + '=' + params[key]}.join('&') loc = nil while response.code == '302' loc = response['Location'] response = http.request_get loc end while loc wait = response['Retry-After'] or break @genv.log "Waiting (#{wait})..." , :info sleep wait.to_i response = http.request_get loc end response.value # raises http error if not 2xx return response.body end |