intermine 0.98.06 → 0.98.08

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -52,10 +52,17 @@ end
52
52
 
53
53
  Rake::TestTask.new(:live_tests) do |t|
54
54
  t.libs << "test"
55
- t.test_files = FileList['test/live_test.rb']
55
+ t.test_files = FileList['test/live_test.rb'] << FileList['test/live_summary_test.rb']
56
56
  t.verbose = true
57
57
  end
58
58
 
59
+ Rake::TestTask.new(:live_summary) do |t|
60
+ t.libs << "test"
61
+ t.test_files = FileList['test/live_summary_test.rb']
62
+ t.verbose = true
63
+ end
64
+
65
+
59
66
  Rake::RDocTask.new do |t|
60
67
  t.title = 'InterMine Webservice Client Documentation'
61
68
  t.rdoc_files.include 'README.rdoc'
@@ -27,6 +27,10 @@ module Metadata
27
27
  #
28
28
  class Model
29
29
 
30
+ FLOAT_TYPES = ["Float", "Double", "float", "double"]
31
+ INT_TYPES = ["Integer", "int", "long", "Long", "short", "Short"]
32
+ BOOL_TYPES = ["Boolean", "boolean"]
33
+ NUMERIC_TYPES = FLOAT_TYPES | INT_TYPES
30
34
 
31
35
  # The name of the model
32
36
  attr_reader :name
@@ -497,9 +501,9 @@ module Metadata
497
501
  #
498
502
  def to_module
499
503
  if @module.nil?
500
- nums = ["Float", "Double", "float", "double"]
501
- ints = ["Integer", "int"]
502
- bools = ["Boolean", "boolean"]
504
+ nums = Model::FLOAT_TYPES
505
+ ints = Model::INT_TYPES
506
+ bools = Model::BOOL_TYPES
503
507
 
504
508
  supers = @extends.map { |x| @model.get_cd(x).to_module }
505
509
 
@@ -276,6 +276,12 @@ module InterMine::PathQuery
276
276
  # URLs for internal consumption.
277
277
  attr_reader :list_upload_uri, :list_append_uri
278
278
 
279
+ # The number of rows to return - defaults to nil (all rows)
280
+ attr_accessor :size
281
+
282
+ # The index of the first row to return - defaults to 0 (first row)
283
+ attr_accessor :start
284
+
279
285
  # Construct a new query object. You should not use this directly.
280
286
  # Instead use the factory methods in Service.
281
287
  #
@@ -290,6 +296,8 @@ module InterMine::PathQuery
290
296
  if root
291
297
  @root = InterMine::Metadata::Path.new(root, model).rootClass
292
298
  end
299
+ @size = nil
300
+ @start = 0
293
301
  @constraints = []
294
302
  @joins = []
295
303
  @views = []
@@ -377,6 +385,38 @@ module InterMine::PathQuery
377
385
  return Results::ResultsReader.new(@url, self, start, size)
378
386
  end
379
387
 
388
+ # Set the maximum number of rows this query will return.
389
+ #
390
+ # This method can be used to set a default maximum size for
391
+ # a query. Set to nil for all rows. The value given here
392
+ # will be overridden by any value supplied by #each_row
393
+ # or #each_result, unless that value is nil, in which
394
+ # case this value will be used. If unset, the query will return all results.
395
+ #
396
+ # Returns self for method chaining.
397
+ #
398
+ # See also #size= and #offset
399
+ #
400
+ def limit(size)
401
+ @size = size
402
+ return self
403
+ end
404
+
405
+ # Set the index of the first row of results this query will return.
406
+ #
407
+ # This method can be used to set a value for the query offset.
408
+ # The value given here will be overridden by any value supplied by #each_row
409
+ # or #each_result. If unset, results will start from the first row.
410
+ #
411
+ # Returns self for method chaining.
412
+ #
413
+ # See also #start= and #limit
414
+ #
415
+ def offset(start)
416
+ @start = start
417
+ return self
418
+ end
419
+
380
420
  # Iterate over the results of this query one row at a time.
