unipept 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5a71603248346c391236d3c403bef0ecd240399
4
- data.tar.gz: d8d91d4254c7c6b86be958cb0b10e2a4665c8b4f
3
+ metadata.gz: 7a8c0e99c89c6bc8304ff54fb44c0f432021f2db
4
+ data.tar.gz: 29e5c50c53cc1246212d9bf1e184ac0760c90739
5
5
  SHA512:
6
- metadata.gz: b6c359618d1603f0f871b93f24cfc6aa8c08d5f14010622749a2abce4b9e05b713ac865dd61074c3f607c931714f29684cdb7ab40fb1f2e30f40aca8e781506a
7
- data.tar.gz: 17b7aa1681f7dbec7068d5313d26e4c156b2a0311f67dd2b5abc22924ede1a0280cad6e9e07593cadacd844cbfe072ec7730b677e0baa61741dda44e3926c2ef
6
+ metadata.gz: 0be78a434a0758a1f12d991511d13f106e2fd7646a338f95c7699b0f79132e28f60a0b1da843ab0bff3d113fce23ac8ef9586b4cf053b23a3633036fd6ab3646
7
+ data.tar.gz: 205a9c2c8b6c2594bd26464f4f45201940fa5dd041ffc8f620aa08a3425c491bbe56c67cf8c61f5a90e8cd5e3138bb868f304c9b4b3e59ac74eb3589bc181dda
data/Rakefile CHANGED
@@ -24,7 +24,7 @@ Jeweler::Tasks.new do |gem|
24
24
  gem.authors = ["Toon Willems"]
25
25
  # dependencies defined in Gemfile
26
26
  gem.add_dependency 'faraday', '~> 0.9'
27
- gem.add_dependency 'cri', '~> 2.5'
27
+ gem.add_dependency 'cri', '~> 2.6'
28
28
  gem.add_dependency 'ruby-progressbar', '~> 1.4'
29
29
  end
30
30
  Jeweler::RubygemsDotOrgTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
data/bin/unipept CHANGED
@@ -12,6 +12,8 @@ require_relative '../lib/unipept'
12
12
 
13
13
  class ApiRunner < Cri::CommandRunner
14
14
 
15
+ attr_accessor :progress
16
+
15
17
  def initialize(args, opts, cmd)
16
18
  super
17
19
  host = Unipept::Configuration.new['host']
@@ -19,9 +21,14 @@ class ApiRunner < Cri::CommandRunner
19
21
  puts "WARNING: no host has been set, you can set the host with `unipept config host http://localhost:3000/`"
20
22
  exit 1
21
23
  end
24
+ if !host.start_with? "http://"
25
+ host = "http://#{host}"
26
+ end
27
+
22
28
  @url = "#{host}/api/v1/#{mapping[cmd.name]}.json"
23
29
  end
24
30
 
31
+
25
32
  def mapping
26
33
  {'pept2taxa' => 'single', 'pept2lca' => 'lca'}
27
34
  end
@@ -41,55 +48,78 @@ class ApiRunner < Cri::CommandRunner
41
48
  end
42
49
 
43
50
  def url_options(sub_part)
51
+ filter = options[:select] ? options[:select] : []
52
+ if filter.empty?
53
+ names = true
54
+ else
55
+ names = filter.any? {|f| /.*name.*/.match f}
56
+ end
44
57
  {:sequences => sub_part,
45
58
  :equate_il => options[:equate],
46
- :full_lineage => options[:lineage]}
59
+ :full_lineage => options[:lineage],
60
+ :names => names,
61
+ }
47
62
  end
48
63
 
49
64
  def run
50
65
  formatter = Unipept::Formatter.new_for_format(options[:format])
51
66
  peptides = read_input
52
67
 
53
- filter = options[:select] rescue nil
54
- filter = glob_to_regex(filter) if filter
55
-
56
- progress = ProgressBar.create(total: peptides.size, output: $stderr)
68
+ filter_list = options[:select] ? options[:select] : []
69
+ filter_list = filter_list.map {|f| glob_to_regex(f) }
70
+ output = STDOUT.tty? ? STDOUT : STDERR
71
+ self.progress = ProgressBar.create(total: peptides.size, output: output)
57
72
 
73
+ printed_header = false
58
74
  result = []
59
- peptides.each_slice(self.batch_size) do |sub_division|
60
75
 
76
+ peptides.each_slice(self.batch_size) do |sub_division|
61
77
  begin
62
78
  sub_result = JSON[Faraday.post(@url, url_options(sub_division)).body]
63
79
  rescue
64
- puts "API endpoint gave an error, exiting."
80
+ STDERR.puts "API endpoint gave an error, exiting."
65
81
  exit 1
66
82
  end
67
83
 
68
84
  sub_result = [sub_result] if not sub_result.kind_of? Array
69
85
 
70
- sub_result.map! {|r| r.select! {|k,v| filter.match k } } if filter
86
+ sub_result.map! {|r| r.select! {|k,v| filter_list.any? {|f| f.match k } } } if ! filter_list.empty?
71
87
 
