unipept 2.1.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/ci.yml +6 -27
  4. data/.rakeTasks +7 -0
  5. data/.rubocop.yml +2 -0
  6. data/.ruby-version +1 -1
  7. data/CITATION.cff +30 -0
  8. data/Gemfile +2 -2
  9. data/Gemfile.lock +60 -41
  10. data/README.md +2 -2
  11. data/Rakefile +4 -4
  12. data/VERSION +1 -1
  13. data/lib/batch_iterator.rb +16 -0
  14. data/lib/commands/prot2pept.rb +1 -2
  15. data/lib/commands/unipept/api_runner.rb +10 -12
  16. data/lib/commands/unipept/config.rb +1 -1
  17. data/lib/commands/unipept/pept2taxa.rb +1 -5
  18. data/lib/commands/unipept/taxa2tree.rb +74 -0
  19. data/lib/commands/unipept.rb +25 -1
  20. data/lib/commands/uniprot.rb +4 -5
  21. data/lib/configuration.rb +6 -7
  22. data/lib/formatters.rb +108 -36
  23. data/lib/server_message.rb +2 -4
  24. data/test/commands/unipept/test_api_runner.rb +8 -7
  25. data/test/commands/unipept/test_config.rb +1 -1
  26. data/test/commands/unipept/test_pept2ec.rb +11 -11
  27. data/test/commands/unipept/test_pept2funct.rb +15 -15
  28. data/test/commands/unipept/test_pept2go.rb +10 -10
  29. data/test/commands/unipept/test_pept2interpro.rb +26 -26
  30. data/test/commands/unipept/test_pept2lca.rb +2 -2
  31. data/test/commands/unipept/test_pept2prot.rb +2 -2
  32. data/test/commands/unipept/test_pept2taxa.rb +2 -4
  33. data/test/commands/unipept/test_peptinfo.rb +16 -16
  34. data/test/commands/unipept/test_taxa2lca.rb +2 -2
  35. data/test/commands/unipept/test_taxa2tree.rb +68 -0
  36. data/test/commands/unipept/test_taxonomy.rb +2 -2
  37. data/test/helper.rb +10 -0
  38. data/test/support/api_stub.rb +60 -0
  39. data/test/support/resources/pept2ec.json +55 -0
  40. data/test/support/resources/pept2funct.json +73 -0
  41. data/test/support/resources/pept2go.json +43 -0
  42. data/test/support/resources/pept2interpro.json +43 -0
  43. data/test/support/resources/pept2lca.json +14 -0
  44. data/test/support/resources/pept2prot.json +422 -0
  45. data/test/support/resources/pept2taxa.json +194 -0
  46. data/test/support/resources/peptinfo.json +70 -0
  47. data/test/support/resources/taxa2tree.json +194 -0
  48. data/test/support/resources/taxonomy.json +22 -0
  49. data/test/test_configuration.rb +1 -1
  50. data/test/test_formatters.rb +5 -5
  51. data/test/test_output_writer.rb +1 -1
  52. data/test/test_server_message.rb +2 -2
  53. data/test.taxa +4 -0
  54. data/unipept.gemspec +32 -21
  55. metadata +26 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d025bbebf7189fd0afe9cc8cd945f8ec2f14c231a3081f0e24284dc2997d988
4
- data.tar.gz: 889ea0bbd83199ec503a7736a21d5e216e054af1a691603c413958ee1c5efab1
3
+ metadata.gz: b8f3ce5867e19149483ab70e24d4cc5da97d8ba9e62e38491b714abc89078ee0
4
+ data.tar.gz: '09cfcdbc3608ee36a75825e7f7555add797b002e3abccc5caada703efc8d0b86'
5
5
  SHA512:
