biomart 0.2.1 → 0.2.2

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.
data/.gitignore CHANGED
@@ -1,4 +1,6 @@
1
+ .yardoc/*
1
2
  coverage*
3
+ pkg/*
2
4
  simplecov*
5
+ tmp/*.json
3
6
  tmp/metric_fu*
4
- tmp/*.json
@@ -1,3 +1,8 @@
1
+ === 0.2.1 2011-02-18
2
+
3
+ * 1 major bugfix:
4
+ * More forceful filter checking in 0.2.1 was causing queries on 'pointerFilters' to error out unnecessarily.
5
+
1
6
  === 0.2.1 2011-02-16
2
7
 
3
8
  * 1 minor bugfix:
@@ -43,7 +43,27 @@ module Biomart
43
43
 
44
44
  # Centralised request function for handling all of the HTTP requests
45
45
  # to the biomart servers.
46
- def request( params={} )
46
+ #
47
+ # @param [Hash] params Parameters to be passed to the request
48
+ # @return [String] The response body
49
+ #
50
+ # @example
51
+ # request({
52
+ # :url => 'http://www.example.com', # the url
53
+ # :method => 'get', # get/post
54
+ # :query => 'a string', # when using post, send this as 'query' (i.e. the biomart query xml)
55
+ # :timeout => 60 # override the default timeout
56
+ # })
57
+ #
58
+ # @raise Biomart::ArgumentError Raised if a params hash is not passed (or it is empty)
59
+ # @raise Biomart::HTTPError Raised if a HTTP error was encountered
60
+ # @raise Biomart::FilterError Raised when a filter is not found
61
+ # @raise Biomart::AttributeError Raised when an attribute is not found
62
+ # @raise Biomart::DatasetError Raised when a dataset is not found
63
+ # @raise Biomart::BiomartError Raised for any other unhandled error
64
+ def request( params )
65
+ raise ArgumentError if !params.is_a?(Hash) || params.empty?
66
+
47
67
  if params[:url] =~ / /
48
68
  params[:url].gsub!(" ","+")
49
69
  end
@@ -12,14 +12,17 @@ module Biomart
12
12
  end
13
13
 
14
14
  # Convenience method to see if this attribute is hidden from
15
- # the standard MartView interface. Returns true/false.
15
+ # the standard MartView interface.
16
+ #
17
+ # @return [Boolean] true/false
16
18
  def hidden?
17
19
  @hidden
18
20
  end
19
21
 
20
22
  # Convenience method to see if this attribute would be
21
23
  # enabled by default in the standard MartView interface.
22
- # Returns true/false.
24
+ #
25
+ # @return [Boolean] true/false
23
26
  def default?
24
27
  @default
25
28
  end
@@ -20,6 +20,8 @@ module Biomart
20
20
 
21
21
  # Returns an array of the dataset names (biomart 'name')
22
22
  # for this dataset.
23
+ #
24
+ # @return [Array] An array of dataset names
23
25
  def list_datasets
24
26
  if @datasets.empty?
25
27
  fetch_datasets
@@ -29,6 +31,8 @@ module Biomart
29
31
 
30
32
  # Returns a hash (keyed by the biomart 'name' for the dataset)
31
33
  # of all of the Biomart::Dataset objects belonging to this server.
34
+ #
35
+ # @return [Hash] A hash of Biomart::Dataset objects keyed by 'name'
32
36
  def datasets
33
37
  if @datasets.empty?
34
38
  fetch_datasets
@@ -38,6 +42,8 @@ module Biomart
38
42
 
39
43
  # Returns true / false if this database is visbile in the
40
44
  # default MartView interface.
45
+ #
46
+ # @return [Boolean] true/false
41
47
  def visible?
42
48
  @visible
43
49
  end
@@ -37,6 +37,8 @@ module Biomart
37
37
 
38
38
  # Returns a hash (keyed by the biomart 'internal_name' for the filter)
39
39
  # of all of the Biomart::Filter objects belonging to this dataset.
40
+ #
41
+ # @return [Hash] A hash of Biomart::Filter objects keyed by 'internal_name'
40
42
  def filters
41
43
  if @filters.empty?
42
44
  fetch_configuration()
@@ -46,6 +48,8 @@ module Biomart
46
48
 
47
49
  # Returns an array of the filter names (biomart 'internal_name')
48
50
  # for this dataset.
51
+ #
52
+ # @return [Array] An array of filters (their 'internal_name's)
49
53
  def list_filters
50
54
  if @filters.empty?
51
55
  fetch_configuration()
@@ -55,6 +59,8 @@ module Biomart
55
59
 
56
60
  # Returns a hash (keyed by the biomart 'internal_name' for the attribute)
57
61
  # of all of the Biomart::Attribute objects belonging to this dataset.
62
+ #
63
+ # @return [Hash] A hash of Biomart::Attribute objects keyed by 'internal_name'
58
64
  def attributes
59
65
  if @attributes.empty?
60
66
  fetch_configuration()
@@ -64,6 +70,8 @@ module Biomart
64
70
 
65
71
  # Returns an array of the attribute names (biomart 'internal_name')
66
72
  # for this dataset.
73
+ #
74
+ # @return [Array] An array of attributes (their 'internal_name's)
67
75
  def list_attributes
68
76
  if @attributes.empty?
69
77
  fetch_configuration()
@@ -73,13 +81,16 @@ module Biomart
73
81
 
74
82
  # Function to perform a Biomart count. Returns an integer value for
75
83
  # the result of the count query.
76
- #
77
- # optional arguments:
84
+ #
85
+ # arguments:
78
86
  #
79
87
  # {
80
- # :timeout => integer, # set a timeout length for the request (secs)
81
- # :filters => {} # hash of key-value pairs (filter => search term)
88
+ # :timeout => integer, # set a timeout length for the request (secs) - optional
89
+ # :filters => {} # hash of key-value pairs (filter => search term) - optional
82
90
  # }
91
+ #
92
+ # @param [Hash] args The arguments hash
93
+ # @raise Biomart::ArgumentError Raised when un-supported arguments are passed
83
94
  def count( args={} )
84
95
  if args[:federate]
85
96
  raise Biomart::ArgumentError, "You cannot federate a count query."
@@ -136,6 +147,10 @@ module Biomart
136
147
  #
137
148
  # But with the :process_results option will return an array of hashes,
138
149
  # where each hash represents a row of results (keyed by the attribute name).
150
+ #
151
+ # @param [Hash] args The arguments hash
152
+ # @return [Hash/Array] Will return a hash by default (of unprocessed data), or will return an array of hashes
153
+ # @raise Biomart::ArgumentError Raised if incorrect arguments are passed
139
154
  def search( args={} )
140
155
  if args[:required_attributes] and !args[:required_attributes].is_a?(Array)
141
156
  raise Biomart::ArgumentError, "The :required_attributes option must be passed as an array."
@@ -154,7 +169,10 @@ module Biomart
154
169
  return result
155
170
  end
156
171
 
157
- # Utility function to build the Biomart query XML
172
+ # Utility function to build the Biomart query XML - used by #count and #search.
173
+ #
174
+ # @see #count
175
+ # @see #search
158
176
  def generate_xml( args={} )
159
177
  biomart_xml = ""
160
178
  xml = Builder::XmlMarkup.new( :target => biomart_xml, :indent => 2 )
@@ -184,7 +202,8 @@ module Biomart
184
202
  end
185
203
 
186
204
  # Simple heartbeat function to test that a Biomart server is online.
187
- # Returns true/false.
205
+ #
206
+ # @return [Boolean] true/false
188
207
  def alive?
189
208
  server = Biomart::Server.new( @url )
190
209
  return server.alive?
@@ -198,17 +217,17 @@ module Biomart
198
217
  url = @url + "?type=configuration&dataset=#{@name}"
199
218
  document = REXML::Document.new( request( :url => url ) )
200
219
 
201
- # Top-Level filters...
202
- REXML::XPath.each( document, '//FilterDescription' ) do |f|
203
- unless f.attributes["displayType"].eql? "container"
204
- @filters[ f.attributes["internalName"] ] = Filter.new( f.attributes )
205
- end
206
- end
207
-
208
- # Filters nested inside containers...
209
- REXML::XPath.each( document, '//FilterDescription/Option' ) do |f|
210
- if f.attributes["displayType"] != nil
211
- @filters[ f.attributes["internalName"] ] = Filter.new( f.attributes )
220
+ # Filters...
221
+ ['//FilterDescription','//FilterDescription/Option'].each do |filter_xpath|
222
+ REXML::XPath.each( document, filter_xpath ) do |f|
223
+ if f.attributes["displayType"] != nil
224
+ next if f.attributes["displayType"] == "container"
225
+ @filters[ f.attributes["internalName"] ] = Filter.new( f.attributes )
226
+ else f.attributes["pointerFilter"] != nil
227
+ pointer_filter = Filter.new( f.attributes )
228
+ @filters[ pointer_filter.name ] = pointer_filter
229
+ @filters[ pointer_filter.pointer_filter ] = pointer_filter
230
+ end
212
231
  end
213
232
  end
214
233
 
@@ -2,7 +2,7 @@ module Biomart
2
2
  # Class representation for a biomart filter.
3
3
  # Will belong to a Biomart::Dataset.
4
4
  class Filter
5
- attr_reader :name, :display_name, :default_value, :qualifier, :type
5
+ attr_reader :name, :display_name, :default_value, :qualifier, :type, :pointer_dataset, :pointer_filter
6
6
 
7
7
  def initialize(args)
8
8
  @name = args["internalName"]
@@ -14,24 +14,33 @@ module Biomart
14
14
  @type = args["type"]
15
15
  @multiple_values = args["multipleValues"] ? true : false
16
16
 
17
+ @pointer_dataset = args["pointerDataset"]
18
+ @pointer_filter = args["pointerFilter"]
19
+ @pointer_interface = args["pointerInterface"]
20
+
17
21
  @type.downcase! unless @type.nil?
18
22
  end
19
23
 
20
24
  # Convenience method to see if this filter is hidden from
21
- # the standard MartView interface. Returns true/false.
25
+ # the standard MartView interface.
26
+ #
27
+ # @return [Boolean] true/false
22
28
  def hidden?
23
29
  @hidden
24
30
  end
25
31
 
26
32
  # Convenience method to see if this filter would be
27
33
  # enabled by default in the standard MartView interface.
28
- # Returns true/false.
34
+ #
35
+ # @return [Boolean] true/false
29
36
  def default?
30
37
  @default
31
38
  end
32
39
 
33
40
  # Convenience method to see if this filter allows multiple
34
41
  # values to be passed to it.
42
+ #
43
+ # @return [Boolean] true/false
35
44
  def multiple_values?
36
45
  @multiple_values
37
46
  end
@@ -18,6 +18,8 @@ module Biomart
18
18
 
19
19
  # Returns an array of the database names (biomart 'name')
20
20
  # for this dataset.
21
+ #
22
+ # @return [Array] An array of database names
21
23
  def list_databases
22
24
  if @databases.empty?
23
25
  fetch_databases
@@ -27,6 +29,8 @@ module Biomart
27
29
 
28
30
  # Returns a hash (keyed by the biomart 'name' for the database)
29
31
  # of all of the Biomart::Database objects belonging to this server.
32
+ #
33
+ # @return [Hash] A hash of Biomart::Database objects keyed by the database name
30
34
  def databases
31
35
  if @databases.empty?
32
36
  fetch_databases
@@ -1,3 +1,3 @@
1
1
  module Biomart
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -49,6 +49,7 @@ class BiomartTest < Test::Unit::TestCase
49
49
  @ensembl_var = Biomart::Dataset.new( "http://www.ensembl.org/biomart", { :name => "hsapiens_snp" } )
50
50
  @emma = Biomart::Dataset.new( "http://www.emmanet.org/biomart", { :name => "strains" } )
51
51
  @dcc = Biomart::Dataset.new( "http://www.knockoutmouse.org/biomart", { :name => "dcc" } )
52
+ @mgi = Biomart::Dataset.new( "http://biomart.informatics.jax.org/biomart", { :name => "markers" } )
52
53
  end
53
54
 
54
55
  should "have basic metadata" do
@@ -60,6 +61,7 @@ class BiomartTest < Test::Unit::TestCase
60
61
  should "have filters" do
61
62
  assert( @htgt_targ.list_filters.is_a?( Array ), "Biomart::Dataset.list_filters is not returning an array." )
62
63
  assert( @htgt_targ.list_filters.include?( "ensembl_gene_id" ), "Biomart::Dataset filter parsing is off - ensembl_gene_id is not in htgt_targ!" )
64
+ assert( @mgi.list_filters.include?( "ancestor_term_1023_filter" ), "Biomart::Dataset filter parsing is off - ancestor_term_1023_filter is not in mgi markers!" )
63
65
  assert( @kermits.filters["ensembl_gene_id"].is_a?( Biomart::Filter ), "Biomart::Dataset is not creating Biomart::Filter objects." )
64
66
  end
65
67
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Darren Oakley
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-16 00:00:00 +00:00
17
+ date: 2011-02-18 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency