solvebio 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.travis.yml +13 -0
- data/Gemfile +4 -0
- data/Gemspec +3 -0
- data/LICENSE +21 -0
- data/Makefile +17 -0
- data/README.md +64 -0
- data/Rakefile +59 -0
- data/bin/solvebio.rb +36 -0
- data/demo/README.md +14 -0
- data/demo/dataset/facets.rb +13 -0
- data/demo/dataset/field.rb +13 -0
- data/demo/depository/README.md +24 -0
- data/demo/depository/all.rb +13 -0
- data/demo/depository/retrieve.rb +13 -0
- data/demo/depository/versions-all.rb +13 -0
- data/demo/query/query-filter.rb +30 -0
- data/demo/query/query.rb +13 -0
- data/demo/query/range-filter.rb +18 -0
- data/demo/test-api.rb +98 -0
- data/lib/apiresource.rb +130 -0
- data/lib/cli/auth.rb +122 -0
- data/lib/cli/help.rb +13 -0
- data/lib/cli/irb.rb +58 -0
- data/lib/cli/irbrc.rb +53 -0
- data/lib/cli/options.rb +75 -0
- data/lib/client.rb +152 -0
- data/lib/credentials.rb +67 -0
- data/lib/errors.rb +81 -0
- data/lib/filter.rb +312 -0
- data/lib/help.rb +46 -0
- data/lib/locale.rb +47 -0
- data/lib/main.rb +37 -0
- data/lib/query.rb +415 -0
- data/lib/resource.rb +414 -0
- data/lib/solvebio.rb +14 -0
- data/lib/solveobject.rb +101 -0
- data/lib/tabulate.rb +706 -0
- data/solvebio.gemspec +75 -0
- data/test/data/netrc-save +6 -0
- data/test/helper.rb +3 -0
- data/test/test-auth.rb +54 -0
- data/test/test-client.rb +27 -0
- data/test/test-error.rb +36 -0
- data/test/test-filter.rb +70 -0
- data/test/test-netrc.rb +42 -0
- data/test/test-query-batch.rb +60 -0
- data/test/test-query-init.rb +29 -0
- data/test/test-query-paging.rb +123 -0
- data/test/test-query.rb +88 -0
- data/test/test-resource.rb +47 -0
- data/test/test-solveobject.rb +27 -0
- data/test/test-tabulate.rb +127 -0
- metadata +158 -0
data/test/test-query.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
$VERBOSE = true
|
2
|
+
require_relative 'helper'
|
3
|
+
|
4
|
+
class TestQuery < Test::Unit::TestCase
|
5
|
+
|
6
|
+
TEST_DATASET_NAME = 'ClinVar/2.0.0-1/Variants'
|
7
|
+
|
8
|
+
if SolveBio::api_key
|
9
|
+
|
10
|
+
def setup
|
11
|
+
begin
|
12
|
+
@dataset = SolveBio::Dataset.retrieve(TEST_DATASET_NAME)
|
13
|
+
rescue SocketError
|
14
|
+
@dataset = nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# When paging is off, results.length should return the number of
|
19
|
+
# results retrieved.
|
20
|
+
def test_limit
|
21
|
+
skip('Are you connected to the Internet?') unless @dataset
|
22
|
+
@dataset = SolveBio::Dataset.retrieve(TEST_DATASET_NAME)
|
23
|
+
limit = 10
|
24
|
+
results = @dataset.query :paging=>false, :limit => limit
|
25
|
+
assert_equal(limit, results.length,
|
26
|
+
'limit == results.size, paging = false')
|
27
|
+
|
28
|
+
|
29
|
+
results.each_with_index do |val, i|
|
30
|
+
assert results[i], "retrieving value at #{i}"
|
31
|
+
end
|
32
|
+
|
33
|
+
assert_raise IndexError do
|
34
|
+
puts results[limit]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# test Query when limit is specified and is GREATER THAN total available
|
39
|
+
# results
|
40
|
+
def test_limit_empty
|
41
|
+
skip('Are you connected to the Internet?') unless @dataset
|
42
|
+
limit = 100
|
43
|
+
results = @dataset.query(:paging=>false, :limit => limit).
|
44
|
+
filter({:hg19_start => 1234})
|
45
|
+
assert_equal(0, results.size)
|
46
|
+
|
47
|
+
assert_raise IndexError do
|
48
|
+
puts results[0]
|
49
|
+
end
|
50
|
+
|
51
|
+
results = @dataset.query(:paging=>false, :limit => limit).
|
52
|
+
filter :hg19_start => 148459988
|
53
|
+
assert_equal(1, results.size)
|
54
|
+
end
|
55
|
+
|
56
|
+
# test Filtered Query in which limit is specified but is GREATER THAN
|
57
|
+
# the number of total available results
|
58
|
+
def test_limit_filter
|
59
|
+
skip('Are you connected to the Internet?') unless @dataset
|
60
|
+
limit = 10
|
61
|
+
num_filters = 3
|
62
|
+
|
63
|
+
filters3 =
|
64
|
+
SolveBio::Filter.new(:hg19_start => 148459988) |
|
65
|
+
SolveBio::Filter.new(:hg19_start => 148562304) |
|
66
|
+
SolveBio::Filter.new(:hg19_start => 148891521)
|
67
|
+
|
68
|
+
results = @dataset.query(:paging=>false, :limit => limit,
|
69
|
+
:filters => filters3)
|
70
|
+
|
71
|
+
num_filters.times do |i|
|
72
|
+
assert results[i]
|
73
|
+
end
|
74
|
+
|
75
|
+
assert_equal(num_filters, results.size)
|
76
|
+
|
77
|
+
assert_raise IndexError do
|
78
|
+
puts results[num_filters]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
else
|
83
|
+
def test_skip
|
84
|
+
skip 'Please set SolveBio::api_key'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$VERBOSE = true
|
3
|
+
require 'test/unit'
|
4
|
+
require_relative '../lib/resource'
|
5
|
+
|
6
|
+
class TestResource < Test::Unit::TestCase
|
7
|
+
|
8
|
+
# Do the class FULL_NAME_REGEX contants match what the think they
|
9
|
+
# should?
|
10
|
+
def test_full_name_regexp
|
11
|
+
assert('Clinvar/2.0.0-1/Variants' =~
|
12
|
+
SolveBio::Dataset::FULL_NAME_REGEX,
|
13
|
+
'Dataset regexp')
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_SolveObject_inspect
|
18
|
+
str = SolveBio::SolveObject.new.inspect
|
19
|
+
assert(str =~ /^<SolveBio::SolveObject:[[:xdigit:]]+> JSON: {}/,
|
20
|
+
'empty SolveObject inspect')
|
21
|
+
str = SolveBio::SolveObject.new(62).inspect
|
22
|
+
assert(str =~ /^<SolveBio::SolveObject id=62:[[:xdigit:]]+> JSON: {"id":62}/,
|
23
|
+
"SolveObject inspect with id #{str}")
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_Dataset_from_response
|
28
|
+
resp = {
|
29
|
+
'class_name' => 'Dataset',
|
30
|
+
'data_url' => 'https://api.solvebio.com/v1/datasets/25/data',
|
31
|
+
'depository' => 'ClinVar',
|
32
|
+
'depository_id' => 223,
|
33
|
+
'depository_version' => 'ClinVar/2.0.0-1',
|
34
|
+
'depository_version_id' => 15,
|
35
|
+
'description' => '',
|
36
|
+
'fields_url' => 'https://api.solvebio.com/v1/datasets/25/fields',
|
37
|
+
'full_name' => 'ClinVar/2.0.0-1/Variants',
|
38
|
+
'id' => 25,
|
39
|
+
'name' => 'Variants',
|
40
|
+
'title' => 'Variants',
|
41
|
+
'url' => 'https://api.solvebio.com/v1/datasets/25'
|
42
|
+
}
|
43
|
+
so = resp.to_solvebio
|
44
|
+
assert_equal SolveBio::Dataset, so.class, 'Hash -> SolveObject'
|
45
|
+
resp.keys.each {|k| assert_equal resp[k], so[k]}
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$VERBOSE = true
|
3
|
+
require 'test/unit'
|
4
|
+
require_relative '../lib/solveobject'
|
5
|
+
|
6
|
+
class TestSolveObject < Test::Unit::TestCase
|
7
|
+
|
8
|
+
# Does our kind of camelCasing works?
|
9
|
+
def test_camelcase
|
10
|
+
|
11
|
+
data =
|
12
|
+
[
|
13
|
+
['abc', 'abc', 'no camelcase'],
|
14
|
+
['aBcDef', 'a_bc_def', 'letters only'],
|
15
|
+
['abc01Def', 'abc01_def', 'letters and numbers'],
|
16
|
+
['aBcDef', 'a_bc_def', 'multiple letter match'],
|
17
|
+
['a1B2C3', 'a1_b2_c3', 'multi letters and numbers'],
|
18
|
+
['?Foo', '?_foo', 'weird symbols, part 1'],
|
19
|
+
['Dataset', 'dataset', 'no camelcase with caps'],
|
20
|
+
]
|
21
|
+
data.each do |triple|
|
22
|
+
assert_equal(triple[1],
|
23
|
+
camelcase_to_underscore(triple[0]),
|
24
|
+
triple[2])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require_relative '../lib/tabulate'
|
4
|
+
$VERBOSE = true
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
class TestTabulate < Test::Unit::TestCase
|
8
|
+
|
9
|
+
include SolveBio::Tabulate
|
10
|
+
|
11
|
+
def test_classify
|
12
|
+
|
13
|
+
assert_equal true, '123.45'.number?
|
14
|
+
assert_equal true, '123'.number?
|
15
|
+
assert_equal false, 'spam'.number?
|
16
|
+
assert_equal true, '123'.int?
|
17
|
+
assert_equal false, '123.45'.int?
|
18
|
+
|
19
|
+
assert_equal NilClass, _type(nil)
|
20
|
+
assert_equal String, _type('foo')
|
21
|
+
assert_equal Fixnum, _type('1')
|
22
|
+
assert_equal Fixnum, _type(1)
|
23
|
+
assert_equal Fixnum, _type('\x1b[31m42\x1b[0m')
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_align
|
27
|
+
assert_equal( 2, '123.45'.afterpoint)
|
28
|
+
assert_equal(-1, '1001'.afterpoint)
|
29
|
+
assert_equal(-1, 'eggs'.afterpoint)
|
30
|
+
assert_equal( 2, '123e45'.afterpoint)
|
31
|
+
|
32
|
+
assert_equal(" \u044f\u0439\u0446\u0430",
|
33
|
+
"\u044f\u0439\u0446\u0430".padleft(6))
|
34
|
+
assert_equal("\u044f\u0439\u0446\u0430 ",
|
35
|
+
"\u044f\u0439\u0446\u0430".padright(6))
|
36
|
+
|
37
|
+
assert_equal(" \u044f\u0439\u0446\u0430 ",
|
38
|
+
"\u044f\u0439\u0446\u0430".padboth(6))
|
39
|
+
|
40
|
+
assert_equal(" \u044f\u0439\u0446\u0430 ",
|
41
|
+
"\u044f\u0439\u0446\u0430".padboth(7))
|
42
|
+
|
43
|
+
assert_equal('abc', 'abc'.padright(2))
|
44
|
+
assert_equal('abc', 'abc'.padleft(2))
|
45
|
+
assert_equal('abc', 'abc'.padboth(2))
|
46
|
+
|
47
|
+
|
48
|
+
assert_equal([' 12.345 ', '-1234.5 ', ' 1.23 ',
|
49
|
+
' 1234.5 ', ' 1e+234 ', ' 1.0e234'],
|
50
|
+
align_column(
|
51
|
+
["12.345", "-1234.5", "1.23", "1234.5",
|
52
|
+
"1e+234", "1.0e234"], "decimal"))
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_column_type
|
56
|
+
assert_equal(Fixnum, column_type(["1", "2"]))
|
57
|
+
assert_equal(Float, column_type(["1", "2.3"]))
|
58
|
+
assert_equal(String, column_type(["1", "2.3", "four"]))
|
59
|
+
assert_equal(String,
|
60
|
+
column_type(["four", '\u043f\u044f\u0442\u044c']))
|
61
|
+
assert_equal(String, column_type([nil, "brux"]))
|
62
|
+
assert_equal(Fixnum, column_type([1, 2, nil]))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_tabulate
|
66
|
+
tsv = simple_separated_format("\t")
|
67
|
+
expected = <<-EOS
|
68
|
+
foo 1
|
69
|
+
spam 23
|
70
|
+
EOS
|
71
|
+
assert_equal(expected.chomp, tabulate([["foo", 1], ["spam", 23]], [], tsv),
|
72
|
+
'simple separated format table')
|
73
|
+
####################################################################
|
74
|
+
expected = <<-EOS
|
75
|
+
| буква | цифра |
|
76
|
+
|---------+---------|
|
77
|
+
| аз | 2 |
|
78
|
+
| буки | 4 |
|
79
|
+
EOS
|
80
|
+
hrow = ["\u0431\u0443\u043a\u0432\u0430", "\u0446\u0438\u0444\u0440\u0430"]
|
81
|
+
tbl = [["\u0430\u0437", 2], ["\u0431\u0443\u043a\u0438", 4]]
|
82
|
+
assert_equal(expected.chomp, SolveBio::Tabulate.tabulate(tbl, hrow),
|
83
|
+
'org mode with header and unicode')
|
84
|
+
|
85
|
+
###################################################################
|
86
|
+
expected = <<-EOS
|
87
|
+
| Fields | Data |
|
88
|
+
|-----------------------+-----------------------------|
|
89
|
+
| rcvaccession_version | 2 |
|
90
|
+
| hg18_chromosome | 3 |
|
91
|
+
| hg19_start | 148562304 |
|
92
|
+
| rcvaccession | RCV000060731 |
|
93
|
+
| hg38_start | 148844517 |
|
94
|
+
| reference_allele | C |
|
95
|
+
| gene_symbols | CPB1 |
|
96
|
+
| rsid | rs150241322 |
|
97
|
+
| hg19_chromosome | 3 |
|
98
|
+
| hgvs | NC_000003.12:g.148844517C>T |
|
99
|
+
| clinical_significance | other |
|
100
|
+
| alternate_alleles | T |
|
101
|
+
| clinical_origin | somatic |
|
102
|
+
| type | SNV |
|
103
|
+
EOS
|
104
|
+
|
105
|
+
hash = {
|
106
|
+
"rcvaccession_version"=>2,
|
107
|
+
"hg18_chromosome"=>"3",
|
108
|
+
"hg19_start"=>148562304,
|
109
|
+
"rcvaccession"=>"RCV000060731",
|
110
|
+
"hg38_start"=>148844517,
|
111
|
+
"reference_allele"=>"C",
|
112
|
+
"gene_symbols"=>["CPB1"],
|
113
|
+
"rsid"=>"rs150241322",
|
114
|
+
"hg19_chromosome"=>"3",
|
115
|
+
"hgvs"=>["NC_000003.12:g.148844517C>T"],
|
116
|
+
"clinical_significance"=>"other",
|
117
|
+
"alternate_alleles"=>["T"],
|
118
|
+
"clinical_origin"=>["somatic"],
|
119
|
+
"type"=>"SNV"
|
120
|
+
}
|
121
|
+
assert_equal(expected.chomp, tabulate(hash.to_a,
|
122
|
+
['Fields', 'Data'],
|
123
|
+
['right', 'left']),
|
124
|
+
'mixed data with arrays; close to actual query output')
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: solvebio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.5.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- solvebio.com
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2014-08-16 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: netrc
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.7.7
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rake
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rdoc
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
description: |
|
49
|
+
SolveBio is a platform for biomedical datasets. With SolveBio you can
|
50
|
+
forget about parsing complex flat files and sifting through cryptic
|
51
|
+
datasets. Just use the Ruby Client and API to explore massive
|
52
|
+
datasets and automate just about any bioinformatics workflow.
|
53
|
+
|
54
|
+
See https://www.solvebio.com/docs/api/ for more information.
|
55
|
+
|
56
|
+
email: contact@solvebio.com
|
57
|
+
executables:
|
58
|
+
- solvebio.rb
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files:
|
62
|
+
- LICENSE
|
63
|
+
files:
|
64
|
+
- .gitignore
|
65
|
+
- .travis.yml
|
66
|
+
- Gemfile
|
67
|
+
- Gemspec
|
68
|
+
- LICENSE
|
69
|
+
- Makefile
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/solvebio.rb
|
73
|
+
- demo/README.md
|
74
|
+
- demo/dataset/facets.rb
|
75
|
+
- demo/dataset/field.rb
|
76
|
+
- demo/depository/README.md
|
77
|
+
- demo/depository/all.rb
|
78
|
+
- demo/depository/retrieve.rb
|
79
|
+
- demo/depository/versions-all.rb
|
80
|
+
- demo/query/query-filter.rb
|
81
|
+
- demo/query/query.rb
|
82
|
+
- demo/query/range-filter.rb
|
83
|
+
- demo/test-api.rb
|
84
|
+
- lib/apiresource.rb
|
85
|
+
- lib/cli/auth.rb
|
86
|
+
- lib/cli/help.rb
|
87
|
+
- lib/cli/irb.rb
|
88
|
+
- lib/cli/irbrc.rb
|
89
|
+
- lib/cli/options.rb
|
90
|
+
- lib/client.rb
|
91
|
+
- lib/credentials.rb
|
92
|
+
- lib/errors.rb
|
93
|
+
- lib/filter.rb
|
94
|
+
- lib/help.rb
|
95
|
+
- lib/locale.rb
|
96
|
+
- lib/main.rb
|
97
|
+
- lib/query.rb
|
98
|
+
- lib/resource.rb
|
99
|
+
- lib/solvebio.rb
|
100
|
+
- lib/solveobject.rb
|
101
|
+
- lib/tabulate.rb
|
102
|
+
- solvebio.gemspec
|
103
|
+
- test/data/netrc-save
|
104
|
+
- test/helper.rb
|
105
|
+
- test/test-auth.rb
|
106
|
+
- test/test-client.rb
|
107
|
+
- test/test-error.rb
|
108
|
+
- test/test-filter.rb
|
109
|
+
- test/test-netrc.rb
|
110
|
+
- test/test-query-batch.rb
|
111
|
+
- test/test-query-init.rb
|
112
|
+
- test/test-query-paging.rb
|
113
|
+
- test/test-query.rb
|
114
|
+
- test/test-resource.rb
|
115
|
+
- test/test-solveobject.rb
|
116
|
+
- test/test-tabulate.rb
|
117
|
+
homepage: https://www.solvebio.com
|
118
|
+
licenses: []
|
119
|
+
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options:
|
122
|
+
- --charset=UTF-8
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 1.9.0
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: "0"
|
137
|
+
requirements: []
|
138
|
+
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 1.8.23
|
141
|
+
signing_key:
|
142
|
+
specification_version: 2
|
143
|
+
summary: SolveBio Ruby bindings.
|
144
|
+
test_files:
|
145
|
+
- test/data/netrc-save
|
146
|
+
- test/helper.rb
|
147
|
+
- test/test-auth.rb
|
148
|
+
- test/test-client.rb
|
149
|
+
- test/test-error.rb
|
150
|
+
- test/test-filter.rb
|
151
|
+
- test/test-netrc.rb
|
152
|
+
- test/test-query-batch.rb
|
153
|
+
- test/test-query-init.rb
|
154
|
+
- test/test-query-paging.rb
|
155
|
+
- test/test-query.rb
|
156
|
+
- test/test-resource.rb
|
157
|
+
- test/test-solveobject.rb
|
158
|
+
- test/test-tabulate.rb
|