381
421
  #
382
422
  # Rows support both array-like index based access as well as
@@ -390,7 +430,9 @@ module InterMine::PathQuery
390
430
  # puts r.to_h # Materialize the row an a Hash
391
431
  # end
392
432
  #
393
- def each_row(start=0, size=nil)
433
+ def each_row(start=nil, size=nil)
434
+ start = start.nil? ? @start : start
435
+ size = size.nil? ? @size : size
394
436
  results_reader(start, size).each_row {|row|
395
437
  yield row
396
438
  }
@@ -405,7 +447,9 @@ module InterMine::PathQuery
405
447
  # end
406
448
  # end
407
449
  #
408
- def each_result(start=0, size=nil)
450
+ def each_result(start=nil, size=nil)
451
+ start = start.nil? ? @start : start
452
+ size = size.nil? ? @size : size
409
453
  results_reader(start, size).each_result {|row|
410
454
  yield row
411
455
  }
@@ -430,7 +474,9 @@ module InterMine::PathQuery
430
474
  # rows.last["symbol"]
431
475
  # => "eve"
432
476
  #
433
- def rows(start=0, size=nil)
477
+ def rows(start=nil, size=nil)
478
+ start = start.nil? ? @start : start
479
+ size = size.nil? ? @size : size
434
480
  res = []