6
- metadata.gz: 7394e17376d8e22f57d07046b2a0930a133717b44c3ceeaf50c61ef05011d711ea36a88e0212b8dde1c6efefce5b7d4e9fd4d7461363b8aea83e24bbaea214d8
7
- data.tar.gz: 470253cdb07286db4f9e9d37f0323a64f4f9726d007d7b4a8dc73fdc171335ec6e50d91505e94c533b11fb141ec6ccaff4f6437d41d8997108e0ed9df3a537bf
6
+ metadata.gz: e29aa64adf5a502377c2fdedb63969d29fa6f8d517262d65ec0a99b40746bf0a1d3d5a26552dd25cd425008d0f8a0f4ed7bd69ec6786d77ef2c688ce0e5b7c5d
7
+ data.tar.gz: 9d6d08532a96fb85423a7843745df5fe75f125e6f7119f6ba2b76f525b75bd057aac7d27a0a5c1e6357df5aed0af42bb00a9fd260aa3be58f623dc75dc3da7b4
@@ -0,0 +1,9 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: monthly
7
+ time: "13:00"
8
+ timezone: Europe/Brussels
9
+ open-pull-requests-limit: 99
@@ -7,27 +7,16 @@ jobs:
7
7
  runs-on: ubuntu-latest
8
8
  strategy:
9
9
  matrix:
10
- ruby: ["2.4", "2.5", "2.6"]
10
+ ruby: ["2.7", "3.0", "3.1"]
11
11
  fail-fast: false
12
12
  name: Test Ruby ${{ matrix.ruby }}
13
13
  steps:
14
14
  - uses: actions/checkout@v1
15
15
  - name: Setup Ruby
16
- uses: actions/setup-ruby@v1
16
+ uses: ruby/setup-ruby@v1
17
17
  with:
18
18
  ruby-version: ${{ matrix.ruby }}
19
- - name: Cache Ruby dependencies
20
- uses: actions/cache@v1
21
- with:
22
- path: vendor/bundle
23
- key: ${{ runner.os }}-${{ matrix.ruby }}-gem-${{ hashFiles('**/Gemfile.lock') }}
24
- restore-keys: |
25
- ${{ runner.os }}-${{ matrix.ruby }}-gem-
26
- - name: Install dependencies
27
- run: |
28
- gem install bundler:1.17.2
29
- bundle config path vendor/bundle
30
- bundle install --jobs 4 --retry 3
19
+ bundler-cache: true
31
20
  - name: Test
32
21
  run: |
33
22
  bundle exec rake test
@@ -37,19 +26,9 @@ jobs:
37
26
  steps:
38
27
  - uses: actions/checkout@v1
39
28
  - name: Setup Ruby
40
- uses: actions/setup-ruby@v1
41
- - name: Cache Ruby dependencies
42
- uses: actions/cache@v1
29
+ uses: ruby/setup-ruby@v1
43
30
  with:
44
- path: vendor/bundle
45
- key: ${{ runner.os }}-${{ matrix.ruby }}-gem-${{ hashFiles('**/Gemfile.lock') }}
46
- restore-keys: |
47
- ${{ runner.os }}-${{ matrix.ruby }}-gem-
48
- - name: Install dependencies
49
- run: |
50
- gem install bundler:1.17.2
51
- bundle config path vendor/bundle
52
- bundle install --jobs 4 --retry 3
31
+ bundler-cache: true
53
32
  - name: Test
54
33
  run: |
