solvebio 1.5.2 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +13 -8
- data/Gemfile +4 -2
- data/README.md +5 -3
- data/demo/cheatsheet.rb +31 -0
- data/lib/cli/auth.rb +6 -6
- data/lib/cli/irbrc.rb +2 -1
- data/lib/cli/options.rb +1 -1
- data/lib/client.rb +85 -83
- data/lib/credentials.rb +2 -2
- data/lib/main.rb +11 -2
- data/lib/query.rb +5 -6
- data/lib/resource/annotation.rb +23 -0
- data/lib/resource/apiresource.rb +241 -0
- data/lib/resource/dataset.rb +91 -0
- data/lib/resource/datasetfield.rb +37 -0
- data/lib/resource/depository.rb +50 -0
- data/lib/resource/depositoryversion.rb +69 -0
- data/lib/resource/main.rb +123 -0
- data/lib/resource/sample.rb +75 -0
- data/lib/{solveobject.rb → resource/solveobject.rb} +43 -22
- data/lib/resource/user.rb +5 -0
- data/lib/solvebio.rb +1 -1
- data/lib/util.rb +29 -0
- data/solvebio.gemspec +7 -4
- data/test/Makefile +9 -0
- data/test/data/sample.vcf.gz +0 -0
- data/test/helper.rb +9 -2
- data/test/test-annotation.rb +46 -0
- data/test/test-auth.rb +8 -4
- data/test/test-client.rb +6 -6
- data/test/test-conversion.rb +13 -0
- data/test/test-dataset.rb +42 -0
- data/test/test-depository.rb +35 -0
- data/test/test-netrc.rb +13 -3
- data/test/test-query-batch.rb +26 -46
- data/test/test-query-paging.rb +77 -98
- data/test/test-query.rb +47 -64
- data/test/test-resource.rb +8 -15
- data/test/test-sample-access.rb +59 -0
- data/test/test-sample-download.rb +20 -0
- data/test/test-tabulate.rb +27 -23
- data/test/{test-solveobject.rb → test-util.rb} +17 -2
- metadata +128 -56
- data/lib/apiresource.rb +0 -130
- data/lib/help.rb +0 -46
- data/lib/resource.rb +0 -414
data/test/test-auth.rb
CHANGED
@@ -34,14 +34,17 @@ class TestAuth < Test::Unit::TestCase
|
|
34
34
|
def teardown
|
35
35
|
# Restore creds to what they were when we started
|
36
36
|
save_credentials(*@@creds) if @@creds
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
netrc_path = SolveBio::Credentials.netrc_path
|
38
|
+
n = Netrc.read(netrc_path)
|
39
|
+
if n[SolveBio::API_HOST]
|
40
|
+
i_am = run_it @@whoami_cmd
|
41
|
+
assert_equal(@i_was, i_am,
|
42
|
+
'get_credential and save_creditentials be idempotent')
|
43
|
+
end
|
40
44
|
end
|
41
45
|
|
42
46
|
# Integration test of logout
|
43
47
|
def test_logout
|
44
|
-
|
45
48
|
# Dunno if we are logged in or out - log out
|
46
49
|
output = run_it @logout_cmd
|
47
50
|
# We should be logged out. Try again, and check message.
|
@@ -51,4 +54,5 @@ class TestAuth < Test::Unit::TestCase
|
|
51
54
|
output = run_it @@whoami_cmd
|
52
55
|
assert_equal 'You are not logged-in.', output
|
53
56
|
end
|
57
|
+
|
54
58
|
end
|
data/test/test-client.rb
CHANGED
@@ -4,8 +4,6 @@ require 'test/unit'
|
|
4
4
|
require 'fileutils'
|
5
5
|
require_relative '../lib/client'
|
6
6
|
|
7
|
-
# require 'trepanning'
|
8
|
-
|
9
7
|
class TestClient < Test::Unit::TestCase
|
10
8
|
|
11
9
|
def test_get
|
@@ -15,10 +13,12 @@ class TestClient < Test::Unit::TestCase
|
|
15
13
|
# Can we get something from google?
|
16
14
|
output = `curl --silent http://www.google.com`
|
17
15
|
if $?.success? and output
|
18
|
-
assert(client.request('
|
19
|
-
true
|
20
|
-
|
21
|
-
|
16
|
+
assert(client.request('get', 'http://www.google.com',
|
17
|
+
{:raw => true, :redirect => true}),
|
18
|
+
'HTTP GET, google.com')
|
19
|
+
assert(client.request('get', 'https://www.google.com',
|
20
|
+
{:raw => true}),
|
21
|
+
'HTTPS GET google.com')
|
22
22
|
else
|
23
23
|
skip('Are you connected to the Internet? www.google.com is unavailable')
|
24
24
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require_relative '../lib/resource/apiresource'
|
3
|
+
|
4
|
+
class ConversionTest < Test::Unit::TestCase
|
5
|
+
def test_class_to_api_name
|
6
|
+
ar = SolveBio::APIResource
|
7
|
+
[%w(Annotation annotations),
|
8
|
+
%w(DataField data_fields),
|
9
|
+
%w(Depository depositories)].each do |class_name, expect|
|
10
|
+
assert_equal(expect, ar.class_to_api_name(class_name))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Test Dataset, DatasetField, and Facets
|
2
|
+
require_relative './helper'
|
3
|
+
require_relative '../lib/resource/main'
|
4
|
+
|
5
|
+
class TestDataset < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@dataset = SolveBio::Dataset.retrieve(TEST_DATASET_NAME)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_dataset
|
11
|
+
assert(@dataset.member?('id'),
|
12
|
+
'Should be able to get id in dataset')
|
13
|
+
|
14
|
+
%w(class_name created_at data_url depository depository_id
|
15
|
+
depository_version depository_version_id description
|
16
|
+
fields_url full_name name title updated_at url).each do |field|
|
17
|
+
assert(@dataset.member?(field),
|
18
|
+
"Should find field #{field} in dataset #{@dataset.id}")
|
19
|
+
end
|
20
|
+
|
21
|
+
fields = @dataset.fields()
|
22
|
+
dataset_field = fields[:data][0]
|
23
|
+
assert(dataset_field.member?('id'),
|
24
|
+
'Should be able to get id in list of dataset fields')
|
25
|
+
|
26
|
+
dataset_field2 = SolveBio::DatasetField.retrieve(dataset_field.id)
|
27
|
+
assert_equal(dataset_field, dataset_field2,
|
28
|
+
"Retrieving SolveBio::DatasetField id " +
|
29
|
+
"#{dataset_field[:id]} found by all()")
|
30
|
+
|
31
|
+
%w(class_name created_at dataset dataset_id description facets_url
|
32
|
+
name updated_at url).each do |field|
|
33
|
+
assert(dataset_field.member?(field),
|
34
|
+
"Should find field #{field} in fields #{dataset_field.id}")
|
35
|
+
end
|
36
|
+
facets = dataset_field.facets()
|
37
|
+
|
38
|
+
# We can get small or large numbers like 0 or 4902851621.0
|
39
|
+
assert(facets['total'] >= 0,
|
40
|
+
'facets should have a numeric total field >= 0')
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Test Depository, DepositoryVersions
|
2
|
+
|
3
|
+
require_relative './helper'
|
4
|
+
class TestDepository < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_depositories
|
7
|
+
depos = SolveBio::Depository.all()
|
8
|
+
|
9
|
+
depo = depos[:data][0]
|
10
|
+
assert(depo.member?('id'),
|
11
|
+
'Should be able to get id in depository')
|
12
|
+
|
13
|
+
depo2 = SolveBio::Depository.retrieve(depo.id)
|
14
|
+
assert_equal(depo, depo2,
|
15
|
+
"Retrieving dataset id #{depo.id} found by all()")
|
16
|
+
|
17
|
+
%w(class_name created_at description external_resources
|
18
|
+
full_name id is_private is_restricted latest_version
|
19
|
+
latest_version_id name title updated_at url versions_count
|
20
|
+
versions_url).each do |field|
|
21
|
+
assert(depo.member?(field),
|
22
|
+
"Should find field #{field} in depo #{depo.id}")
|
23
|
+
end
|
24
|
+
|
25
|
+
depo_version_id = depo.versions()[:data][0].id
|
26
|
+
depo_version = SolveBio::DepositoryVersion.retrieve(depo_version_id)
|
27
|
+
|
28
|
+
%w(class_name created_at datasets_url depository depository_id
|
29
|
+
description full_name id latest name released released_at
|
30
|
+
title updated_at url).each do |field|
|
31
|
+
assert(depo_version.member?(field),
|
32
|
+
"Should find field #{field} in depo version")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/test/test-netrc.rb
CHANGED
@@ -7,15 +7,24 @@ require_relative '../lib/credentials'
|
|
7
7
|
# Does .netrc reading and manipulation work?
|
8
8
|
class TestNetrc < Test::Unit::TestCase
|
9
9
|
|
10
|
+
|
10
11
|
def setup
|
11
12
|
@netrc_path_save = ENV["NETRC_PATH"]
|
12
|
-
path = ENV[
|
13
|
+
path = ENV['NETRC_PATH'] = File.join(File.dirname(__FILE__), 'data')
|
13
14
|
FileUtils.cp(File.join(path, 'netrc-save'), File.join(path, '.netrc'))
|
14
15
|
File.chmod(0600, "#{path}/.netrc")
|
16
|
+
@old_warn_level = $VERBOSE
|
17
|
+
@old_api_host = SolveBio::API_HOST
|
18
|
+
$VERBOSE = nil
|
19
|
+
SolveBio.const_set(:API_HOST, 'https://api.solvebio.com')
|
20
|
+
$VERBOSE = @old_warn_level
|
15
21
|
end
|
16
22
|
|
17
23
|
def teardown
|
18
24
|
ENV["NETRC_PATH"] = @netrc_path_save
|
25
|
+
$VERBOSE = nil
|
26
|
+
SolveBio.const_set(:API_HOST, @old_api_host)
|
27
|
+
$VERBOSE = @old_warn_level
|
19
28
|
end
|
20
29
|
|
21
30
|
include SolveBio::Credentials
|
@@ -25,13 +34,14 @@ class TestNetrc < Test::Unit::TestCase
|
|
25
34
|
end
|
26
35
|
|
27
36
|
def test_get_credentials
|
28
|
-
assert_equal ['rocky@example.com', 'shhhh'], get_credentials
|
37
|
+
assert_equal ['rocky@example.com', 'shhhh'], get_credentials.to_a
|
29
38
|
end
|
30
39
|
|
31
40
|
def test_save_credentials
|
32
41
|
new_values = get_credentials.map{|x| x+"abc"}
|
33
42
|
save_credentials(*new_values)
|
34
|
-
assert_equal
|
43
|
+
assert_equal(new_values, get_credentials.to_a,
|
44
|
+
'Should append "abc" to creds')
|
35
45
|
end
|
36
46
|
|
37
47
|
def test_delete_credentials
|
data/test/test-query-batch.rb
CHANGED
@@ -1,60 +1,40 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
$VERBOSE = true
|
3
|
+
require 'socket'
|
3
4
|
require_relative 'helper'
|
5
|
+
require_relative '../lib/resource/main'
|
4
6
|
|
5
7
|
class TestQueryBatch < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@dataset = SolveBio::Dataset.retrieve(TEST_DATASET_NAME)
|
10
|
+
end
|
6
11
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def setup
|
12
|
-
begin
|
13
|
-
@dataset = SolveBio::Dataset.retrieve(TEST_DATASET_NAME)
|
14
|
-
rescue SocketError
|
15
|
-
@dataset = nil
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_invalid_batch_query
|
20
|
-
skip('Are you connected to the Internet?') unless @dataset
|
21
|
-
assert_raise SolveBio::Error do
|
22
|
-
SolveBio::BatchQuery
|
23
|
-
.new([
|
24
|
-
@dataset.query(:limit => 1, :fields => [:bogus_field]),
|
25
|
-
@dataset.query(:limit => 10).filter(:hg19_start__gt => 100000)
|
26
|
-
]).execute
|
27
|
-
end
|
28
|
-
|
29
|
-
dataset2 = SolveBio::Dataset.retrieve('HGNC/1.0.0-1/HGNC')
|
30
|
-
results = SolveBio::BatchQuery
|
12
|
+
def test_invalid_batch_query
|
13
|
+
assert_raise SolveBio::Error do
|
14
|
+
SolveBio::BatchQuery
|
31
15
|
.new([
|
32
|
-
|
33
|
-
@dataset.query(:limit => 10).filter(:
|
16
|
+
@dataset.query(:limit => 1, :fields => [:bogus_field]),
|
17
|
+
@dataset.query(:limit => 10).filter(:bogus_id__gt => 100000)
|
34
18
|
]).execute
|
35
|
-
assert_equal(2, results.length)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_batch_query
|
42
|
-
skip('Are you connected to the Internet?') unless @dataset
|
43
|
-
queries = [
|
44
|
-
@dataset.query(:limit => 1),
|
45
|
-
@dataset.query(:limit => 10).filter(:hg19_start__gt => 100000)
|
46
|
-
]
|
47
|
-
results = SolveBio::BatchQuery.new(queries).execute
|
48
|
-
assert_equal(2, results.size)
|
49
|
-
assert_equal(1, results[0]['results'].length)
|
50
|
-
assert_equal(10, results[1]['results'].size)
|
51
19
|
end
|
52
20
|
|
21
|
+
results = SolveBio::BatchQuery
|
22
|
+
.new([
|
23
|
+
@dataset.query(:limit => 10).filter(:hgnc_id__lt => 100),
|
24
|
+
@dataset.query(:limit => 10).filter(:hgnc_id__gt => 100)
|
25
|
+
]).execute
|
26
|
+
assert_equal(2, results.length)
|
53
27
|
|
54
|
-
else
|
55
|
-
def test_skip
|
56
|
-
skip 'Please set SolveBio::api_key'
|
57
|
-
end
|
58
28
|
end
|
59
29
|
|
30
|
+
def test_batch_query
|
31
|
+
queries = [
|
32
|
+
@dataset.query(:limit => 1),
|
33
|
+
@dataset.query(:limit => 10).filter(:hgnc_id__gt => 100)
|
34
|
+
]
|
35
|
+
results = SolveBio::BatchQuery.new(queries).execute
|
36
|
+
assert_equal(2, results.size)
|
37
|
+
assert_equal(1, results[0]['results'].length)
|
38
|
+
assert_equal(10, results[1]['results'].size)
|
39
|
+
end
|
60
40
|
end
|
data/test/test-query-paging.rb
CHANGED
@@ -1,122 +1,101 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
$VERBOSE = true
|
3
|
+
require 'socket'
|
3
4
|
require_relative 'helper'
|
5
|
+
require_relative '../lib/resource/main'
|
4
6
|
|
5
7
|
class TestQueryPaging < Test::Unit::TestCase
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def setup
|
12
|
-
begin
|
13
|
-
@dataset = SolveBio::Dataset.retrieve(TEST_DATASET_NAME)
|
14
|
-
rescue SocketError
|
15
|
-
@dataset = nil
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_query
|
20
|
-
skip('Are you connected to the Internet?') unless @dataset
|
21
|
-
results = @dataset.query(:paging=>true, :limit => 10)
|
22
|
-
# When paging is on, results.size should return the number
|
23
|
-
# of total number of results.
|
24
|
-
assert_equal(results.size, results.total,
|
25
|
-
'results.size == results.total, paging=true')
|
26
|
-
end
|
9
|
+
def setup
|
10
|
+
@dataset = SolveBio::Dataset.retrieve(TEST_DATASET_NAME)
|
11
|
+
end
|
27
12
|
|
28
|
-
|
29
|
-
|
30
|
-
#
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
assert_equal(results.total, results.length,
|
36
|
-
'results.total == results.length, paging = true')
|
37
|
-
end
|
13
|
+
def test_query
|
14
|
+
results = @dataset.query(:paging=>true, :limit => 10)
|
15
|
+
# When paging is on, results.size should return the number
|
16
|
+
# of total number of results.
|
17
|
+
assert_equal(results.size, results.total,
|
18
|
+
'results.size == results.total, paging=true')
|
19
|
+
end
|
38
20
|
|
21
|
+
# In paging queries, results.size should return the total number of
|
22
|
+
# results that exist. Yes, this is the same as test_query, but
|
23
|
+
# we reverse the order of access, to make sure "warmup" is called.
|
24
|
+
def test_limit
|
25
|
+
limit = 10
|
26
|
+
results = @dataset.query(:paging=>true, :limit => limit)
|
27
|
+
assert_equal(results.total, results.length,
|
28
|
+
'results.total == results.length, paging = true')
|
29
|
+
end
|
39
30
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
filter(:hg19_start__range => [140000000, 140050000])
|
31
|
+
def test_paging
|
32
|
+
limit = 100
|
33
|
+
total = 4
|
34
|
+
results = @dataset.query(:paging => true, :limit => limit).
|
35
|
+
filter(:hgnc_id__in => [2396, 2404, 2409, 2411])
|
46
36
|
|
47
|
-
|
37
|
+
assert_equal(total, results.total)
|
48
38
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
55
|
-
assert_equal(i, total-1)
|
39
|
+
# Make sure we can iterate over the entire result set
|
40
|
+
i = 0
|
41
|
+
results.each_with_index do |val, j|
|
42
|
+
assert val, "Can retrieve filter item #{i}"
|
43
|
+
i = j
|
56
44
|
end
|
45
|
+
assert_equal(i, total-1)
|
46
|
+
end
|
57
47
|
|
48
|
+
def test_range
|
49
|
+
limit = 30
|
50
|
+
results = @dataset.query(:paging => true, :limit => limit).
|
51
|
+
filter(:hgnc_id__range => [10, 6000])[2..5]
|
52
|
+
assert_equal(3, results.size)
|
58
53
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
filter(:hg19_start__range => [140000000, 140050000])[2..5]
|
64
|
-
assert_equal(3, results.size)
|
65
|
-
|
66
|
-
results = @dataset.query(:paging => true, :limit => limit).
|
67
|
-
filter(:hg19_start__range => [140000000, 140050000])[0..8]
|
68
|
-
assert_equal(7, results.size)
|
69
|
-
end
|
54
|
+
results = @dataset.query(:paging => true, :limit => limit).
|
55
|
+
filter(:hgnc_id__range => [10, 6000])[0..7]
|
56
|
+
assert_equal(7, results.size)
|
57
|
+
end
|
70
58
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
idx1 = 5
|
75
|
-
|
76
|
-
query = proc{
|
77
|
-
@dataset.query( :paging => true, :limit => 20).
|
78
|
-
filter(:hg19_start__range => [140000000, 140060000])[2..10]
|
79
|
-
}
|
80
|
-
|
81
|
-
results_slice = query.call()[idx0...idx1]
|
82
|
-
results_paging = []
|
83
|
-
query.call.each_with_index do |r, i|
|
84
|
-
break if i == idx1
|
85
|
-
results_paging << r if i >= idx0
|
86
|
-
end
|
87
|
-
|
88
|
-
assert_equal(results_slice.size, results_paging.size)
|
89
|
-
|
90
|
-
results_paging.size.times do |i|
|
91
|
-
id_a = results_paging[i][:hg19_start]
|
92
|
-
id_b = results_slice[i][:hg19_start]
|
93
|
-
assert_equal(id_a, id_b)
|
94
|
-
end
|
95
|
-
end
|
59
|
+
def test_paging_and_slice_equivalence
|
60
|
+
idx0 = 3
|
61
|
+
idx1 = 5
|
96
62
|
|
63
|
+
query = proc{
|
64
|
+
@dataset.query( :paging => true, :limit => 10).
|
65
|
+
filter(:hgnc_id__range => [1000, 5000])[2..10]
|
66
|
+
}
|
97
67
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
68
|
+
results_slice = query.call()[idx0...idx1]
|
69
|
+
results_paging = []
|
70
|
+
query.call.each_with_index do |r, i|
|
71
|
+
break if i == idx1
|
72
|
+
results_paging << r if i >= idx0
|
73
|
+
end
|
102
74
|
|
103
|
-
|
104
|
-
# q = self.dataset.query(paging=True, limit=100) \
|
105
|
-
# .filter(omim_id__in=range(100000, 120000))
|
106
|
-
results_slice = q[idx0..idx1]
|
107
|
-
results_cached = q[idx0..idx1]
|
75
|
+
assert_equal(results_slice.size, results_paging.size)
|
108
76
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
assert_equal(id_b, id_a)
|
114
|
-
end
|
77
|
+
results_paging.size.times do |i|
|
78
|
+
id_a = results_paging[i][:hgnic_id]
|
79
|
+
id_b = results_slice[i][:hgnc_id]
|
80
|
+
assert_equal(id_a, id_b)
|
115
81
|
end
|
82
|
+
end
|
116
83
|
|
117
|
-
|
118
|
-
|
119
|
-
|
84
|
+
def test_caching
|
85
|
+
idx0 = 60
|
86
|
+
idx1 = 81
|
87
|
+
|
88
|
+
q = @dataset.query(:paging => true, :limit => 100)
|
89
|
+
# q = self.dataset.query(paging=True, limit=100) \
|
90
|
+
# .filter(omim_id__in=range(100000, 120000))
|
91
|
+
results_slice = q[idx0..idx1]
|
92
|
+
results_cached = q[idx0..idx1]
|
93
|
+
|
94
|
+
assert_equal(results_slice.size, results_cached.size)
|
95
|
+
results_slice.size-1.times do |i|
|
96
|
+
id_a = results_slice[i]['reference_allele']
|
97
|
+
id_b = results_cached[i]['reference_allele']
|
98
|
+
assert_equal(id_b, id_a)
|
120
99
|
end
|
121
100
|
end
|
122
101
|
|