dazoakley-biomart 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +15 -0
- data/README.rdoc +113 -0
- data/Rakefile +29 -0
- data/lib/biomart/attribute.rb +12 -0
- data/lib/biomart/database.rb +52 -0
- data/lib/biomart/dataset.rb +179 -0
- data/lib/biomart/filter.rb +13 -0
- data/lib/biomart/server.rb +64 -0
- data/lib/biomart.rb +70 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/test_biomart.rb +96 -0
- data/test/test_helper.rb +9 -0
- metadata +102 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.rdoc
|
4
|
+
Rakefile
|
5
|
+
lib/biomart.rb
|
6
|
+
lib/biomart/attribute.rb
|
7
|
+
lib/biomart/database.rb
|
8
|
+
lib/biomart/dataset.rb
|
9
|
+
lib/biomart/filter.rb
|
10
|
+
lib/biomart/server.rb
|
11
|
+
script/console
|
12
|
+
script/destroy
|
13
|
+
script/generate
|
14
|
+
test/test_biomart.rb
|
15
|
+
test/test_helper.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
= Biomart
|
2
|
+
|
3
|
+
http://biomart.rubyforge.org
|
4
|
+
|
5
|
+
http://github.com/dazoakley/biomart
|
6
|
+
|
7
|
+
Biomart provides a simple interface for working with Biomart servers
|
8
|
+
(see http://www.biomart.org for more info on Biomart itself), so you
|
9
|
+
don't have to get down and dirty with the basic webservice calls yourself.
|
10
|
+
|
11
|
+
== Install
|
12
|
+
|
13
|
+
sudo gem install biomart
|
14
|
+
|
15
|
+
== Usage
|
16
|
+
|
17
|
+
Include the module in your code:
|
18
|
+
|
19
|
+
require "rubygems"
|
20
|
+
require "biomart"
|
21
|
+
|
22
|
+
To basically connect to a Biomart server and have access to all of its
|
23
|
+
information and meta data:
|
24
|
+
|
25
|
+
biomart = Biomart::Server.new( "http://www.biomart.org/biomart" )
|
26
|
+
|
27
|
+
# List all of the available datasets on this Biomart server
|
28
|
+
# (be patient - this will take a while on this server as there's
|
29
|
+
# a lot there...)
|
30
|
+
p biomart.list_datasets
|
31
|
+
|
32
|
+
# Grab the "kermits" dataset
|
33
|
+
kermits = biomart.datasets["kermits"]
|
34
|
+
|
35
|
+
# List it's filters and attributes
|
36
|
+
p kermits.list_filters
|
37
|
+
p kermits.list_attributes
|
38
|
+
|
39
|
+
# Count the total number of records in the dataset
|
40
|
+
p kermits.count()
|
41
|
+
|
42
|
+
# Do a count with a filter added
|
43
|
+
p kermits.count( :filters => { "sponsor" => "EUCOMM" } )
|
44
|
+
|
45
|
+
# Do a search using the default filters and attributes
|
46
|
+
# - this will return a hash with :headers (an array of the headers) and :data (an array of arrays of results)
|
47
|
+
# Doing a search like this is generally a BAD idea as biomarts tend to hold a LOT of data... Unless you have time to kill...
|
48
|
+
p kermits.search()
|
49
|
+
|
50
|
+
# Do a search using some specific filters (but the default attributes)
|
51
|
+
p kermits.search( :filters => { "marker_symbol" => "Cbx1" } )
|
52
|
+
|
53
|
+
# Do a search with specific filters and attributes
|
54
|
+
p kermits.search( :filters => { "marker_symbol" => "Cbx1" }, :attributes => ["marker_symbol"] )
|
55
|
+
|
56
|
+
# If you would like to retrieve a more useful results object - i.e. an array of hashes, where each
|
57
|
+
# hash represents a row of results (keyed by the attribute name), add the :process_results argument
|
58
|
+
p kermits.search( :filters => { "marker_symbol" => "Cbx1" }, :process_results => true )
|
59
|
+
|
60
|
+
Or if you know the dataset you wish to work with and would like to
|
61
|
+
just get on with things...
|
62
|
+
|
63
|
+
htgt_targ = Biomart::Dataset.new( "http://www.sanger.ac.uk/htgt/biomart", { :name => "htgt_targ" } )
|
64
|
+
p htgt_targ.count( :filters => { "is_eucomm" => "1" } )
|
65
|
+
|
66
|
+
# etc. etc.
|
67
|
+
|
68
|
+
See Biomart module and Class docs for more detail.
|
69
|
+
|
70
|
+
== Using a Proxy
|
71
|
+
|
72
|
+
If you need to channel all of your requests via a proxy, specify your
|
73
|
+
proxy via Biomart.proxy:
|
74
|
+
|
75
|
+
Biomart.proxy = "http://proxy.example.com/"
|
76
|
+
|
77
|
+
Now all requests made through Biomart will be proxied via http://proxy.example.com.
|
78
|
+
|
79
|
+
Alternatively you can also set your proxy url in the environment variable
|
80
|
+
'http_proxy', and Biomart will automatically detect this.
|
81
|
+
|
82
|
+
== Meta
|
83
|
+
|
84
|
+
Written by Darren Oakley (daz dot oakley at gmail dot com)
|
85
|
+
|
86
|
+
http://biomart.rubyforge.org
|
87
|
+
|
88
|
+
http://github.com/dazoakley/biomart
|
89
|
+
|
90
|
+
== License
|
91
|
+
|
92
|
+
(The MIT License)
|
93
|
+
|
94
|
+
Copyright (c) 2009 Darren Oakley
|
95
|
+
|
96
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
97
|
+
a copy of this software and associated documentation files (the
|
98
|
+
'Software'), to deal in the Software without restriction, including
|
99
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
100
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
101
|
+
permit persons to whom the Software is furnished to do so, subject to
|
102
|
+
the following conditions:
|
103
|
+
|
104
|
+
The above copyright notice and this permission notice shall be
|
105
|
+
included in all copies or substantial portions of the Software.
|
106
|
+
|
107
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
108
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
109
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
110
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
111
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
112
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
113
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/biomart'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
# Hoe.plugin :website
|
9
|
+
# Hoe.plugin :cucumberfeatures
|
10
|
+
|
11
|
+
# Generate all the Rake tasks
|
12
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
+
$hoe = Hoe.spec 'biomart' do
|
14
|
+
self.developer 'Darren Oakley', 'daz.oakley@gmail.com'
|
15
|
+
self.rubyforge_name = self.name
|
16
|
+
self.url = "http://github.com/dazoakley/biomart"
|
17
|
+
self.summary = "A ruby API for interacting with Biomart services."
|
18
|
+
self.description = "A ruby API for interacting with Biomart services."
|
19
|
+
self.extra_deps = [['builder','>= 0']]
|
20
|
+
self.extra_rdoc_files = ["README.rdoc"]
|
21
|
+
self.extra_dev_deps = [['thoughtbot-shoulda','>=0']]
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'newgem/tasks'
|
25
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
26
|
+
|
27
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
28
|
+
# remove_task :default
|
29
|
+
# task :default => [:spec, :features]
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Biomart
|
2
|
+
class Database
|
3
|
+
include Biomart
|
4
|
+
|
5
|
+
attr_reader :name, :display_name, :visible
|
6
|
+
|
7
|
+
def initialize( url, args )
|
8
|
+
@url = url or raise ArgumentError, "must pass :url"
|
9
|
+
unless @url =~ /martservice/
|
10
|
+
@url = @url + "/martservice"
|
11
|
+
end
|
12
|
+
|
13
|
+
@name = args["name"] || args[:name]
|
14
|
+
@display_name = args["displayName"] || args[:display_name]
|
15
|
+
@visible = ( args["visible"] || args[:visible] ) ? true : false
|
16
|
+
@datasets = {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def list_datasets
|
20
|
+
if @datasets.empty?
|
21
|
+
fetch_datasets
|
22
|
+
end
|
23
|
+
return @datasets.keys
|
24
|
+
end
|
25
|
+
|
26
|
+
def datasets
|
27
|
+
if @datasets.empty?
|
28
|
+
fetch_datasets
|
29
|
+
end
|
30
|
+
return @datasets
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def fetch_datasets
|
36
|
+
url = @url + "?type=datasets&mart=#{@name}"
|
37
|
+
document = request( :url => url )
|
38
|
+
tsv_data = CSV.parse( document, "\t" )
|
39
|
+
tsv_data.each do |t|
|
40
|
+
if t[1] and ( t[3] === "1" )
|
41
|
+
dataset_attr = {
|
42
|
+
"name" => t[1],
|
43
|
+
"displayName" => t[2],
|
44
|
+
"visible" => t[3]
|
45
|
+
}
|
46
|
+
@datasets[ dataset_attr["name"] ] = Dataset.new( @url, dataset_attr )
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
module Biomart
|
2
|
+
class Dataset
|
3
|
+
include Biomart
|
4
|
+
|
5
|
+
attr_reader :name, :display_name, :visible
|
6
|
+
|
7
|
+
def initialize( url, args )
|
8
|
+
@url = url or raise ArgumentError, "must pass :url"
|
9
|
+
unless @url =~ /martservice/
|
10
|
+
@url = @url + "/martservice"
|
11
|
+
end
|
12
|
+
|
13
|
+
@name = args["name"] || args[:name]
|
14
|
+
@display_name = args["displayName"] || args[:display_name]
|
15
|
+
@visible = ( args["visible"] || args[:visible] ) ? true : false
|
16
|
+
|
17
|
+
@filters = {}
|
18
|
+
@attributes = {}
|
19
|
+
@importables = {}
|
20
|
+
@exportables = {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def filters
|
24
|
+
if @filters.empty?
|
25
|
+
fetch_configuration()
|
26
|
+
end
|
27
|
+
return @filters
|
28
|
+
end
|
29
|
+
|
30
|
+
def list_filters
|
31
|
+
if @filters.empty?
|
32
|
+
fetch_configuration()
|
33
|
+
end
|
34
|
+
return @filters.keys
|
35
|
+
end
|
36
|
+
|
37
|
+
def attributes
|
38
|
+
if @attributes.empty?
|
39
|
+
fetch_configuration()
|
40
|
+
end
|
41
|
+
return @attributes
|
42
|
+
end
|
43
|
+
|
44
|
+
def list_attributes
|
45
|
+
if @attributes.empty?
|
46
|
+
fetch_configuration()
|
47
|
+
end
|
48
|
+
return @attributes.keys
|
49
|
+
end
|
50
|
+
|
51
|
+
def count( args={} )
|
52
|
+
args.merge!({ :count => "1" })
|
53
|
+
result = request( :method => 'post', :url => @url, :query => generate_xml(args) )
|
54
|
+
return result.to_i
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
def search( args={} )
|
59
|
+
response = request( :method => 'post', :url => @url, :query => generate_xml(args) )
|
60
|
+
result = process_tsv( args, response )
|
61
|
+
result = convert_results_to_array_of_hashes( result ) if args[:process_results]
|
62
|
+
return result
|
63
|
+
end
|
64
|
+
|
65
|
+
# Utility function to build the Biomart query XML
|
66
|
+
def generate_xml( args={} )
|
67
|
+
biomart_xml = ""
|
68
|
+
xml = Builder::XmlMarkup.new( :target => biomart_xml, :indent => 2 )
|
69
|
+
|
70
|
+
xml.instruct!
|
71
|
+
xml.declare!( :DOCTYPE, :Query )
|
72
|
+
xml.Query( :virtualSchemaName => "default", :formatter => "TSV", :header => "0", :uniqueRows => "1", :count => args[:count], :datasetConfigVersion => "0.6" ) {
|
73
|
+
xml.Dataset( :name => @name, :interface => "default" ) {
|
74
|
+
|
75
|
+
if args[:filters]
|
76
|
+
args[:filters].each do |name,value|
|
77
|
+
if value.is_a? Array
|
78
|
+
value = value.join(",")
|
79
|
+
end
|
80
|
+
xml.Filter( :name => name, :value => value )
|
81
|
+
end
|
82
|
+
else
|
83
|
+
self.filters.each do |name,filter|
|
84
|
+
if filter.default
|
85
|
+
xml.Filter( :name => name, :value => filter.default_value )
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
unless args[:count]
|
91
|
+
if args[:attributes]
|
92
|
+
args[:attributes].each do |name|
|
93
|
+
xml.Attribute( :name => name )
|
94
|
+
end
|
95
|
+
else
|
96
|
+
self.attributes.each do |name,attribute|
|
97
|
+
if attribute.default
|
98
|
+
xml.Attribute( :name => name )
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
return biomart_xml
|
108
|
+
end
|
109
|
+
|
110
|
+
# Utility function to transform the tab-separated data retrieved
|
111
|
+
# from the Biomart search query into a ruby object.
|
112
|
+
def process_tsv( args, tsv )
|
113
|
+
headers = []
|
114
|
+
|
115
|
+
if args[:attributes]
|
116
|
+
args[:attributes].each do |attribute|
|
117
|
+
headers.push(attribute)
|
118
|
+
end
|
119
|
+
else
|
120
|
+
self.attributes.each do |name,attribute|
|
121
|
+
if attribute.default
|
122
|
+
headers.push(name)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
return {
|
128
|
+
:headers => headers,
|
129
|
+
:data => CSV.parse( tsv, "\t" )
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
# Utility function to quickly convert a search result into an array of hashes
|
134
|
+
# (keyed by the attribute name) for easier processing - this is not done by
|
135
|
+
# default on all searches as this can cause a large overhead on big data returns.
|
136
|
+
def convert_results_to_array_of_hashes( search_results )
|
137
|
+
result_objects = []
|
138
|
+
|
139
|
+
search_results[:data].each do |row|
|
140
|
+
tmp = {}
|
141
|
+
row.each_index do |index|
|
142
|
+
tmp[ search_results[:headers][index] ] = row[index]
|
143
|
+
end
|
144
|
+
result_objects.push(tmp)
|
145
|
+
end
|
146
|
+
|
147
|
+
return result_objects
|
148
|
+
end
|
149
|
+
|
150
|
+
private
|
151
|
+
|
152
|
+
# Utility function to retrieve and process the configuration
|
153
|
+
# xml for a dataset
|
154
|
+
def fetch_configuration
|
155
|
+
url = @url + "?type=configuration&dataset=#{@name}"
|
156
|
+
document = REXML::Document.new( request( :url => url ) )
|
157
|
+
|
158
|
+
# Top-Level filters...
|
159
|
+
REXML::XPath.each( document, '//FilterDescription' ) do |f|
|
160
|
+
unless f.attributes["displayType"].eql? "container"
|
161
|
+
@filters[ f.attributes["internalName"] ] = Filter.new( f.attributes )
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
# Filters nested inside containers...
|
166
|
+
REXML::XPath.each( document, '//FilterDescription/Option' ) do |f|
|
167
|
+
if f.attributes["displayType"] != nil
|
168
|
+
@filters[ f.attributes["internalName"] ] = Filter.new( f.attributes )
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# Attributes are much simpler...
|
173
|
+
REXML::XPath.each( document, '//AttributeDescription' ) do |a|
|
174
|
+
@attributes[ a.attributes["internalName"] ] = Attribute.new( a.attributes )
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Biomart
|
2
|
+
class Filter
|
3
|
+
attr_reader :name, :display_name, :default, :default_value
|
4
|
+
|
5
|
+
def initialize(args)
|
6
|
+
@name = args["internalName"]
|
7
|
+
@display_name = args["displayName"]
|
8
|
+
@default = args["defaultOn"] ? true : false
|
9
|
+
@default_value = args["defaultValue"]
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Biomart
|
2
|
+
class Server
|
3
|
+
include Biomart
|
4
|
+
|
5
|
+
attr_reader :url
|
6
|
+
|
7
|
+
def initialize( url )
|
8
|
+
@url = url or raise ArgumentError, "must pass :url"
|
9
|
+
unless @url =~ /martservice/
|
10
|
+
@url = @url + "/martservice"
|
11
|
+
end
|
12
|
+
|
13
|
+
@databases = {}
|
14
|
+
@datasets = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def list_databases
|
18
|
+
if @databases.empty?
|
19
|
+
fetch_databases
|
20
|
+
end
|
21
|
+
return @databases.keys
|
22
|
+
end
|
23
|
+
|
24
|
+
def databases
|
25
|
+
if @databases.empty?
|
26
|
+
fetch_databases
|
27
|
+
end
|
28
|
+
return @databases
|
29
|
+
end
|
30
|
+
|
31
|
+
def list_datasets
|
32
|
+
if @datasets.empty?
|
33
|
+
fetch_datasets
|
34
|
+
end
|
35
|
+
return @datasets.keys
|
36
|
+
end
|
37
|
+
|
38
|
+
def datasets
|
39
|
+
if @datasets.empty?
|
40
|
+
fetch_datasets
|
41
|
+
end
|
42
|
+
return @datasets
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def fetch_databases
|
48
|
+
url = @url + '?type=registry'
|
49
|
+
document = REXML::Document.new( request( :url => url ) )
|
50
|
+
REXML::XPath.each( document, "//MartURLLocation" ) do |d|
|
51
|
+
if d.attributes["visible"] === "1"
|
52
|
+
@databases[ d.attributes["name"] ] = Database.new( @url, d.attributes )
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def fetch_datasets
|
58
|
+
self.databases.each do |name,database|
|
59
|
+
@datasets.merge!( database.datasets )
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
data/lib/biomart.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require "uri"
|
2
|
+
require "net/http"
|
3
|
+
require "rexml/document"
|
4
|
+
require "csv"
|
5
|
+
|
6
|
+
require "rubygems"
|
7
|
+
require "builder"
|
8
|
+
|
9
|
+
module Biomart
|
10
|
+
VERSION = "0.0.1"
|
11
|
+
|
12
|
+
# Specialised classes for error reporting
|
13
|
+
class BiomartError < StandardError
|
14
|
+
attr_reader :data
|
15
|
+
|
16
|
+
def initialize(data)
|
17
|
+
@data = data
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Unauthorized < StandardError; end
|
23
|
+
class Unavailable < StandardError; end
|
24
|
+
class NotFound < StandardError; end
|
25
|
+
|
26
|
+
@@url = 'http://www.biomart.org/biomart/martservice'
|
27
|
+
@@client = Net::HTTP
|
28
|
+
|
29
|
+
def request( params={} )
|
30
|
+
if Biomart.proxy or ENV['http_proxy']
|
31
|
+
proxy_uri = Biomart.proxy
|
32
|
+
proxy_uri ||= ENV['http_proxy']
|
33
|
+
proxy = URI.parse( proxy_uri )
|
34
|
+
@@client = Net::HTTP::Proxy( proxy.host, proxy.port )
|
35
|
+
end
|
36
|
+
|
37
|
+
params[:url] = URI.escape(params[:url])
|
38
|
+
|
39
|
+
if params[:method] === 'post'
|
40
|
+
res = post( params )
|
41
|
+
else
|
42
|
+
res = get( params )
|
43
|
+
end
|
44
|
+
|
45
|
+
return res.body
|
46
|
+
end
|
47
|
+
|
48
|
+
def get( params={} )
|
49
|
+
res = @@client.get_response( URI.parse(params[:url]) )
|
50
|
+
return res
|
51
|
+
end
|
52
|
+
|
53
|
+
def post( params={} )
|
54
|
+
res = @@client.post_form( URI.parse(params[:url]), { "query" => params[:query] } )
|
55
|
+
return res
|
56
|
+
end
|
57
|
+
|
58
|
+
class << self
|
59
|
+
attr_accessor :proxy
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
directory = File.expand_path(File.dirname(__FILE__))
|
65
|
+
|
66
|
+
require File.join(directory, 'biomart', 'server')
|
67
|
+
require File.join(directory, 'biomart', 'database')
|
68
|
+
require File.join(directory, 'biomart', 'dataset')
|
69
|
+
require File.join(directory, 'biomart', 'filter')
|
70
|
+
require File.join(directory, 'biomart', 'attribute')
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/biomart.rb'}"
|
9
|
+
puts "Loading biomart gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class BiomartTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@htgt = Biomart::Server.new('http://www.sanger.ac.uk/htgt/biomart')
|
6
|
+
@htgt_alt = Biomart::Server.new('http://www.sanger.ac.uk/htgt/biomart')
|
7
|
+
end
|
8
|
+
|
9
|
+
context "A Biomart::Server instance" do
|
10
|
+
should "have databases" do
|
11
|
+
assert( @htgt_alt.list_databases.is_a?( Array ), "Biomart::Server.list_databases is not returning an array." )
|
12
|
+
assert( @htgt_alt.list_databases.include?( "htgt" ), "Biomart::Server datbase parsing is off - htgt is not in htgt!" )
|
13
|
+
assert( @htgt.databases["htgt"].is_a?( Biomart::Database ), "Biomart::Server is not creating Biomart::Database objects." )
|
14
|
+
end
|
15
|
+
|
16
|
+
should "have datasets" do
|
17
|
+
assert( @htgt_alt.list_datasets.is_a?( Array ), "Biomart::Server.list_datasets is not returning an array." )
|
18
|
+
assert( @htgt_alt.list_datasets.include?( "htgt_targ" ), "Biomart::Server dataset parsing is off - htgt_targ is not in htgt!" )
|
19
|
+
assert( @htgt.datasets["htgt_targ"].is_a?( Biomart::Dataset ), "Biomart::Server is not creating Biomart::Dataset objects." )
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "A Biomart::Database instance" do
|
24
|
+
setup do
|
25
|
+
@htgt_database = @htgt.databases["htgt"]
|
26
|
+
end
|
27
|
+
|
28
|
+
should "have basic metadata" do
|
29
|
+
assert( @htgt_database.display_name, "Biomart::Database does not have a 'display name'." )
|
30
|
+
assert( @htgt_database.name, "Biomart::Database does not have a 'name'." )
|
31
|
+
assert( @htgt_database.visible != nil, "Biomart::Database does not have a 'visible' flag." )
|
32
|
+
end
|
33
|
+
|
34
|
+
should "have datasets" do
|
35
|
+
assert( @htgt_database.list_datasets.is_a?( Array ), "Biomart::Database.list_datasets is not returning an array." )
|
36
|
+
assert( @htgt_database.list_datasets.include?( "htgt_targ" ), "Biomart::Database dataset parsing is off - htgt_targ is not in htgt!" )
|
37
|
+
assert( @htgt_database.datasets["htgt_targ"].is_a?( Biomart::Dataset ), "Biomart::Database is not creating Biomart::Dataset objects." )
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "A Biomart::Dataset instance" do
|
42
|
+
setup do
|
43
|
+
@htgt_targ = @htgt.datasets["htgt_targ"]
|
44
|
+
@htgt_trap = @htgt.datasets["htgt_trap"]
|
45
|
+
@kermits = @htgt.datasets["kermits"]
|
46
|
+
end
|
47
|
+
|
48
|
+
should "have basic metadata" do
|
49
|
+
assert( @htgt_targ.display_name, "Biomart::Dataset does not have a 'display name'." )
|
50
|
+
assert( @htgt_targ.name, "Biomart::Dataset does not have a 'name'." )
|
51
|
+
assert( @htgt_targ.visible != nil, "Biomart::Dataset does not have a 'visible' flag." )
|
52
|
+
end
|
53
|
+
|
54
|
+
should "have filters" do
|
55
|
+
assert( @htgt_targ.list_filters.is_a?( Array ), "Biomart::Dataset.list_filters is not returning an array." )
|
56
|
+
assert( @htgt_targ.list_filters.include?( "ensembl_gene_id" ), "Biomart::Dataset filter parsing is off - ensembl_gene_id is not in htgt_targ!" )
|
57
|
+
assert( @kermits.filters["ensembl_gene_id"].is_a?( Biomart::Filter ), "Biomart::Dataset is not creating Biomart::Filter objects." )
|
58
|
+
end
|
59
|
+
|
60
|
+
should "have attributes" do
|
61
|
+
assert( @htgt_targ.list_attributes.is_a?( Array ), "Biomart::Dataset.list_attributes is not returning an array." )
|
62
|
+
assert( @htgt_targ.list_attributes.include?( "ensembl_gene_id" ), "Biomart::Dataset attribute parsing is off - ensembl_gene_id is not in htgt_targ!" )
|
63
|
+
assert( @kermits.attributes["ensembl_gene_id"].is_a?( Biomart::Attribute ), "Biomart::Dataset is not creating Biomart::Attribute objects." )
|
64
|
+
end
|
65
|
+
|
66
|
+
should "perform count queries" do
|
67
|
+
htgt_count = @htgt_targ.count()
|
68
|
+
assert( htgt_count.is_a?( Integer ), "Biomart::Dataset.count is not returning integers." )
|
69
|
+
assert( htgt_count > 0, "Biomart::Dataset.count is returning zero - this is wrong!" )
|
70
|
+
|
71
|
+
htgt_count_single_filter = @htgt_targ.count( :filters => { "is_eucomm" => "1" } )
|
72
|
+
assert( htgt_count_single_filter.is_a?( Integer ), "Biomart::Dataset.count (with single filter) is not returning integers." )
|
73
|
+
assert( htgt_count_single_filter > 0, "Biomart::Dataset.count (with single filter) is returning zero - this is wrong!" )
|
74
|
+
|
75
|
+
htgt_count_single_filter_group_value = @htgt_targ.count( :filters => { "marker_symbol" => ["Cbx1","Cbx7","Art4"] } )
|
76
|
+
assert( htgt_count_single_filter_group_value.is_a?( Integer ), "Biomart::Dataset.count (with single filter, group value) is not returning integers." )
|
77
|
+
assert( htgt_count_single_filter_group_value > 0, "Biomart::Dataset.count (with single filter, group value) is returning zero - this is wrong!" )
|
78
|
+
end
|
79
|
+
|
80
|
+
should "perform search queries" do
|
81
|
+
search = @htgt_trap.search()
|
82
|
+
assert( search.is_a?( Hash ), "Biomart::Dataset.search (no options) is not returning a hash." )
|
83
|
+
assert( search[:data].is_a?( Array ), "Biomart::Dataset.search[:data] (no options) is not returning an array." )
|
84
|
+
|
85
|
+
search1 = @htgt_targ.search( :filters => { "marker_symbol" => "Cbx1" }, :process_results => true )
|
86
|
+
assert( search1.is_a?( Array ), "Biomart::Dataset.search (filters defined with processing) is not returning an array." )
|
87
|
+
assert( search1.first.is_a?( Hash ), "Biomart::Dataset.search (filters defined with processing) is not returning an array of hashes." )
|
88
|
+
assert( search1.first["marker_symbol"] == "Cbx1", "Biomart::Dataset.search (filters defined with processing) is not returning the correct info." )
|
89
|
+
|
90
|
+
search2 = @htgt_targ.search( :filters => { "marker_symbol" => "Cbx1" }, :attributes => ["marker_symbol","ensembl_gene_id"], :process_results => true )
|
91
|
+
assert( search2.is_a?( Array ), "Biomart::Dataset.search (filters and attributes defined with processing) is not returning an array." )
|
92
|
+
assert( search2.first.is_a?( Hash ), "Biomart::Dataset.search (filters and attributes defined with processing) is not returning an array of hashes." )
|
93
|
+
assert( search2.first["marker_symbol"] == "Cbx1", "Biomart::Dataset.search (filters and attributes defined with processing) is not returning the correct info." )
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dazoakley-biomart
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Darren Oakley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-25 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: builder
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: thoughtbot-shoulda
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: hoe
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.3.2
|
44
|
+
version:
|
45
|
+
description: A ruby API for interacting with Biomart services.
|
46
|
+
email:
|
47
|
+
- daz.oakley@gmail.com
|
48
|
+
executables: []
|
49
|
+
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
extra_rdoc_files:
|
53
|
+
- History.txt
|
54
|
+
- Manifest.txt
|
55
|
+
- README.rdoc
|
56
|
+
files:
|
57
|
+
- History.txt
|
58
|
+
- Manifest.txt
|
59
|
+
- README.rdoc
|
60
|
+
- Rakefile
|
61
|
+
- lib/biomart.rb
|
62
|
+
- lib/biomart/attribute.rb
|
63
|
+
- lib/biomart/database.rb
|
64
|
+
- lib/biomart/dataset.rb
|
65
|
+
- lib/biomart/filter.rb
|
66
|
+
- lib/biomart/server.rb
|
67
|
+
- script/console
|
68
|
+
- script/destroy
|
69
|
+
- script/generate
|
70
|
+
- test/test_biomart.rb
|
71
|
+
- test/test_helper.rb
|
72
|
+
has_rdoc: false
|
73
|
+
homepage: http://github.com/dazoakley/biomart
|
74
|
+
licenses:
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options:
|
77
|
+
- --main
|
78
|
+
- README.rdoc
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: "0"
|
86
|
+
version:
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: "0"
|
92
|
+
version:
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
rubyforge_project: biomart
|
96
|
+
rubygems_version: 1.3.5
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: A ruby API for interacting with Biomart services.
|
100
|
+
test_files:
|
101
|
+
- test/test_biomart.rb
|
102
|
+
- test/test_helper.rb
|