55
- bundle exec rake test_style
34
+ bundle exec rake test_style
data/.rakeTasks ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build gem into pkg/" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Remove RDoc HTML files" fullCmd="clobber_rdoc" taksId="clobber_rdoc" /><RakeTask description="Start IRB with all runtime dependencies loaded" fullCmd="console[script]" taksId="console[script]" /><RakeGroup description="" fullCmd="" taksId="gemcutter"><RakeTask description="Release gem to Gemcutter" fullCmd="gemcutter:release" taksId="release" /></RakeGroup><RakeTask description="Generate and validate gemspec" fullCmd="gemspec" taksId="gemspec" /><RakeGroup description="" fullCmd="" taksId="gemspec"><RakeTask description="Display the gemspec for debugging purposes, as juwelier knows it (not from the filesystem)" fullCmd="gemspec:debug" taksId="debug" /><RakeTask description="Regenerate the gemspec on the filesystem" fullCmd="gemspec:generate" taksId="generate" /><RakeTask description="Regenerate and validate gemspec, and then commits and pushes to git" fullCmd="gemspec:release" taksId="release" /><RakeTask description="Validates the gemspec on the filesystem" fullCmd="gemspec:validate" taksId="validate" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="git"><RakeTask description="Tag and push release to git" fullCmd="git:release" taksId="release" /></RakeGroup><RakeTask description="Build and install gem using `gem install`" fullCmd="install" taksId="install" /><RakeTask description="Build RDoc HTML files" fullCmd="rdoc" taksId="rdoc" /><RakeTask description="Release gem" fullCmd="release" taksId="release" /><RakeTask description="Rebuild RDoc HTML files" fullCmd="rerdoc" taksId="rerdoc" /><RakeTask description="Run RuboCop" fullCmd="test_style" taksId="test_style" /><RakeGroup description="" fullCmd="" taksId="test_style"><RakeTask description="Auto-correct RuboCop offenses" fullCmd="test_style:auto_correct" taksId="auto_correct" /></RakeGroup><RakeTask description="Displays the current version" fullCmd="version" taksId="version" /><RakeGroup description="" fullCmd="" taksId="version"><RakeGroup description="" fullCmd="" taksId="bump"><RakeTask description="Bump the major version by 1" fullCmd="version:bump:major" taksId="major" /><RakeTask description="Bump the a minor version by 1" fullCmd="version:bump:minor" taksId="minor" /><RakeTask description="Bump the patch version by 1" fullCmd="version:bump:patch" taksId="patch" /></RakeGroup><RakeTask description="Writes out an explicit version" fullCmd="version:write" taksId="write" /></RakeGroup><RakeTask description="" fullCmd="console" taksId="console" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="gemspec_required" taksId="gemspec_required" /><RakeTask description="" fullCmd="rdoc/created.rid" taksId="rdoc/created.rid" /><RakeTask description="" fullCmd="test" taksId="test" /><RakeTask description="" fullCmd="test_unit" taksId="test_unit" /><RakeTask description="" fullCmd="version_required" taksId="version_required" /></RakeGroup></Settings>
data/.rubocop.yml CHANGED
@@ -1,4 +1,6 @@
1
1
  AllCops:
2
+ TargetRubyVersion: 2.7
3
+ NewCops: enable
2
4
  Exclude:
3
5
  - 'unipept.gemspec'
4
6
  - 'vendor/**/*'
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.6
1
+ 3.0.0
data/CITATION.cff ADDED
@@ -0,0 +1,30 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use this software, please cite it as below."
3
+ preferred-citation:
4
+ type: article
5
+ authors:
6
+ - family-names: "Verschaffelt"
7
+ given-names: "Pieter"
8
+ - family-names: "Van Thienen"
9
+ given-names: "Philippe"
10
+ - family-names: "Van Den Bossche"
11
+ given-names: "Tim"
12
+ - family-names: "Van der Jeugt"
13
+ given-names: "Felix"
14
+ - family-names: "De Tender"
15
+ given-names: "Caroline"
16
+ - family-names: "Martens"
17
+ given-names: "Lennart"
18
+ - family-names: "Dawyndt"
19
+ given-names: "Peter"
20
+ - family-names: "Mesuere"
21
+ given-names: "Bart"
22
+ orcid: "https://orcid.org/0000-0003-0610-3441"
23
+ doi: "10.1093/bioinformatics/btaa553"
24
+ journal: "Bioinformatics"
25
+ start: 4220
26
+ end: 4221
27
+ title: "Unipept CLI 2.0: adding support for visualizations and functional annotations"
28
+ issue: 14
29
+ volume: 36
30
+ year: 2020
data/Gemfile CHANGED
@@ -7,9 +7,9 @@ gem 'typhoeus', '~> 1.3.1'
7
7
  group :development do
8
8
  gem 'minitest', '~> 5.14'
9
9
  gem 'rake', '~> 13.0.1'
10
- gem 'rubocop', '~>0.79.0'
10
+ gem 'rubocop', '~>1.11'
11
11
  end
12
12
 
13
13
  group :release do
14
- gem 'jeweler'
14
+ gem 'juwelier'
15
15
  end
data/Gemfile.lock CHANGED
@@ -1,85 +1,104 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- addressable (2.4.0)
5
- ast (2.4.0)
4
+ addressable (2.8.0)
5
+ public_suffix (>= 2.0.2, < 5.0)
6
+ ast (2.4.2)
6
7
  builder (3.2.4)
