Module: EnsemblREST
- Defined in:
- lib/ensemblrest/map.rb,
lib/ensemblrest/vep.rb,
lib/ensemblrest/info.rb,
lib/ensemblrest/xref.rb,
lib/ensemblrest/lookup.rb,
lib/ensemblrest/archive.rb,
lib/ensemblrest/connect.rb,
lib/ensemblrest/overlap.rb,
lib/ensemblrest/version.rb,
lib/ensemblrest/sequence.rb,
lib/ensemblrest/variation.rb,
lib/ensemblrest/regulation.rb,
lib/ensemblrest/ontoandtaxo.rb,
lib/ensemblrest/variationga4gh.rb,
lib/ensemblrest/comparativegenomics.rb
Overview
raise “Please, use ruby 1.9.0 or later.” if RUBY_VERSION < “1.9.0”
Defined Under Namespace
Modules: Archive, Comparative, GA4GH, Info, Lookup, Map, Ontology, Overlap, Regulation, Sequence, Taxonomy, VEP, Variation, Xref Classes: InvalidResponse, ServiceNotFound
Constant Summary collapse
- SUPPOTEDFORMATS =
{ 'text' => 'text/plain', 'fasta' => 'text/x-fasta', 'gff3' => 'ext/x-gff3', 'json' => 'application/json', 'msgpack' => 'application/x-msgpack', 'nh' => 'text/x-nh', 'seqxml' => 'text/x-seqxml+xml', 'sereal' => 'application/x-sereal', 'phyloxml' => 'text/x-phyloxml+xml', 'xml' => 'text/xml', 'yaml' => 'text/x-yaml' }
- VERSION =
"1.1.1"
- @@url =
URI.parse('http://rest.ensembl.org')
- @@http_connect =
Net::HTTP.new(@@url.host, @@url.port)
Class Method Summary collapse
-
.connect(server) ⇒ Object
Connect to Ensembl REST Service.
-
.get(get_path, options) ⇒ Object
Do a get request.
-
.parse_options(options) ⇒ Object
Parse options use in the Module only.
-
.parse_response(response, type) ⇒ Object
Parse responses use in the Module only.
-
.post(post_path, request_body, options) ⇒ Object
Do a post request.
-
.use37 ⇒ Object
Switch to use GRCh37 assembly version.
-
.use38 ⇒ Object
Switch to use GRCh38 assembly version.
-
.use_GRCh37 ⇒ Object
Switch to use GRCh37 assembly version.
-
.use_GRCh38 ⇒ Object
Switch to use GRCh38 assembly version.
Class Method Details
.connect(server) ⇒ Object
Connect to Ensembl REST Service
44 45 46 47 |
# File 'lib/ensemblrest/connect.rb', line 44 def connect(server) @@url = URI.parse(server) @@http_connect = Net::HTTP.new(@@url.host, @@url.port) end |
.get(get_path, options) ⇒ Object
Do a get request
119 120 121 122 123 |
# File 'lib/ensemblrest/connect.rb', line 119 def get(get_path, ) = EnsemblREST::() request = Net::HTTP::Get.new("#{get_path}#{[:opts].empty? ? '' : "?#{[:opts].join(';')}"}", [:format]) return EnsemblREST::parse_response(@@http_connect.request(request), [:format]['content-type']) end |
.parse_options(options) ⇒ Object
Parse options use in the Module only
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ensemblrest/connect.rb', line 72 def () = {opts: [], format: {}} .each do |k, v| if k.to_s == 'format' [:format] = {'content-type' => EnsemblREST::SUPPOTEDFORMATS.has_key?(v) ? EnsemblREST::SUPPOTEDFORMATS[v] : v} elsif k.to_s == 'content-type' [:format] = {'content-type' => v} else if v.is_a?(TrueClass) [:opts].push("#{k}=1") elsif v.is_a?(FalseClass) [:opts].push("#{k}=0") elsif v.is_a?(Array) v.each {|member| [:opts].push("#{k}=#{member}")} else [:opts].push("#{k}=#{v}") end end end return end |
.parse_response(response, type) ⇒ Object
Parse responses use in the Module only
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ensemblrest/connect.rb', line 96 def parse_response(response, type) case response.code when '200' case type when 'application/json' return JSON.parse(response.body) when 'ext/x-gff3' return Bio::GFF::GFF3.new(response.body) when 'text/x-fasta' return Bio::FastaFormat.new(response.body) when 'text/x-phyloxml+xml' return Bio::PhyloXML::Parser.new(response.body) else return response.body end when '404' raise EnsemblREST::ServiceNotFound, "Service not found" else raise EnsemblREST::InvalidResponse, "Invalid response: #{response.code}" end end |
.post(post_path, request_body, options) ⇒ Object
Do a post request
126 127 128 129 130 131 |
# File 'lib/ensemblrest/connect.rb', line 126 def post(post_path, request_body, ) = EnsemblREST::() request = Net::HTTP::Post.new(post_path, [:format].merge({'Accept' => 'application/json'})) request.body = request_body.to_json return EnsemblREST::parse_response(@@http_connect.request(request), [:format]['content-type']) end |
.use37 ⇒ Object
Switch to use GRCh37 assembly version
56 57 58 |
# File 'lib/ensemblrest/connect.rb', line 56 def use37 EnsemblREST::use_GRCh37 end |
.use38 ⇒ Object
Switch to use GRCh38 assembly version
67 68 69 |
# File 'lib/ensemblrest/connect.rb', line 67 def use38 EnsemblREST::use_GRCh38 end |
.use_GRCh37 ⇒ Object
Switch to use GRCh37 assembly version
50 51 52 53 |
# File 'lib/ensemblrest/connect.rb', line 50 def use_GRCh37 @@url = URI.parse('http://grch37.rest.ensembl.org/') @@http_connect = Net::HTTP.new(@@url.host, @@url.port) end |
.use_GRCh38 ⇒ Object
Switch to use GRCh38 assembly version
61 62 63 64 |
# File 'lib/ensemblrest/connect.rb', line 61 def use_GRCh38 @@url = URI.parse('http://rest.ensembl.org/') @@http_connect = Net::HTTP.new(@@url.host, @@url.port) end |