bio-ensembl-rest 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.travis.yml +10 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +20 -0
- data/README.md +51 -0
- data/Rakefile +45 -0
- data/lib/bio-ensembl-rest.rb +19 -0
- data/lib/bio-ensembl-rest/comparative-genomics.rb +117 -0
- data/lib/bio-ensembl-rest/cross-reference.rb +55 -0
- data/lib/bio-ensembl-rest/ensembl-rest-main.rb +108 -0
- data/lib/bio-ensembl-rest/features.rb +46 -0
- data/lib/bio-ensembl-rest/information.rb +133 -0
- data/lib/bio-ensembl-rest/lookup.rb +20 -0
- data/lib/bio-ensembl-rest/mapping.rb +55 -0
- data/lib/bio-ensembl-rest/ontologies.rb +68 -0
- data/lib/bio-ensembl-rest/sequence.rb +37 -0
- data/lib/bio-ensembl-rest/taxonomy.rb +30 -0
- data/lib/bio-ensembl-rest/variation.rb +37 -0
- data/test/helper.rb +20 -0
- data/test/test-comparative-genomics.rb +159 -0
- data/test/test-cross-reference.rb +81 -0
- data/test/test-features.rb +76 -0
- data/test/test-information.rb +131 -0
- data/test/test-lookup.rb +45 -0
- data/test/test-mapping.rb +105 -0
- data/test/test-ontologies.rb +116 -0
- data/test/test-sequence.rb +110 -0
- data/test/test-taxonomy.rb +58 -0
- data/test/test-variation.rb +62 -0
- metadata +157 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
module EnsemblRest
|
2
|
+
module Features
|
3
|
+
|
4
|
+
##
|
5
|
+
# Uses the given identifier as a way of indicating the Slice of features required
|
6
|
+
def self.feature_id(id, features, opts = {})
|
7
|
+
opts = EnsemblRest.parse_options opts
|
8
|
+
|
9
|
+
# features is a required parameter, but we need to encode it into the url
|
10
|
+
encoded_query = ""
|
11
|
+
features.each {|f| encoded_query << "feature=#{f};"}
|
12
|
+
|
13
|
+
path = (EnsemblRest.build_path "/feature/id/#{id}", opts) + encoded_query
|
14
|
+
|
15
|
+
if opts['content-type'] == 'ruby'
|
16
|
+
plain_opts = opts.clone
|
17
|
+
plain_opts['content-type'] = 'application/json'
|
18
|
+
return JSON.parse feature_id id, features, plain_opts
|
19
|
+
end
|
20
|
+
|
21
|
+
return EnsemblRest.fetch_data path, opts, 'features'
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
##
|
26
|
+
# Retrieves multiple types of features for a given region
|
27
|
+
def self.feature_region(species, region, features, opts = {})
|
28
|
+
opts = EnsemblRest.parse_options opts
|
29
|
+
|
30
|
+
# features is a required parameter, but we need to encode it into the url
|
31
|
+
encoded_query = ""
|
32
|
+
features.each {|f| encoded_query << "feature=#{f};"}
|
33
|
+
|
34
|
+
path = (EnsemblRest.build_path "/feature/region/#{species}/#{region}", opts) + encoded_query
|
35
|
+
|
36
|
+
if opts['content-type'] == 'ruby'
|
37
|
+
plain_opts = opts.clone
|
38
|
+
plain_opts['content-type'] = 'application/json'
|
39
|
+
return JSON.parse feature_region species, region, features, plain_opts
|
40
|
+
end
|
41
|
+
|
42
|
+
return EnsemblRest.fetch_data path, opts, 'features'
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module EnsemblRest
|
2
|
+
module Information
|
3
|
+
|
4
|
+
##
|
5
|
+
# Returns information about the current available assemblies in this given species
|
6
|
+
def self.assembly_info(species, opts = {})
|
7
|
+
opts = EnsemblRest.parse_options opts
|
8
|
+
path = EnsemblRest.build_path "/assembly/info/#{species}", opts
|
9
|
+
|
10
|
+
if opts['content-type'] == 'ruby'
|
11
|
+
plain_opts = opts.clone
|
12
|
+
plain_opts['content-type'] = 'application/json'
|
13
|
+
return JSON.parse assembly_info species, plain_opts
|
14
|
+
end
|
15
|
+
|
16
|
+
return EnsemblRest.fetch_data path, opts, 'information'
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
##
|
21
|
+
# Returns information about the given toplevel sequence region given to this endpoint
|
22
|
+
def self.assembly_info_region(species, region, opts = {})
|
23
|
+
opts = EnsemblRest.parse_options opts
|
24
|
+
path = EnsemblRest.build_path "/assembly/info/#{species}/#{region}", opts
|
25
|
+
|
26
|
+
if opts['content-type'] == 'ruby'
|
27
|
+
plain_opts = opts.clone
|
28
|
+
plain_opts['content-type'] = 'application/json'
|
29
|
+
return JSON.parse assembly_info_region species, plain_opts
|
30
|
+
end
|
31
|
+
|
32
|
+
return EnsemblRest.fetch_data path, opts, 'information'
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
##
|
37
|
+
# Lists all available comparative genomics databases and their data release
|
38
|
+
def self.info_comparas(opts = {})
|
39
|
+
opts = EnsemblRest.parse_options opts
|
40
|
+
path = EnsemblRest.build_path "/info/comparas", opts
|
41
|
+
|
42
|
+
if opts['content-type'] == 'ruby'
|
43
|
+
plain_opts = opts.clone
|
44
|
+
plain_opts['content-type'] = 'application/json'
|
45
|
+
return JSON.parse info_comparas plain_opts
|
46
|
+
end
|
47
|
+
|
48
|
+
return EnsemblRest.fetch_data path, opts, 'information'
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
##
|
53
|
+
# Shows the data releases available on this REST server
|
54
|
+
def self.info_data(opts = {})
|
55
|
+
opts = EnsemblRest.parse_options opts
|
56
|
+
path = EnsemblRest.build_path "/info/data", opts
|
57
|
+
|
58
|
+
if opts['content-type'] == 'ruby'
|
59
|
+
plain_opts = opts.clone
|
60
|
+
plain_opts['content-type'] = 'application/json'
|
61
|
+
return JSON.parse info_data plain_opts
|
62
|
+
end
|
63
|
+
|
64
|
+
return EnsemblRest.fetch_data path, opts, 'information'
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
##
|
69
|
+
# Pings the first available DBAdaptor to see if the service is still active
|
70
|
+
def self.info_ping(opts = {})
|
71
|
+
opts = EnsemblRest.parse_options opts
|
72
|
+
path = EnsemblRest.build_path "/info/ping", opts
|
73
|
+
|
74
|
+
if opts['content-type'] == 'ruby'
|
75
|
+
plain_opts = opts.clone
|
76
|
+
plain_opts['content-type'] = 'application/json'
|
77
|
+
return JSON.parse info_ping plain_opts
|
78
|
+
end
|
79
|
+
|
80
|
+
return EnsemblRest.fetch_data path, opts, 'information'
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
##
|
85
|
+
# Shows the current version of the REST API
|
86
|
+
def self.info_rest(opts = {})
|
87
|
+
opts = EnsemblRest.parse_options opts
|
88
|
+
path = EnsemblRest.build_path "/info/rest", opts
|
89
|
+
|
90
|
+
if opts['content-type'] == 'ruby'
|
91
|
+
plain_opts = opts.clone
|
92
|
+
plain_opts['content-type'] = 'application/json'
|
93
|
+
return JSON.parse info_rest plain_opts
|
94
|
+
end
|
95
|
+
|
96
|
+
return EnsemblRest.fetch_data path, opts, 'information'
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
##
|
101
|
+
# Shows the current version of the Ensembl API
|
102
|
+
def self.info_software(opts = {})
|
103
|
+
opts = EnsemblRest.parse_options opts
|
104
|
+
path = EnsemblRest.build_path "/info/software", opts
|
105
|
+
|
106
|
+
if opts['content-type'] == 'ruby'
|
107
|
+
plain_opts = opts.clone
|
108
|
+
plain_opts['content-type'] = 'application/json'
|
109
|
+
return JSON.parse info_software plain_opts
|
110
|
+
end
|
111
|
+
|
112
|
+
return EnsemblRest.fetch_data path, opts, 'information'
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
##
|
117
|
+
# Lists all available species, their aliases, available adaptor groups and data release
|
118
|
+
def self.info_species(opts = {})
|
119
|
+
opts = EnsemblRest.parse_options opts
|
120
|
+
path = EnsemblRest.build_path "/info/species", opts
|
121
|
+
|
122
|
+
if opts['content-type'] == 'ruby'
|
123
|
+
plain_opts = opts.clone
|
124
|
+
plain_opts['content-type'] = 'application/json'
|
125
|
+
return JSON.parse info_species plain_opts
|
126
|
+
end
|
127
|
+
|
128
|
+
return EnsemblRest.fetch_data path, opts, 'information'
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module EnsemblRest
|
2
|
+
module Lookup
|
3
|
+
|
4
|
+
##
|
5
|
+
# Query for an identifier's location in the available Ensembl databases
|
6
|
+
def self.lookup_id(id, opts = {})
|
7
|
+
opts = EnsemblRest.parse_options opts
|
8
|
+
path = EnsemblRest.build_path "/lookup/id/#{id}", opts
|
9
|
+
|
10
|
+
if opts['content-type'] == 'ruby'
|
11
|
+
plain_opts = opts.clone
|
12
|
+
plain_opts['content-type'] = 'application/json'
|
13
|
+
return JSON.parse lookup_id id, plain_opts
|
14
|
+
end
|
15
|
+
|
16
|
+
return EnsemblRest.fetch_data path, opts, 'lookup'
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module EnsemblRest
|
2
|
+
module Mapping
|
3
|
+
|
4
|
+
##
|
5
|
+
# Convert the co-ordinates of one assembly to another
|
6
|
+
def self.map(asm_one, asm_two, species, region, opts = {})
|
7
|
+
opts = EnsemblRest.parse_options opts
|
8
|
+
path = EnsemblRest.build_path "/map/#{species}/#{asm_one}/#{region}/#{asm_two}", opts
|
9
|
+
|
10
|
+
# TODO: ruby object?
|
11
|
+
if opts['content-type'] == 'ruby'
|
12
|
+
plain_opts = opts.clone
|
13
|
+
plain_opts['content-type'] = 'application/json'
|
14
|
+
return JSON.parse map asm_one, asm_two, species, region, plain_opts
|
15
|
+
end
|
16
|
+
|
17
|
+
return EnsemblRest.fetch_data path, opts, 'mapping'
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
##
|
22
|
+
# Convert from CDNA coordinates to genomic coordinates
|
23
|
+
def self.map_from_cdna(id, region, opts = {})
|
24
|
+
return _map_generic id, region, 'cdna', opts
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Convert from CDS coordinates to genomic coordinates
|
29
|
+
def self.map_from_cds(id, region, opts = {})
|
30
|
+
return _map_generic id, region, 'cds', opts
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Convert from protein (translation) coordinates to genomic coordinates
|
35
|
+
def self.map_from_translation(id, region, opts = {})
|
36
|
+
return _map_generic id, region, 'translation', opts
|
37
|
+
end
|
38
|
+
|
39
|
+
# generic mapping from cdna and cds
|
40
|
+
def self._map_generic(id, region, type, opts = {}) # :nodoc:
|
41
|
+
opts = EnsemblRest.parse_options opts
|
42
|
+
path = EnsemblRest.build_path "/map/#{type}/#{id}/#{region}", opts
|
43
|
+
|
44
|
+
# TODO: ruby object?
|
45
|
+
if opts['content-type'] == 'ruby'
|
46
|
+
plain_opts = opts.clone
|
47
|
+
plain_opts['content-type'] = 'application/json'
|
48
|
+
return JSON.parse _map_generic id, region, type, plain_opts
|
49
|
+
end
|
50
|
+
|
51
|
+
return EnsemblRest.fetch_data path, opts, 'mapping'
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module EnsemblRest
|
2
|
+
module Ontologies
|
3
|
+
|
4
|
+
##
|
5
|
+
# Find all ancestors, all terms above, belonging to a given term
|
6
|
+
def self.ontology_ancestor(id, opts = {})
|
7
|
+
return _ontology_id_generic id, 'ancestors_plain', opts
|
8
|
+
end
|
9
|
+
|
10
|
+
##
|
11
|
+
# Reconstruct the entire ancestory of a term from is_a and part_of relationships.
|
12
|
+
def self.ontology_ancestor_chart(id, opts = {})
|
13
|
+
return _ontology_id_generic id, 'ancestors_chart', opts
|
14
|
+
end
|
15
|
+
|
16
|
+
##
|
17
|
+
# Find all descendents, all terms below, belonging to a given term.
|
18
|
+
def self.ontology_descendents(id, opts = {})
|
19
|
+
return _ontology_id_generic id, 'descendents', opts
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Search for an ontological term by its namespaced identifier
|
24
|
+
def self.ontology_id(id, opts = {})
|
25
|
+
return _ontology_id_generic id, 'plain', opts
|
26
|
+
end
|
27
|
+
|
28
|
+
def self._ontology_id_generic(id, type, opts = {}) # :nodoc:
|
29
|
+
opts = EnsemblRest.parse_options opts
|
30
|
+
case type
|
31
|
+
when 'ancestors_plain'
|
32
|
+
url = "/ontology/ancestors/#{id}"
|
33
|
+
when 'ancestors_chart'
|
34
|
+
url = "/ontology/ancestors/chart/#{id}"
|
35
|
+
when 'descendents'
|
36
|
+
url = "/ontology/descendents/#{id}"
|
37
|
+
when 'plain'
|
38
|
+
url = "/ontology/id/#{id}"
|
39
|
+
end
|
40
|
+
path = EnsemblRest.build_path url, opts
|
41
|
+
|
42
|
+
if opts['content-type'] == 'ruby'
|
43
|
+
plain_opts = opts.clone
|
44
|
+
plain_opts['content-type'] = 'application/json'
|
45
|
+
return JSON.parse _ontology_id_generic id, type, plain_opts
|
46
|
+
end
|
47
|
+
|
48
|
+
return EnsemblRest.fetch_data path, opts, 'ontologies'
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
##
|
53
|
+
# Search for a list of ontological terms by their name and an optional ontology
|
54
|
+
def self.ontology_name(name, opts = {})
|
55
|
+
opts = EnsemblRest.parse_options opts
|
56
|
+
path = EnsemblRest.build_path "/ontology/name/#{name}", opts
|
57
|
+
|
58
|
+
if opts['content-type'] == 'ruby'
|
59
|
+
plain_opts = opts.clone
|
60
|
+
plain_opts['content-type'] = 'application/json'
|
61
|
+
return JSON.parse ontology_name name, plain_opts
|
62
|
+
end
|
63
|
+
|
64
|
+
return EnsemblRest.fetch_data path, opts, 'ontologies'
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module EnsemblRest
|
2
|
+
module Sequence
|
3
|
+
|
4
|
+
##
|
5
|
+
# Query for multiple types of Sequence by its stable identifier
|
6
|
+
def self.sequence_id(id, opts = {})
|
7
|
+
opts = EnsemblRest.parse_options opts
|
8
|
+
path = EnsemblRest.build_path "/sequence/id/#{id}", opts
|
9
|
+
|
10
|
+
# FIXME: if multiseq is true Bio::Sequence can't parse text/plain right
|
11
|
+
if opts['content-type'] == 'ruby'
|
12
|
+
plain_opts = opts.clone
|
13
|
+
plain_opts['content-type'] = 'text/plain'
|
14
|
+
return Bio::Sequence.auto(sequence_id(id, plain_opts))
|
15
|
+
end
|
16
|
+
|
17
|
+
return EnsemblRest.fetch_data path, opts, 'sequence'
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
##
|
22
|
+
# Query for a region of genomic sequence based on its location
|
23
|
+
def self.sequence_region(species, region, opts = {})
|
24
|
+
opts = EnsemblRest.parse_options opts
|
25
|
+
path = EnsemblRest.build_path "/sequence/region/#{species}/#{region}", opts
|
26
|
+
|
27
|
+
if opts['content-type'] == 'ruby'
|
28
|
+
plain_opts = opts.clone
|
29
|
+
plain_opts['content-type'] = 'text/plain'
|
30
|
+
return Bio::Sequence.auto sequence_region(species, region, plain_opts)
|
31
|
+
end
|
32
|
+
|
33
|
+
return EnsemblRest.fetch_data path, opts, 'sequence'
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module EnsemblRest
|
2
|
+
module Taxonomy
|
3
|
+
|
4
|
+
##
|
5
|
+
# Search for a taxonomic term by its identifier or name
|
6
|
+
def self.taxonomy_id(id, opts = {})
|
7
|
+
return _taxonomy_generic id, 'id', opts
|
8
|
+
end
|
9
|
+
|
10
|
+
##
|
11
|
+
# Return the taxonomic classification of a taxon node
|
12
|
+
def self.taxonomy_classification(id, opts = {})
|
13
|
+
return _taxonomy_generic id, 'classification', opts
|
14
|
+
end
|
15
|
+
|
16
|
+
def self._taxonomy_generic(id, type, opts = {}) # :nodoc:
|
17
|
+
opts = EnsemblRest.parse_options opts
|
18
|
+
path = EnsemblRest.build_path "/taxonomy/#{type}/#{id}", opts
|
19
|
+
|
20
|
+
if opts['content-type'] == 'ruby'
|
21
|
+
plain_opts = opts.clone
|
22
|
+
plain_opts['content-type'] = 'application/json'
|
23
|
+
return JSON.parse _taxonomy_generic id, type, plain_opts
|
24
|
+
end
|
25
|
+
|
26
|
+
return EnsemblRest.fetch_data path, opts, 'taxonomy'
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module EnsemblRest
|
2
|
+
module Variation
|
3
|
+
|
4
|
+
##
|
5
|
+
# Fetch variant consequences based on a variation identifier
|
6
|
+
def self.vep_id(id, species, opts = {})
|
7
|
+
opts = EnsemblRest.parse_options opts
|
8
|
+
path = EnsemblRest.build_path "/vep/#{species}/id/#{id}/consequences", opts
|
9
|
+
|
10
|
+
if opts['content-type'] == 'ruby'
|
11
|
+
plain_opts = opts.clone
|
12
|
+
plain_opts['content-type'] = 'application/json'
|
13
|
+
return JSON.parse vep_id id, species, plain_opts
|
14
|
+
end
|
15
|
+
|
16
|
+
return EnsemblRest.fetch_data path, opts, 'variation'
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
##
|
21
|
+
# Fetch variant consequences
|
22
|
+
def self.vep_region(allele, region, species, opts = {})
|
23
|
+
opts = EnsemblRest.parse_options opts
|
24
|
+
path = EnsemblRest.build_path "/vep/#{species}/#{region}/#{allele}/consequences", opts
|
25
|
+
|
26
|
+
# TODO: ruby object?
|
27
|
+
if opts['content-type'] == 'ruby'
|
28
|
+
plain_opts = opts.clone
|
29
|
+
plain_opts['content-type'] = 'application/json'
|
30
|
+
return JSON.parse vep_region allele, region, species, plain_opts
|
31
|
+
end
|
32
|
+
|
33
|
+
return EnsemblRest.fetch_data path, opts, 'taxonomy'
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'test/unit'
|
13
|
+
require 'shoulda'
|
14
|
+
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
17
|
+
|
18
|
+
require 'bio-ensembl-rest'
|
19
|
+
include EnsemblRest
|
20
|
+
|