72
88
  result << sub_result
73
89
 
90
+ if ! printed_header
91
+ write_to_output formatter.header(sub_result)
92
+ printed_header = true
93
+ end
94
+
95
+ write_to_output formatter.format(sub_result)
74
96
  progress.progress += sub_division.size
75
97
  end
76
98
 
77
99
  begin
78
100
  download_xml(result)
79
101
  rescue
80
- puts "Something went wrong while downloading xml information! please check the output"
102
+ STDERR.puts "Something went wrong while downloading xml information! please check the output"
81
103
  end
82
104
 
83
- result = formatter.format(result)
84
- if options[:output]
85
- File.open(options[:output], 'w') do |f|
86
- f.write result
105
+ end
106
+
107
+ def write_to_output(string)
108
+ if options[:output]
109
+ File.open(options[:output], 'a') do |f|
110
+ f.write string
111
+ end
112
+ else
113
+ if STDOUT.tty?
114
+ progress.log string
115
+ else
116
+ puts string
117
+ end
87
118
  end
88
- else
89
- puts result
90
- end
119
+
91
120
  end
92
121
 
122
+
93
123
  def download_xml(result)
94
124
  if options[:xml]
95
125
  File.open(options[:xml] + ".xml", "wb") do |f|
@@ -117,11 +147,9 @@ class Taxa2lca < ApiRunner
117
147
  end
118
148
 
119
149
  def batch_size
120
- 100000
150
+ Float::INFINITY
121
151
  end
122
152
 
123
-
124
-
125
153
  end
126
154
 
127
155
  class Pept2pro < ApiRunner
@@ -177,7 +205,7 @@ root_cmd.define_command('pept2taxa') do
177
205
  description 'Search Unipept for the given peptide and return taxons'
178
206
 
179
207
  flag :e, :equate, "equate I and L"
180
- option :s, :select, "select the attributes", :argument => :required
208
+ option :s, :select, "select the attributes", :argument => :required, :multiple => true
181
209
  option :l, :lineage, "Show full lineage"
182
210
  option :x, :xml, "Download taxonomy from NCBI as xml (specify output filename)", :argument => :required
183
211
 
@@ -191,7 +219,7 @@ root_cmd.define_command('pept2lca') do
191
219
  description 'Search Unipept for the given peptide and return the lowest common ancestor'
192
220
 
193
221
  flag :e, :equate, "equate I and L"
194
- option :s, :select, "select the attributes", :argument => :required
222
+ option :s, :select, "select the attributes", :argument => :required, :multiple => true
195
223
  option :l, :lineage, "Show full lineage"
196
224
 
197
225
  runner ApiRunner
@@ -203,7 +231,7 @@ root_cmd.define_command('taxa2lca') do
203
231
  summary 'Give lowest common ancestor for taxon ids'
204
232
  description 'Search Unipept for the given taxon ids and return the lowest common ancestor'
205
233
 
206
- option :s, :select, "select the attributes", :argument => :required
234
+ option :s, :select, "select the attributes", :argument => :required, :multiple => true
207
235
  option :l, :lineage, "Show full lineage"
208
236
 
209
237
  runner Taxa2lca
@@ -216,7 +244,7 @@ root_cmd.define_command('pept2pro') do
216
244
  description 'Search Unipept for the given peptides and return the lowest common ancestor'
217
245
 
218
246
  flag :e, :equate, "equate I and L"
219
- option :s, :select, "select the attributes", :argument => :required
247
+ option :s, :select, "select the attributes", :argument => :required, :multiple => true
220
248
  option :x, :xml, "download uniprot record in specified directory", :argument => :required
221
249
 
222
250
  runner Pept2pro
@@ -22,7 +22,11 @@ module Unipept
22
22
  end
23
23
 
24
24
  def self.default
25
- 'json'
25
+ 'csv'
26
+ end
27
+
28
+ def header(sample_data)
29
+ ""
26
30
  end
27
31
 
28
32
  # JSON formatted data goes in, something other comes out
@@ -45,14 +49,18 @@ module Unipept
45
49
 
46
50
  register :csv
47
51
 
48
- def format(data)
52
+ def header(data)
49
53
  CSV.generate do |csv|
50
54
  first = data.first
51
55
  if first.kind_of? Array
52
56
  first = first.first
53
57
  end
54
58
  csv << first.keys.map(&:to_s)
59
+ end
60
+ end
55
61
 
62
+ def format(data)
63
+ CSV.generate do |csv|
56
64
  data.each do |o|
57
65
  if o.kind_of? Array
58
66
  o.each {|h| csv << h.values }
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.1
4
+ version: 0.2.2
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-04-11 00:00:00.000000000 Z
11
+ date: 2014-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '2.5'
103
+ version: '2.6'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '2.5'
110
+ version: '2.6'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: ruby-progressbar
113
113
  requirement: !ruby/object:Gem::Requirement