solvebio 1.7.2 → 1.7.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31db4c26b2c9b63dcbebbe8696a37b3e0946c831
4
- data.tar.gz: 84b6c054b263fde61e0123c03eabbe9240cd4177
3
+ metadata.gz: fe11b480aa4ded4563e8615f5aff700e65d79d28
4
+ data.tar.gz: 951035287b583008e5351229aa3c46f7ab3e4d7d
5
5
  SHA512:
6
- metadata.gz: 6874a148c1e5a109981fdb3aa649437c58c8037232f3cbcdd25b9c31365290575c1a3f29ec6934710695aea5986f96ef419686b7eff07fad4cfcea153eb7a41d
7
- data.tar.gz: 24f926d966b43b7ab239993169bfe35f87abfb1f0e0c9f3a4f93d91133e0a9b1647d31b253ecc18c8d645219ee1da631163dd6846a8142515704a6a1c2a8cd1c
6
+ metadata.gz: c2533fc844714b62149bf76086dc5945d77a0db209ddd9afbb029d530e31476133e0bb6d38dde2e174e5b7347054c8d92e51a5a7a9b7f8a9b5148789902a7b6f
7
+ data.tar.gz: 4f56c1719d719818b2cecbe90923832edf0831eb9bfb9acbcaf61289553b2b91e910d8cea2640b191ba93531d96e39ece7c64cf02a96e470473fae0a5652929b
data/.bumpversion.cfg CHANGED
@@ -1,5 +1,5 @@
1
1
  [bumpversion]
2
- current_version = 1.7.2
2
+ current_version = 1.7.3
3
3
  files = lib/solvebio/version.rb
4
4
  commit = True
5
5
  tag = False
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
+ sudo: false
2
3
  before_script:
3
4
  - gem install netrc --version=0.7.7
4
5
  - gem install rest_client addressable webmock
data/Rakefile CHANGED
@@ -25,7 +25,8 @@ end
25
25
 
26
26
  task :install => :gem do
27
27
  Dir.chdir(ROOT_DIR) do
28
- sh %{gem install --dev --both pkg/#{gemspec.file_name}}
28
+ sh %{gem install --both pkg/#{gemspec.file_name}}
29
+ # sh %{gem install --dev --both pkg/#{gemspec.file_name}}
29
30
  end
30
31
  end
31
32
 
@@ -108,23 +108,6 @@ module SolveBio
108
108
  def self.included base
109
109
  base.extend ClassMethods
110
110
  end
111
-
112
- def to_s
113
- if self.class.constants.member?(:TAB_FIELDS)
114
- items = self.class.const_get(:TAB_FIELDS).map{
115
- |name| [name, self[name]]
116
- }
117
- else
118
- items = self
119
- end
120
- return Tabulate.tabulate(items, ['Fields', 'Data'],
121
- ['right', 'left'], true)
122
- end
123
-
124
- def size
125
- self[:total]
126
- end
127
- alias :total :size
128
111
  end
129
112
 
130
113
  module Search
@@ -0,0 +1,124 @@
1
+
2
+ ____ _ ____ _
3
+ / ___| ___ | |_ _____| __ )(_) ___
4
+ \___ \ / _ \| \ \ / / _ \ _ \| |/ _ \
5
+ ___) | (_) | |\ V / __/ |_) | | (_) |
6
+ |____/ \___/|_| \_/ \___|____/|_|\___/
7
+ For Ruby
8
+
9
+
10
+ # Welcome to the SolveBio Ruby Tutorial!
11
+
12
+ First, open the SolveBio Ruby shell by typing "solvebio.rb".
13
+
14
+ The SolveBio Ruby Shell is based on IRB. When you log in, it will automatically pick up your API key.
15
+
16
+ View this tutorial online: https://www.solvebio.com/docs/ruby-tutorial
17
+
18
+
19
+ ## Navigate the Library
20
+
21
+ List all available depositories:
22
+
23
+ Depository.all
24
+
25
+
26
+ Depositories are versioned containers of datasets. There are many versions of each depository, and each version may have one or more datasets.
27
+
28
+ To list all datasets from all depositories:
29
+
30
+ Dataset.all
31
+
32
+
33
+ Pass "latest=true" to get all the latest versions of each dataset:
34
+
35
+ Dataset.all(:latest => true)
36
+
37
+
38
+ To retrieve a dataset by its full name ("ClinVar/3.0.0-2014-12-05/Variants"):
39
+
40
+ Dataset.retrieve('ClinVar/3.0.0-2014-12-05/Variants')
41
+
42
+ By leaving out the version (for example: "ClinVar/Variants"), you get a quick shortcut to the latest version of any dataset.
43
+ **Be careful here: you should always specify an exact version in your production code**.
44
+
45
+
46
+ ## Query a Dataset
47
+
48
+ Every dataset in SolveBio can be queried the same way. You can build queries manually in the Ruby shell, or use our visual Workbench (https://www.solvebio.com/workbench).
49
+
50
+ In this example, we will query the latest Variants dataset from ClinVar.
51
+
52
+ dataset = Dataset.retrieve('ClinVar/Variants')
53
+ dataset.query
54
+
55
+
56
+ The "query()" function returns a Ruby enumerable so you can loop through all the results easily.
57
+
58
+ To examine a single result more closely, you may treat the query response as a list of dictionaries:
59
+
60
+ dataset.query[0]
61
+
62
+
63
+ You can also slice the result set like any other Ruby array:
64
+
65
+ dataset.query[0..100]
66
+
67
+
68
+ ## Filter a Dataset
69
+
70
+ To narrow down your query, you can filter on any field. For example, to get all variants in ClinVar that are Pathogenic, you would filter on the `clinical_significance` field for "Pathogenic":
71
+
72
+ dataset.query.filter(:clinical_significance => 'Pathogenic')
73
+
74
+
75
+ By default, adding more filters will result in a boolean AND query (all filters must match):
76
+
77
+ dataset.query.filter(:clinical_significance => 'Pathogenic', :review_status => 'single')
78
+
79
+
80
+ Use the "Filter" class to do more advanced filtering. For example, combine a few filters using boolean OR:
81
+
82
+ filters = Filter(:clinical_significance => 'Pathogenic') | Filter(:clinical_significance => 'Benign')
83
+ dataset.query.filter(filters)
84
+
85
+
86
+ ## Genomic Datasets
87
+
88
+ Some SolveBio datasets allow querying by genome build. We call these "genomic datasets". To find out if a dataset is genomic, and what genome builds are supported:
89
+
90
+ dataset.is_genomic
91
+ > true
92
+ dataset.genome_builds
93
+ > ['GRCh38', 'GRCh37']
94
+
95
+
96
+ By default, build 'GRCh37' will be selected if it is available. If not, the most recent build will be selected by default. To manually select a genome build when querying, specify the build as a query parameter:
97
+
98
+ dataset.query(:genome_build => 'GRCh38')
99
+
100
+
101
+ On genomic datasets, you may query by position (single nucleotide) or by range:
102
+
103
+ dataset.query(:genome_build => 'GRCh37').position('chr1', 976629)
104
+ > ...
105
+ dataset.query(:genome_build => 'GRCh37').range('chr1', 976629, 1000000)
106
+ > ...
107
+
108
+
109
+ Position and range queries return all results that overlap with the specified coordinate(s).
110
+ Add the parameter `exact=true` to request exact matches.
111
+
112
+
113
+ dataset.query(:genome_build => 'GRCh37').position('chr1', 883516, exact=true)
114
+ > ...
115
+ dataset.query(:genome_build => 'GRCh37').range('chr9', 136289550, 136289579, exact=true)
116
+ > ...
117
+
118
+
119
+ ## Next Steps
120
+
121
+ To learn more about a dataset and its fields, use `dataset.help()`.
122
+ For more information on queries and filters, see the API reference: https://www.solvebio.com/docs/api?ruby
123
+
124
+
@@ -2,11 +2,34 @@ module SolveBio
2
2
  module CLI
3
3
  module Tutorial
4
4
  def tutorial
5
- puts <<-TUTORIAL
6
- # Tutorial coming soon!
7
- TUTORIAL
5
+ tutorial_file = File.join(File.dirname(__FILE__), "tutorial.md")
6
+ less = which('less')
7
+ if less
8
+ exec less + ' ' + tutorial_file
9
+ else
10
+ puts File.read(tutorial_file)
11
+ puts
12
+ puts "#######################################################################"
13
+ puts
14
+ puts "Warning: 'less' command not found in $PATH."
15
+ puts "Read the tutorial online at https://www.solvebio.com/docs/ruby-tutorial"
16
+ puts
17
+ puts "#######################################################################"
18
+ puts
19
+ end
8
20
  end
9
21
  module_function :tutorial
22
+
23
+ def which(cmd)
24
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
25
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
26
+ exts.each { |ext|
27
+ exe = File.join(path, "#{cmd}#{ext}")
28
+ return exe if File.executable?(exe) && !File.directory?(exe)
29
+ }
30
+ end
31
+ return nil
32
+ end
10
33
  end
11
34
  end
12
35
  end
@@ -74,6 +74,11 @@ module SolveBio
74
74
  headers = opts[:default_headers] ? @headers.merge(opts[:headers] || {}) : nil
75
75
  authorization = api_key ? "Token #{api_key}" : nil
76
76
 
77
+ # In Rest-Client, GET params are parsed from headers[:params]
78
+ if opts[:params]
79
+ headers.merge!({:params => opts[:params]})
80
+ end
81
+
77
82
  # By default, encode payload as JSON
78
83
  if ['post', 'put', 'patch'].include?(method.downcase) and opts[:json]
79
84
  opts[:payload] = opts[:payload].to_json
@@ -6,6 +6,9 @@ module SolveBio
6
6
  include SolveBio::APIOperations::Delete
7
7
  include SolveBio::APIOperations::Help
8
8
 
9
+ LIST_FIELDS = [%w(full_name title description),
10
+ %w(Name Title Description)]
11
+
9
12
  def depository
10
13
  return Depository.retrieve(self.depository)
11
14
  end
@@ -11,8 +11,11 @@ module SolveBio
11
11
  include SolveBio::APIOperations::Update
12
12
  include SolveBio::APIOperations::Help
13
13
 
14
+ @@permanent_attributes = Set.new([:id, :latest_version])
15
+
14
16
  # Fields that get shown by tabulate
15
- TAB_FIELDS = %w(description full_name latest_version name title url)
17
+ LIST_FIELDS = [%w(full_name title description),
18
+ %w(Name Title Description)]
16
19
 
17
20
  def versions(name=nil, params={})
18
21
  # construct the depo version full name
@@ -34,5 +37,9 @@ module SolveBio
34
37
  results
35
38
  end
36
39
 
40
+ def latest_version
41
+ return versions(self[:latest_version].split('/')[-1])
42
+ end
43
+
37
44
  end
38
45
  end
@@ -6,8 +6,8 @@ module SolveBio
6
6
  include SolveBio::APIOperations::Help
7
7
 
8
8
  # Fields that get shown by tabulate
9
- TAB_FIELDS = %w(datasets_url depository description full_name
10
- latest url)
9
+ LIST_FIELDS = [%w(full_name title description),
10
+ %w(Name Title Description)]
11
11
 
12
12
  def datasets_url(name=nil)
13
13
  name ||= self['name']
@@ -1,6 +1,5 @@
1
1
  module SolveBio
2
2
  class ListObject < SolveObject
3
-
4
3
  def [](k)
5
4
  case k
6
5
  when String, Symbol
@@ -45,10 +44,26 @@ module SolveBio
45
44
  self.to_a[i]
46
45
  end
47
46
 
47
+ def size
48
+ self[:total]
49
+ end
50
+ alias :total :size
51
+
48
52
  def to_a
49
53
  return Util.to_solve_object(self.data)
50
54
  end
51
55
 
56
+ def to_s
57
+ if self.data[0] and self.data[0].class.constants.member?(:LIST_FIELDS)
58
+ # Tabulate the result list
59
+ fields, headers = self.data[0].class::LIST_FIELDS
60
+ items = self.data.map { |item| fields.map{ |field| item[field] } }
61
+ return "\n" + Tabulate.tabulate(items, headers)
62
+ end
63
+ super
64
+ end
65
+ alias :inspect :to_s
66
+
52
67
  def each(*pass)
53
68
  return self unless block_given?
54
69
  i = 0
@@ -41,16 +41,15 @@ module SolveBio
41
41
  @filters = params[:filters].kind_of?(SolveBio::Filter) ? params[:filters].filters : (params[:filters] || [])
42
42
 
43
43
  @response = nil
44
- # Limit defines the total number of results that will be returned
44
+ # limit defines the total number of results that will be returned
45
45
  # from a query involving 1 or more pagination requests.
46
46
  @limit = params[:limit] || INT_MAX
47
- # Page limit and page offset are the low level API limit and offset params.
48
- # page_offset may be changed periodically during sequential pagination requests.
47
+ # page_size/page_offset are the low level API limit and offset params.
49
48
  @page_size = params[:page_size] || DEFAULT_PAGE_SIZE
50
- # Page offset can only be set by execute()
49
+ # page_offset can only be set by execute()
51
50
  # It always contains the current absolute offset contained in the buffer.
52
51
  @page_offset = nil
53
- # @slice is set to tell the Query object that is being sliced and "def each" should not
52
+ # slice is set to tell the Query object that is being sliced and "def each" should not
54
53
  # reset the page_offset to 0 before iterating.
55
54
  @slice = nil
56
55
 
@@ -3,6 +3,11 @@ module SolveBio
3
3
  TYPES = {NilClass => 0, Fixnum => 1, Float => 2, String => 4}
4
4
 
5
5
  INVISIBILE_CODES = %r{\\x1b\[\d*m} # ANSI color codes
6
+
7
+ def self.tty_cols
8
+ cols = (ENV['COLUMNS'].to_i || 80 rescue 80)
9
+ return cols > 0 ? cols : 80
10
+ end
6
11
 
7
12
  Line = Struct.new(:start, :hline, :sep, :last)
8
13
 
@@ -288,23 +293,21 @@ module SolveBio
288
293
  return rows, headers
289
294
  end
290
295
 
291
- TTY_COLS = ENV['COLUMNS'].to_i || 80 rescue 80
292
296
  # Return a string which represents a row of data cells.
293
297
  def build_row(cells, padding, first, sep, last)
294
-
295
298
  pad = ' ' * padding
296
299
  padded_cells = cells.map{|cell| pad + cell + pad }
297
300
  rendered_cells = (first + padded_cells.join(sep) + last).rstrip
298
301
 
299
302
  # Enforce that we don't wrap lines by setting a max
300
303
  # limit on row width which is equal to TTY_COLS (see printing)
301
- if rendered_cells.size > TTY_COLS
304
+ if rendered_cells.size > Tabulate.tty_cols
302
305
  if not cells[-1].end_with?(' ') and not cells[-1].end_with?('-')
303
306
  terminating_str = ' ... '
304
307
  else
305
308
  terminating_str = ''
306
309
  end
307
- prefix = rendered_cells[0..TTY_COLS - terminating_str.size - 2]
310
+ prefix = rendered_cells[0..Tabulate.tty_cols - terminating_str.size - 2]
308
311
  rendered_cells = "%s%s%s" % [prefix, terminating_str, last]
309
312
  end
310
313
 
@@ -395,6 +398,7 @@ module SolveBio
395
398
  end
396
399
  end
397
400
  end
401
+
398
402
  return lines.join("\n")
399
403
  end
400
404
 
@@ -426,8 +430,11 @@ module SolveBio
426
430
  end
427
431
 
428
432
  # format rows and columns, convert numeric values to strings
429
- cols = list_of_lists[0].zip(*list_of_lists[1..-1]) if
430
- list_of_lists.size > 1
433
+ if list_of_lists.size == 1
434
+ cols = [[list_of_lists[0][0]], [list_of_lists[0][1]]]
435
+ else
436
+ cols = list_of_lists[0].zip(*list_of_lists[1..-1])
437
+ end
431
438
 
432
439
  coltypes = cols.map{|c| column_type(c)}
433
440
 
@@ -459,7 +466,7 @@ module SolveBio
459
466
  else
460
467
  # align headers and add headers
461
468
  minwidths =
462
- minwidths.zip(cols).map{|minw, c| [minw, c[0].send(width_fn)].max}
469
+ minwidths.zip(cols).map{|minw, c| [minw, c ? c[0].send(width_fn) : 0].max}
463
470
  headers =
464
471
  headers.zip(aligns, minwidths).map{|h, a, minw| align_header(h, a, minw)}
465
472
  end
@@ -471,9 +478,10 @@ module SolveBio
471
478
  # make sure values don't have newlines or tabs in them
472
479
  rows.each do |r|
473
480
  r.each_with_index do |c, i|
474
- r[i] = c.gsub("\n", '').gsub("\t", '')
481
+ r[i] = c.gsub("\n", '').gsub("\t", '').gsub("\r", '')
475
482
  end
476
483
  end
484
+
477
485
  return format_table(tablefmt, headers, rows, minwidths, aligns)
478
486
  end
479
487
  end
@@ -1,3 +1,3 @@
1
1
  module SolveBio
2
- VERSION = '1.7.2'
2
+ VERSION = '1.7.3'
3
3
  end
@@ -16,7 +16,7 @@ module SolveBio
16
16
  def test_query_tabulate
17
17
  old_verbose = $VERBOSE
18
18
  $VERBOSE=nil
19
- SolveBio::Tabulate.const_set(:TTY_COLS, 66)
19
+ ENV['COLUMNS'] = "66"
20
20
  $VERBOSE=old_verbose
21
21
  dataset = SolveBio::Dataset.retrieve(TEST_DATASET_NAME)
22
22
  results = dataset.query().filter(:hgnc_id => 2396)
@@ -61,7 +61,7 @@ module SolveBio
61
61
  def test_tabulate
62
62
  old_verbose = $VERBOSE
63
63
  $VERBOSE=nil
64
- SolveBio::Tabulate.const_set(:TTY_COLS, 80)
64
+ ENV['COLUMNS'] = "80"
65
65
  $VERBOSE=old_verbose
66
66
  tsv = simple_separated_format("\t")
67
67
  expected = <<-EOS
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solvebio
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.2
4
+ version: 1.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - SolveBio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-15 00:00:00.000000000 Z
11
+ date: 2014-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: netrc
@@ -140,6 +140,7 @@ files:
140
140
  - lib/solvebio/cli/credentials.rb
141
141
  - lib/solvebio/cli/irb.rb
142
142
  - lib/solvebio/cli/irbrc.rb
143
+ - lib/solvebio/cli/tutorial.md
143
144
  - lib/solvebio/cli/tutorial.rb
144
145
  - lib/solvebio/client.rb
145
146
  - lib/solvebio/dataset.rb