unipept 0.2.10 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/bin/unipept +49 -17
  5. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ead8dcab7989d462a289d66dcde96b8fd190953
4
- data.tar.gz: 239fb70845d676a350a0c2ec0c0ba378c196a3d2
3
+ metadata.gz: e0cedbb475ea3469e5e59bed186772d043056252
4
+ data.tar.gz: bae15a7be7890c1c9331f4c12edc148db1273425
5
5
  SHA512:
6
- metadata.gz: 98489a9cc2ad823dd787f540e4b5810fb4f98215e5ef73c5ff7756991c7c6cb44d6491218942c115e4fce1e5f9ea809c4d5766d3b56fb1d6a13a987fe4d27448
7
- data.tar.gz: 30239e524d0d45121caee7c68a26eef59275eac3cc0c0890c6a66d6a28c6f240945d2c992a41e1bdb13f6e6f376feb68a5d47571cecd9864a82ccc4f95b520a0
6
+ metadata.gz: af89285b238a595f688964b2294db03db2cd9a8943c8677eda59e951108a692c28a2ed28136187c4d3fca87ee6624d228537c196e8c0faff397f9cb983ae2717
7
+ data.tar.gz: 845bf1890a13ce5e836690781c7dc32f59c0392e8620704734dc8edc13b03e98b3a1678d4b3ce0ff3a20f62e84d2a1d7908bf00035edc1f258dd03ae0bd51f90
data/Rakefile CHANGED
@@ -23,7 +23,7 @@ Jeweler::Tasks.new do |gem|
23
23
  gem.email = "willemstoon@gmail.com"
24
24
  gem.authors = ["Toon Willems"]
25
25
  # dependencies defined in Gemfile
26
- gem.add_dependency 'faraday', '~> 0.9'
26
+ gem.add_dependency 'typhoeus', '~> 0.6'
27
27
  gem.add_dependency 'cri', '~> 2.6'
28
28
  end
29
29
  Jeweler::RubygemsDotOrgTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.10
1
+ 0.3.0
data/bin/unipept CHANGED
@@ -1,7 +1,7 @@
1
1
  #!usr/bin/env ruby
2
2
 
3
3
  require 'cri'
4
- require 'faraday'
4
+ require 'typhoeus'
5
5
  require 'yaml'
6
6
  require 'json'
7
7
  require 'fileutils'
@@ -45,7 +45,7 @@ class ApiRunner < Cri::CommandRunner
45
45
  end
46
46
 
47
47
  def batch_size
48
- 10
48
+ 100
49
49
  end
50
50
 
51
51
  def url_options(sub_part)
@@ -73,32 +73,60 @@ class ApiRunner < Cri::CommandRunner
73
73
  printed_header = false
74
74
  result = []
75
75
 
76
+ hydra = Typhoeus::Hydra.new(max_concurrency: 20)
77
+ num_req = 0
78
+
76
79
  peptide_iterator(peptides) do |sub_division|
77
80
  if $interupted
78
81
  $stdin.close
79
82
  exit 1
80
83
  end
81
- begin
82
- sub_result = JSON[Faraday.post(@url, url_options(sub_division)).body]
83
- rescue
84
- STDERR.puts "API endpoint gave an error, exiting."
85
- exit 1
86
- end
87
84
 
88
- sub_result = [sub_result] if not sub_result.kind_of? Array
89
-
90
- sub_result.map! {|r| r.select! {|k,v| filter_list.any? {|f| f.match k } } } if ! filter_list.empty?
91
-
92
- result << sub_result
85
+ request = Typhoeus::Request.new(
86
+ @url,
87
+ method: :post,
88
+ body: url_options(sub_division)
89
+ )
90
+ request.on_complete do |resp|
91
+ if resp.timed_out?
92
+ $stderr.puts "request timed out, continuing anyway, but results might be incomplete"
93
+ else
94
+ if resp.success?
95
+ # if JSON parsing goes wrong
96
+ sub_result = JSON[resp.response_body] rescue []
97
+ sub_result = [sub_result] if not sub_result.kind_of? Array
98
+
99
+ sub_result.map! {|r| r.select! {|k,v| filter_list.any? {|f| f.match k } } } if ! filter_list.empty?
100
+
101
+ result << sub_result
102
+
103
+ if ! printed_header
104
+ write_to_output formatter.header(sub_result)
105
+ printed_header = true
106
+ end
107
+ write_to_output formatter.format(sub_result)
108
+ else
109
+ path = File.expand_path(File.join(Dir.home, "unipept.log"))
110
+ File.open(path, "w") do |f|
111
+ f.write resp.response_body
112
+ end
113
+ $stderr.puts "API request failed! log can be found in #{path}"
114
+ end
115
+ end
116
+ end
117
+ hydra.queue request
93
118
 
94
- if ! printed_header
95
- write_to_output formatter.header(sub_result)
96
- printed_header = true
119
+ num_req += 1
120
+ if num_req == 200
121
+ hydra.run
122
+ num_req = 0
97
123
  end
98
124
 
99
- write_to_output formatter.format(sub_result)
100
125
  end
101
126
 
127
+ hydra.run
128
+
129
+
102
130
  begin
103
131
  download_xml(result)
104
132
  rescue
@@ -179,6 +207,10 @@ class Pept2prot < ApiRunner
179
207
  end
180
208
  end
181
209
 
210
+ def batch_size
211
+ 10
212
+ end
213
+
182
214
  end
183
215
 
184
216
  root_cmd = Cri::Command.new_basic_root.modify do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unipept
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toon Willems
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-02 00:00:00.000000000 Z
11
+ date: 2014-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda
@@ -81,19 +81,19 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.8'
83
83
  - !ruby/object:Gem::Dependency
84
- name: faraday
84
+ name: typhoeus
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.9'
89
+ version: '0.6'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.9'
96
+ version: '0.6'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: cri
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  requirements: []
157
157
  rubyforge_project:
158
- rubygems_version: 2.2.0
158
+ rubygems_version: 2.2.2
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: CLI interface to unipept