7
- cri (2.15.10)
8
+ cri (2.15.11)
8
9
  descendants_tracker (0.0.4)
9
10
  thread_safe (~> 0.3, >= 0.3.1)
10
11
  ethon (0.12.0)
11
12
  ffi (>= 1.3.0)
12
- faraday (0.9.2)
13
+ faraday (1.3.0)
14
+ faraday-net_http (~> 1.0)
13
15
  multipart-post (>= 1.2, < 3)
16
+ ruby2_keywords
17
+ faraday-net_http (1.0.1)
14
18
  ffi (1.12.1)
15
- git (1.5.0)
16
- github_api (0.16.0)
17
- addressable (~> 2.4.0)
19
+ git (1.8.1)
20
+ rchardet (~> 1.8)
21
+ github_api (0.19.0)
22
+ addressable (~> 2.4)
18
23
  descendants_tracker (~> 0.0.4)
19
- faraday (~> 0.8, < 0.10)
20
- hashie (>= 3.4)
21
- mime-types (>= 1.16, < 3.0)
24
+ faraday (>= 0.8, < 2)
25
+ hashie (~> 3.5, >= 3.5.2)
22
26
  oauth2 (~> 1.0)
23
- hashie (4.0.0)
27
+ hashie (3.6.0)
24
28
  highline (2.0.3)
25
- jaro_winkler (1.5.4)
26
- jeweler (2.3.9)
29
+ juwelier (2.4.9)
27
30
  builder
28
31
  bundler
29
- git (>= 1.2.5)
30
- github_api (~> 0.16.0)
31
- highline (>= 1.6.15)
32
- nokogiri (>= 1.5.10)
32
+ git
33
+ github_api
34
+ highline
35
+ kamelcase (~> 0)
36
+ nokogiri
33
37
  psych
34
38
  rake
35
39
  rdoc
36
40
  semver2
37
- jwt (2.2.1)
38
- mime-types (2.99.3)
39
- mini_portile2 (2.4.0)
40
- minitest (5.14.0)
41
- multi_json (1.14.1)
41
+ jwt (2.2.2)
42
+ kamelcase (0.0.2)
43
+ semver2 (~> 3)
44
+ mini_portile2 (2.8.0)
45
+ minitest (5.15.0)
46
+ multi_json (1.15.0)
42
47
  multi_xml (0.6.0)
43
48
  multipart-post (2.1.1)
44
- nokogiri (1.10.7)
45
- mini_portile2 (~> 2.4.0)
46
- oauth2 (1.4.2)
49
+ nokogiri (1.13.4)
50
+ mini_portile2 (~> 2.8.0)
51
+ racc (~> 1.4)
52
+ oauth2 (1.4.4)
47
53
  faraday (>= 0.8, < 2.0)
48
54
  jwt (>= 1.0, < 3.0)
49
55
  multi_json (~> 1.3)
50
56
  multi_xml (~> 0.5)
51
57
  rack (>= 1.2, < 3)
52
- parallel (1.19.1)
53
- parser (2.7.0.2)
54
- ast (~> 2.4.0)
55
- psych (3.1.0)
56
- rack (2.1.1)
57
- rainbow (3.0.0)
58
- rake (13.0.1)
59
- rdoc (6.2.1)
60
- rubocop (0.79.0)
61
- jaro_winkler (~> 1.5.1)
58
+ parallel (1.22.1)
59
+ parser (3.1.1.0)
60
+ ast (~> 2.4.1)
61
+ psych (4.0.3)
62
+ stringio
63
+ public_suffix (4.0.6)
64
+ racc (1.6.0)
65
+ rack (2.2.3)
66
+ rainbow (3.1.1)
67
+ rake (13.0.6)
68
+ rchardet (1.8.0)
69
+ rdoc (6.4.0)
70
+ psych (>= 4.0.0)
71
+ regexp_parser (2.3.0)
72
+ rexml (3.2.5)
73
+ rubocop (1.27.0)
62
74
  parallel (~> 1.10)
63
- parser (>= 2.7.0.1)
75
+ parser (>= 3.1.0.0)
64
76
  rainbow (>= 2.2.2, < 4.0)