435
481
  results_reader(start, size).each_row {|row|
436
482
  res << row
@@ -445,7 +491,9 @@ module InterMine::PathQuery
445
491
  # genes.last.symbol
446
492
  # => "eve"
447
493
  #
448
- def results(start=0, size=nil)
494
+ def results(start=nil, size=nil)
495
+ start = start.nil? ? @start : start
496
+ size = size.nil? ? @size : size
449
497
  res = []
450
498
  results_reader(start, size).each_result {|row|
451
499
  res << row
@@ -453,6 +501,43 @@ module InterMine::PathQuery
453
501
  res
454
502
  end
455
503
 
504
+ def summary_items(summary_path, start=0, size=nil)
505
+ q = self.clone
506
+ q.add_views(summary_path)
507
+ rr = q.results_reader(start, size)
508
+ if block_given?
509
+ rr.each_summary(summary_path) {|summary|
510
+ yield summary
511
+ }
512
+ else
513
+ ret = []
514
+ rr.each_summary(summary_path) {|summary|
515
+ ret << summary
516
+ }
517
+ return ret
518
+ end
519
+ end
520
+
521
+ def summarise(summary_path, start=0, size=nil)
522
+ path = make_path(add_prefix(summary_path))
523
+ q = self.clone
524
+ q.add_views(summary_path)
525
+ rr = q.results_reader(start, size)
526
+ if InterMine::Metadata::Model::NUMERIC_TYPES.include? path.end_type
527
+ h = {}
528
+ rr.each_summary(summary_path) { |summary|
529
+ h = Hash[summary.map {|k, v| [k, v.to_f]}]
530
+ }
531
+ return h
532
+ else
533
+ h = {}
534
+ rr.each_summary(summary_path) {|summary|
535
+ h[summary["item"]] = summary["count"]
536
+ }
537
+ return h
538
+ end
539
+ end
540
+
456
541
  # Return all result record objects returned by running this query.
457
542
  def all
458
543
  return self.results
@@ -525,12 +610,14 @@ module InterMine::PathQuery
525
610
  y = add_prefix(x)
526
611
  if y.end_with?("*")
527
612
  prefix = y.chomp(".*")
528
- path = InterMine::Metadata::Path.new(prefix, @model, subclasses)
529
- attrs = path.end_cd.attributes.map {|x| prefix + "." + x.name}
613
+ path = make_path(prefix)
614
+ attrs = path.end_cd.attributes.map {|x|
615
+ prefix + "." + x.name
616
+ }
530
617
  add_views(attrs)
531
618
  else
532
- path = InterMine::Metadata::Path.new(y, @model, subclasses)
533
- path = InterMine::Metadata::Path.new(y.to_s + ".id", @model, subclasses) unless path.is_attribute?
619
+ path = make_path(y)
620
+ path = make_path(y.to_s + ".id") unless path.is_attribute?
534
621
  if @root.nil?
535
622
  @root = path.rootClass
536
623
  end
@@ -540,6 +627,10 @@ module InterMine::PathQuery
540
627
  return self
541
628
  end
542
629
 
630
+ def make_path(path)
631
+ return InterMine::Metadata::Path.new(path, @model, subclasses)
632
+ end
633
+
543
634
  alias add_to_select add_views
544
635
 
545
636
  # Replace any currently existing views with the given view list.
@@ -251,20 +251,10 @@ module InterMine::Results
251
251
 
252
252
  # Iterate over the result set one ResultsRow at a time
253
253
  def each_row
254
- container = ''
255
- each_line(params("jsonrows")) do |line|
256
- if line.start_with?("[")
257
- begin
258
- row = ResultsRow.new(line.chomp("," + $/), @query.views)
259
- rescue => e
260
- raise ServiceError, "Error parsing #{line}: #{e.message}"
261
- end
262
- yield row
263
- else
264
- container << line
265
- end
266
- end
267
- check_result_set(container)
254
+ processor = lambda {|x| ResultsRow.new(x.chomp("," + $/), @query.views) }
255
+ read_result_set(params("jsonrows"), processor) {|x|
256
+ yield x
257
+ }
268
258
  end
269
259
 
270
260
  # Iterate over the resultset, one object at a time, where the
@@ -284,21 +274,40 @@ module InterMine::Results
284
274
  #
285
275
  def each_result
286
276
  model = @query.model
277
+ processor = lambda {|x| model.make_new(JSON.parse(x.chomp("," + $/)))}
278
+ read_result_set(params("jsonobjects"), processor) {|x|
279
+ yield x
280
+ }
281
+ end
282
+
283
+ def each_summary(summary_path)
284
+ extra = {"summaryPath" => @query.add_prefix(summary_path)}
285
+ p = params("jsonrows").merge(extra)
286
+ processor = lambda {|x| JSON.parse(x.chomp("," + $/)) }
287
+ read_result_set(p, processor) {|x|
288
+ yield x
289
+ }
290
+ end
291
+
292
+ def read_result_set(parameters, processor)
287
293
  container = ''
288
- each_line(params("jsonobjects")) do |line|
289
- line.chomp!("," + $/)
290
- if line.start_with?("{") and line.end_with?("}")
294
+ in_results = false
295
+ each_line(parameters) do |line|
296
+ if line.start_with?("]")
297
+ in_results = false
298
+ end
299
+ if in_results
291
300
  begin
292
- data = JSON.parse(line)
293
- result = model.make_new(data)
294
- rescue JSON::ParserError => e
295
- raise ServiceError, "Error parsing #{line}: #{e.message}"
301
+ row = processor.call(line)
296
302
  rescue => e
297
- raise ServiceError, "Could not instantiate this result object: #{e.message}"
303
+ raise ServiceError, "Error parsing #{line}: #{e.message}"
298
304
  end
299
- yield result
305
+ yield row
300
306
  else
301
307
  container << line
308
+ if line.chomp($/).end_with?("[")
309
+ in_results = true
310
+ end
302
311
  end
303
312
  end
304
313
  check_result_set(container)
@@ -1,3 +1,3 @@
1
1
  module Intermine
2
- VERSION = "0.98.06"
2
+ VERSION = "0.98.08"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intermine
3
3
  version: !ruby/object:Gem::Version
4
- hash: 411
4
+ hash: 391
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 98
9
- - 6
10
- version: 0.98.06
9
+ - 8
10
+ version: 0.98.08
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Kalderimis
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-03 00:00:00 +01:00
18
+ date: 2011-10-26 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency