-
Notifications
You must be signed in to change notification settings - Fork 0
/
symbol_checker.rb
41 lines (33 loc) · 974 Bytes
/
symbol_checker.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
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
class SymbolChecker
require 'net/http'
require 'uri'
require 'rubygems'
require 'json'
require 'pp'
def check_gene_symbols(gene_symbols_array)
server="http://rest.genenames.org"
confirmed_gene_symbols = Array.new
missing_gene_symbols = Array.new
gene_symbols_array.each do |this_symbol|
get_path = "/fetch/symbol/#{this_symbol}"
url = URI.parse(server)
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(get_path, {'Accept' => 'application/json'})
response = http.request(request)
if response.code != "200"
puts "Invalid response: #{response.code}"
puts response.body
exit
end
result = JSON.parse(response.body)
if result.fetch("response").fetch("numFound") > 0
confirmed_gene_symbols.push("#{this_symbol}")
else
missing_gene_symbols.push("#{this_symbol}")
end
#pp result
end
results[confirmed_gene_symbols, missing_gene_symbols]
return results
end
end