77
+ regexp_parser (>= 1.8, < 3.0)
78
+ rexml
79
+ rubocop-ast (>= 1.16.0, < 2.0)
65
80
  ruby-progressbar (~> 1.7)
66
- unicode-display_width (>= 1.4.0, < 1.7)
67
- ruby-progressbar (1.10.1)
81
+ unicode-display_width (>= 1.4.0, < 3.0)
82
+ rubocop-ast (1.17.0)
83
+ parser (>= 3.1.1.0)
84
+ ruby-progressbar (1.11.0)
85
+ ruby2_keywords (0.0.4)
68
86
  semver2 (3.4.2)
87
+ stringio (3.0.1)
69
88
  thread_safe (0.3.6)
70
89
  typhoeus (1.3.1)
71
90
  ethon (>= 0.9.0)
72
- unicode-display_width (1.6.1)
91
+ unicode-display_width (2.1.0)
73
92
 
74
93
  PLATFORMS
75
94
  ruby
76
95
 
77
96
  DEPENDENCIES
78
97
  cri (~> 2.15.10)
79
- jeweler
98
+ juwelier
80
99
  minitest (~> 5.14)
81
100
  rake (~> 13.0.1)
82
- rubocop (~> 0.79.0)
101
+ rubocop (~> 1.11)
83
102
  typhoeus (~> 1.3.1)
84
103
 
85
104
  BUNDLED WITH
data/README.md CHANGED
@@ -7,11 +7,11 @@ Documentation about the web service can be found at [http://unipept.ugent.be/api
7
7
 
8
8
  ## Installation
9
9
 
10
- To use the Unipept CLI, Ruby version 1.9.3 or higher needs to be installed. You can check this by running `ruby -v` on the commandline:
10
+ To use the Unipept CLI, Ruby version 2.6 or higher needs to be installed. You can check this by running `ruby -v` on the commandline:
11
11
 
12
12
  ```
13
13
  $ ruby -v
14
- ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
14
+ ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [arm64-darwin21]
15
15
  ```
16
16
 
17
17
  More information on installing Ruby can be found at https://www.ruby-lang.org/en/installation/
data/Rakefile CHANGED
@@ -11,8 +11,8 @@ require 'rake'
11
11
  require 'rake/testtask'
12
12
  require 'rubocop/rake_task'
13
13
  begin
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
14
+ require 'juwelier'
15
+ Juwelier::Tasks.new do |gem|
16
16
  # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
17
  gem.name = 'unipept'
18
18
  gem.executables = %w[unipept prot2pept peptfilter uniprot]
@@ -26,9 +26,9 @@ begin
26
26
  EOS
27
27
  gem.email = 'unipept@ugent.be'
28
28
  gem.authors = ['Bart Mesuere', 'Pieter Verschaffelt', 'Toon Willems', 'Tom Naessens']
29
- gem.required_ruby_version = '>= 2.0.0'
29
+ gem.required_ruby_version = '>= 2.6.0'
30
30
  end
31
- Jeweler::RubygemsDotOrgTasks.new
31
+ Juwelier::RubygemsDotOrgTasks.new
32
32
  rescue LoadError
33
33
  # do nothing
34
34
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.1
1
+ 2.2.2
@@ -20,6 +20,8 @@ module Unipept
20
20
  first_line = lines.next rescue return
21
21
  if fasta? first_line
22
22
  fasta_iterator(first_line, lines, &block)
23
+ elsif csv_taxa2tree? first_line
24
+ csv_taxa_iterator(first_line, lines, &block)
23
25
  else
24
26
  normal_iterator(first_line, lines, &block)
25
27
  end
@@ -34,6 +36,10 @@ module Unipept
34
36
  line.start_with? '>'
35
37
  end
36
38
 
39
+ def csv_taxa2tree?(line)
40
+ line.include? 'taxon_id'
41
+ end
42
+
37
43
  private
38
44
 
39
45
  # Splits the input lines in fasta format into slices, based on the
@@ -69,5 +75,15 @@ module Unipept
69
75
  end
70
76
  end.each_slice(batch_size).with_index(&block)
71
77
  end
78
+
79
+ def csv_taxa_iterator(first_line, next_lines, &block)
80
+ # Find index of taxon_id in the first_line and only parse this part from the next lines
81
+ taxon_idx = first_line.rstrip.split(',').find_index('taxon_id')
82
+ Enumerator.new do |y|
83
+ loop do
84
+ y << next_lines.next.rstrip.split(',')[taxon_idx]
85
+ end
86
+ end.each_slice(batch_size).with_index(&block)
87
+ end
72
88
  end
73
89
  end
@@ -1,7 +1,6 @@
1
1
  module Unipept::Commands
2
2
  class Prot2pept
3
- attr_reader :root_command
4
- attr_reader :valid_formats
3
+ attr_reader :root_command, :valid_formats
5
4
 
6
5
  @root_command = Cri::Command.define do
7
6
  name 'prot2pept'
@@ -2,18 +2,14 @@ require_relative '../../retryable_typhoeus'
2
2
 
3
3
  module Unipept
4
4
  class Commands::ApiRunner < Cri::CommandRunner
5
- attr_reader :configuration
6
-
7
- attr_reader :url
8
-
9
- attr_reader :user_agent
5
+ attr_reader :configuration, :url, :user_agent
10
6
 
11
7
  def initialize(args, opts, cmd)
12
8
  super
13
9
  @configuration = Unipept::Configuration.new
14
10
 
15
11
  @host = host
16
- @user_agent = 'Unipept CLI - unipept ' + Unipept::VERSION
12
+ @user_agent = "Unipept CLI - unipept #{Unipept::VERSION}"
17
13
  @url = "#{@host}/api/v1/#{cmd.name}.json"
18
14
  @fasta = false
19
15
  end
@@ -39,7 +35,7 @@ module Unipept
39
35
  # - if none of the previous are given, uses stdin
40
36
  def input_iterator
41
37
  return arguments.each unless arguments.empty?
42
- return IO.foreach(options[:input]) if options[:input]
38
+ return File.foreach(options[:input]) if options[:input]
43
39
 
44
40
  $stdin.each_line
45
41
  end
@@ -115,6 +111,8 @@ module Unipept
115
111
  batch_order = Unipept::BatchOrder.new
116
112
  last_id = 0
117
113
 
114
+ # puts input_iterator.inspect
115
+
118
116
  batch_iterator.iterate(input_iterator) do |input_slice, batch_id, fasta_mapper|
119
117
  last_id = batch_id
120
118
  @fasta = !fasta_mapper.nil?
@@ -146,11 +144,11 @@ module Unipept
146
144
  def save_error(message)
147
145
  path = error_file_path
148
146
  FileUtils.mkdir_p File.dirname(path)
149
- File.open(path, 'w') { |f| f.write message }
147
+ File.write(path, message)
150
148
  warn "API request failed! log can be found in #{path}"
151
149
  end
152
150
 
153
- private
151
+ protected
154
152
 
155
153
  def error_file_path
156
154
  File.expand_path(File.join(Dir.home, '.unipept', "unipept-#{Time.now.strftime('%F-%T')}.log"))
@@ -171,7 +169,7 @@ module Unipept
171
169
 
172
170
  lambda do
173
171
  unless result.empty?
174
- output_writer.write_line formatter.header(result, fasta_mapper) if batch_id.zero? && !options[:"no-header"]
172
+ output_writer.write_line formatter.header(result, fasta_mapper) if batch_id.zero? && !options[:'no-header']
175
173
  output_writer.write_line formatter.format(result, fasta_mapper, batch_id.zero?)
176
174
  end
177
175
  end
@@ -181,7 +179,7 @@ module Unipept
181
179
  if response.timed_out?
182
180
  -> { save_error('request timed out, continuing anyway, but results might be incomplete') }
183
181
  elsif response.code.zero?
184
- -> { save_error('could not get an http response, continuing anyway, but results might be incomplete' + response.return_message) }
182
+ -> { save_error("could not get an http response, continuing anyway, but results might be incomplete#{response.return_message}") }
185
183
  else
186
184
  -> { save_error("Got #{response.code}: #{response.response_body}\nRequest headers: #{response.request.options}\nRequest body:\n#{response.request.encoded_body}\n\n") }
187
185
  end
@@ -210,7 +208,7 @@ module Unipept
210
208
  if %w[ec go ipr].include? k
211
209
  v.each do |item|
212
210
  item.each do |field_name, field_value|
213
- new_field_name = %w[ec_number go_term ipr_code].include?(field_name) ? field_name : k + '_' + field_name
211
+ new_field_name = %w[ec_number go_term ipr_code].include?(field_name) ? field_name : "#{k}_#{field_name}"
214
212
  output_row[new_field_name] = [] unless output_row.key? new_field_name
215
213
  output_row[new_field_name] << field_value
216
214
  end
@@ -7,7 +7,7 @@ module Unipept
7
7
 
8
8
  if arguments.size == 2
9
9
  set_config(key, value)
10
- puts key + ' was set to ' + value
10
+ puts "#{key} was set to #{value}"
11
11
  else
12
12
  puts get_config(key)
13
13
  end
@@ -6,11 +6,7 @@ module Unipept::Commands
6
6
  end
7
7
 
8
8
  def default_batch_size
9
- if options[:all]
10
- 5
11
- else
12
- 10
13
- end
9
+ 5
14
10
  end
15
11
  end
16
12
  end
@@ -0,0 +1,74 @@
1
+ require_relative 'api_runner'
2
+ module Unipept::Commands
3
+ class Taxa2Tree < ApiRunner
4
+ def initialize(args, opts, cmd)
5
+ super
6
+
7
+ # JSON is the default format for this command
8
+ args[:format] = 'json' unless args[:format]
9
+
10
+ unless %w[url html json].include? args[:format]
11
+ warn "Format #{args[:format]} is not supported by taxa2tree. Use html, url or json (default)."
12
+ exit 1
13
+ end
14
+
15
+ if options[:format] == 'html'
16
+ # Overwrite the URL for this command, since it's possible that it uses HTML generated by the server.
17
+ @url = "#{@host}/api/v1/#{cmd.name}.html"
18
+ elsif args[:format] == 'url'
19
+ @link = true
20
+ end
21
+ end
22
+
23
+ def required_fields
24
+ ['taxon_id']
25
+ end
26
+
27
+ def batch_size
28
+ return arguments.length unless arguments.empty?
29
+ return File.foreach(options[:input]).inject(0) { |c, _| c + 1 } if options[:input]
30
+
31
+ @stdin_contents = $stdin.readlines
32
+ @stdin_contents.length
33
+ end
34
+
35
+ def input_iterator
36
+ return arguments.each unless arguments.empty?
37
+ return File.foreach(options[:input]) if options[:input]
38
+
39
+ @stdin_contents.each
40
+ end
41
+
42
+ protected
43
+
44
+ def filter_result(response)
45
+ return response if response.start_with?('<!DOCTYPE')
46
+
47
+ # We do not filter here, since select is not supported by the taxa2tree-command
48
+ [JSON[response]] rescue []
49
+ end
50
+
51
+ def construct_request_body(input)
52
+ data = nil
53
+
54
+ if input[0].include?(',')
55
+ data = input.map do |item|
56
+ splitted = item.rstrip.split ','
57
+ splitted[1] = splitted[1].to_i
58
+ splitted
59
+ end
60
+ data = data.to_h
61
+ else
62
+ data = Hash.new 0
63
+ input.each do |i|
64
+ data[i.rstrip] += 1
65
+ end
66
+ end
67
+
68
+ {
69
+ counts: data,
70
+ link: @link
71
+ }
72
+ end
73
+ end
74
+ end
@@ -19,6 +19,7 @@ require_relative 'unipept/pept2taxa'
19
19
  require_relative 'unipept/peptinfo'
20
20
  require_relative 'unipept/taxa2lca'
21
21
  require_relative 'unipept/taxonomy'
22
+ require_relative 'unipept/taxa2tree'
22
23
 
23
24
  module Unipept
24
25
  class Commands::Unipept
@@ -35,6 +36,7 @@ module Unipept
35
36
  add_taxa2lca_command
36
37
  add_pept2prot_command
37
38
  add_taxonomy_command
39
+ add_taxa2tree_command
38
40
  end
39
41
 
40
42
  def run(args)
@@ -66,7 +68,7 @@ module Unipept
66
68
  option nil, :batch, 'specify the batch size', argument: :required, hidden: true
67
69
  option nil, :parallel, 'specify the number of parallel requests', argument: :required, hidden: true
68
70
  option :o, :output, 'write output to file', argument: :required
69
- option :f, :format, "define the output format (available: #{Unipept::Formatter.available.join ', '}) (default: #{Unipept::Formatter.default})", argument: :required
71
+ option :f, :format, "define the output format (available: #{Unipept::Formatter.available.select { |f| f != 'html' && f != 'url' }.join(', ')}) (default: #{Unipept::Formatter.default}).", argument: :required
70
72
 
71
73
  # Configuration options
72
74
  option nil, 'host', 'specify the server running the Unipept web service', argument: :required
@@ -292,6 +294,28 @@ module Unipept
292
294
  end
293
295
  end
294
296
 
297
+ def add_taxa2tree_command
298
+ @root_command.define_command('taxa2tree') do
299
+ usage 'taxa2tree [options]'
300
+ summary 'Compute lineage tree for given list of taxa'
301
+ description <<-EOS
302
+ The unipept taxa2tree command computes a lineage tree of a given list of NCBI Taxonomy Identifiers. A frequency table is computed for the given list of taxa. Secondly, the lineages for all taxa are looked up. These are then used to build a lineage tree with all counts set. The command expects a list of NCBI Taxonomy Identifiers that are passed
303
+
304
+ - as separate command line arguments
305
+
306
+ - in a text file that is passed as an argument to the -i option
307
+
308
+ - to standard input
309
+
310
+ The command will give priority to the first way NCBI Taxonomy Identifiers are passed, in the order as listed above. Text files and standard input should have one NCBI Taxonomy Identifier per line.
311
+ EOS
312
+
313
+ option :f, :format, "define the output format (available: json, url, html) (default: 'json'). Note that xml and csv are not available for taxa2tree. html and url are used as an output format for visualizations.", argument: :required
314
+
315
+ runner Commands::Taxa2Tree
316
+ end
317
+ end
318
+
295
319
  def add_pept2prot_command
296
320
  @root_command.define_command('pept2prot') do
297
321
  usage 'pept2prot [options]'
@@ -2,8 +2,7 @@ require 'typhoeus'
2
2
 
3
3
  module Unipept::Commands
4
4
  class Uniprot
5
- attr_reader :root_command
6
- attr_reader :valid_formats
5
+ attr_reader :root_command, :valid_formats
7
6
 
8
7
  valid_formats = Set.new %w[fasta txt xml rdf gff sequence]
9
8
  @root_command = Cri::Command.define do
@@ -21,7 +20,7 @@ module Unipept::Commands
21
20
 
22
21
  The uniprot command yields just the protein sequences as a default, but can return several formats.
23
22
  EOS
24
- required :f, :format, 'specify output format (available: ' + valid_formats.to_a.join(', ') + ') (default: sequence)'
23
+ required :f, :format, "specify output format (available: #{valid_formats.to_a.join(', ')}) (default: sequence)"
25
24
  flag :h, :help, 'show help for this command' do |_value, cmd|
26
25
  puts cmd.help
27
26
  exit 0
@@ -29,7 +28,7 @@ module Unipept::Commands
29
28
  run do |opts, args, _cmd|
30
29
  format = opts.fetch(:format, 'sequence')
31
30
  unless valid_formats.include? format
32
- warn format + ' is not a valid output format. Available formats are: ' + valid_formats.to_a.join(', ')
31
+ warn "#{format} is not a valid output format. Available formats are: #{valid_formats.to_a.join(', ')}"
33
32
  exit 1
34
33
  end
35
34
  iterator = args.empty? ? $stdin.each_line : args
@@ -58,7 +57,7 @@ module Unipept::Commands
58
57
  # @return [String] The requested UniProt entry in the requested format
59
58
  def self.get_uniprot_entry(accession, format)
60
59
  if format == 'sequence'
61
- get_uniprot_entry(accession, 'fasta').lines.map(&:chomp)[1..-1].join('')
60
+ get_uniprot_entry(accession, 'fasta').lines.map(&:chomp)[1..].join
62
61
  else
63
62
  # other format has been specified, just download and output
64
63
  resp = Typhoeus.get("https://www.uniprot.org/uniprot/#{accession}.#{format}")