unipept 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +26 -0
  3. data/.travis.yml +7 -0
  4. data/Gemfile +8 -10
  5. data/Gemfile.lock +35 -21
  6. data/README.md +6 -4
  7. data/Rakefile +11 -10
  8. data/VERSION +1 -1
  9. data/bin/peptfilter +2 -44
  10. data/bin/prot2pept +4 -49
  11. data/bin/unipept +2 -197
  12. data/bin/uniprot +4 -53
  13. data/lib/batch_iterator.rb +73 -0
  14. data/lib/batch_order.rb +20 -0
  15. data/lib/commands/peptfilter.rb +118 -0
  16. data/lib/commands/prot2pept.rb +61 -0
  17. data/lib/commands/unipept/api_runner.rb +199 -0
  18. data/lib/commands/unipept/config.rb +29 -0
  19. data/lib/commands/unipept/pept2lca.rb +12 -0
  20. data/lib/commands/unipept/pept2prot.rb +13 -0
  21. data/lib/{unipept/commands → commands/unipept}/pept2taxa.rb +7 -0
  22. data/lib/commands/unipept/taxa2lca.rb +18 -0
  23. data/lib/{unipept/commands → commands/unipept}/taxonomy.rb +3 -0
  24. data/lib/commands/unipept.rb +226 -0
  25. data/lib/commands/uniprot.rb +69 -0
  26. data/lib/commands.rb +10 -0
  27. data/lib/configuration.rb +45 -0
  28. data/lib/formatters.rb +252 -0
  29. data/lib/version.rb +3 -0
  30. data/test/commands/test_peptfilter.rb +170 -0
  31. data/test/commands/test_prot2pept.rb +82 -0
  32. data/test/commands/test_unipept.rb +37 -0
  33. data/test/commands/test_uniprot.rb +136 -0
  34. data/test/commands/unipept/test_api_runner.rb +486 -0
  35. data/test/commands/unipept/test_config.rb +64 -0
  36. data/test/commands/unipept/test_pept2lca.rb +40 -0
  37. data/test/commands/unipept/test_pept2prot.rb +39 -0
  38. data/test/commands/unipept/test_pept2taxa.rb +39 -0
  39. data/test/commands/unipept/test_taxa2lca.rb +39 -0
  40. data/test/commands/unipept/test_taxonomy.rb +37 -0
  41. data/test/helper.rb +69 -23
  42. data/test/test_bach_order.rb +57 -0
  43. data/test/test_base.rb +6 -0
  44. data/test/test_batch_iterator.rb +87 -0
  45. data/test/test_configuration.rb +43 -0
  46. data/test/test_formatters.rb +140 -0
  47. data/unipept.gemspec +55 -33
  48. metadata +62 -40
  49. data/lib/unipept/batch_order.rb +0 -28
  50. data/lib/unipept/commands/api_runner.rb +0 -239
  51. data/lib/unipept/commands/pept2lca.rb +0 -6
  52. data/lib/unipept/commands/pept2prot.rb +0 -20
  53. data/lib/unipept/commands/taxa2lca.rb +0 -12
  54. data/lib/unipept/commands.rb +0 -7
  55. data/lib/unipept/configuration.rb +0 -29
  56. data/lib/unipept/formatters.rb +0 -135
  57. data/lib/unipept/version.rb +0 -3
  58. data/lib/unipept.rb +0 -8
  59. data/test/test_unipept.rb +0 -7
@@ -0,0 +1,170 @@
1
+ require_relative '../../lib/commands'
2
+
3
+ module Unipept
4
+ class PeptfilterTestCase < Unipept::TestCase
5
+ def test_length_filter
6
+ # min length
7
+ assert(Commands::Peptfilter.filter_length('AALER', 4, 10))
8
+ assert(Commands::Peptfilter.filter_length('AALER', 5, 10))
9
+ assert(!Commands::Peptfilter.filter_length('AALER', 6, 10))
10
+
11
+ # max length
12
+ assert(!Commands::Peptfilter.filter_length('AALER', 1, 4))
13
+ assert(Commands::Peptfilter.filter_length('AALER', 1, 5))
14
+ assert(Commands::Peptfilter.filter_length('AALER', 1, 6))
15
+ end
16
+
17
+ def test_lacks_filter
18
+ assert(Commands::Peptfilter.filter_lacks('AALER', ''.chars.to_a))
19
+ assert(Commands::Peptfilter.filter_lacks('AALER', 'BCD'.chars.to_a))
20
+ assert(!Commands::Peptfilter.filter_lacks('AALER', 'A'.chars.to_a))
21
+ assert(!Commands::Peptfilter.filter_lacks('AALER', 'AE'.chars.to_a))
22
+ end
23
+
24
+ def test_contains_filter
25
+ assert(Commands::Peptfilter.filter_contains('AALER', ''.chars.to_a))
26
+ assert(Commands::Peptfilter.filter_contains('AALER', 'A'.chars.to_a))
27
+ assert(Commands::Peptfilter.filter_contains('AALER', 'AE'.chars.to_a))
28
+ assert(!Commands::Peptfilter.filter_contains('AALER', 'BCD'.chars.to_a))
29
+ assert(!Commands::Peptfilter.filter_contains('AALER', 'AB'.chars.to_a))
30
+ end
31
+
32
+ def test_filter
33
+ assert(Commands::Peptfilter.filter('AALTER', 4, 10, 'BCD'.chars.to_a, 'AL'.chars.to_a))
34
+ assert(!Commands::Peptfilter.filter('AALTER', 7, 10, 'BCD.chars.to_a', 'AL'.chars.to_a))
35
+ assert(!Commands::Peptfilter.filter('AALTER', 4, 5, 'BCD'.chars.to_a, 'AL'.chars.to_a))
36
+ assert(!Commands::Peptfilter.filter('AALTER', 4, 10, 'ABC'.chars.to_a, 'AL'.chars.to_a))
37
+ assert(!Commands::Peptfilter.filter('AALTER', 4, 10, 'BCD'.chars.to_a, 'ALC'.chars.to_a))
38
+ end
39
+
40
+ def test_default_min_length_argument
41
+ out, _err = capture_io_with_input('A' * 6) do
42
+ Commands::Peptfilter.run(%w())
43
+ end
44
+ assert_equal('A' * 6, out.chomp)
45
+
46
+ out, _err = capture_io_with_input('A' * 5) do
47
+ Commands::Peptfilter.run(%w())
48
+ end
49
+ assert_equal('A' * 5, out.chomp)
50
+
51
+ out, _err = capture_io_with_input('A' * 4) do
52
+ Commands::Peptfilter.run(%w())
53
+ end
54
+ assert_equal('', out.chomp)
55
+ end
56
+
57
+ def test_default_max_length_argument
58
+ out, _err = capture_io_with_input('A' * 49) do
59
+ Commands::Peptfilter.run(%w())
60
+ end
61
+ assert_equal('A' * 49, out.chomp)
62
+
63
+ out, _err = capture_io_with_input('A' * 50) do
64
+ Commands::Peptfilter.run(%w())
65
+ end
66
+ assert_equal('A' * 50, out.chomp)
67
+
68
+ out, _err = capture_io_with_input('A' * 51) do
69
+ Commands::Peptfilter.run(%w())
70
+ end
71
+ assert_equal('', out.chomp)
72
+ end
73
+
74
+ def test_with_min_argument
75
+ out, _err = capture_io_with_input('A' * 6) do
76
+ Commands::Peptfilter.run(%w(--minlen 7))
77
+ end
78
+ assert_equal('', out.chomp)
79
+
80
+ out, _err = capture_io_with_input('A' * 4) do
81
+ Commands::Peptfilter.run(%w(--minlen 3))
82
+ end
83
+ assert_equal('A' * 4, out.chomp)
84
+ end
85
+
86
+ def test_with_max_argument
87
+ out, _err = capture_io_with_input('A' * 45) do
88
+ Commands::Peptfilter.run(%w(--maxlen 40))
89
+ end
90
+ assert_equal('', out.chomp)
91
+
92
+ out, _err = capture_io_with_input('A' * 55) do
93
+ Commands::Peptfilter.run(%w(--maxlen 60))
94
+ end
95
+ assert_equal('A' * 55, out.chomp)
96
+ end
97
+
98
+ def test_with_lacks_argument
99
+ out, _err = capture_io_with_input('A' * 10) do
100
+ Commands::Peptfilter.run(%w(--lacks B))
101
+ end
102
+ assert_equal('A' * 10, out.chomp)
103
+
104
+ out, _err = capture_io_with_input('A' * 10) do
105
+ Commands::Peptfilter.run(%w(-l B))
106
+ end
107
+ assert_equal('A' * 10, out.chomp)
108
+
109
+ out, _err = capture_io_with_input('A' * 10) do
110
+ Commands::Peptfilter.run(%w(--lacks A))
111
+ end
112
+ assert_equal('', out.chomp)
113
+
114
+ out, _err = capture_io_with_input('A' * 10) do
115
+ Commands::Peptfilter.run(%w(-l A))
116
+ end
117
+ assert_equal('', out.chomp)
118
+ end
119
+
120
+ def test_with_contains_argument
121
+ out, _err = capture_io_with_input('A' * 10) do
122
+ Commands::Peptfilter.run(%w(--contains A))
123
+ end
124
+ assert_equal('A' * 10, out.chomp)
125
+
126
+ out, _err = capture_io_with_input('A' * 10) do
127
+ Commands::Peptfilter.run(%w(-c A))
128
+ end
129
+ assert_equal('A' * 10, out.chomp)
130
+
131
+ out, _err = capture_io_with_input('A' * 10) do
132
+ Commands::Peptfilter.run(%w(--contains B))
133
+ end
134
+ assert_equal('', out.chomp)
135
+
136
+ out, _err = capture_io_with_input('A' * 10) do
137
+ Commands::Peptfilter.run(%w(-c B))
138
+ end
139
+ assert_equal('', out.chomp)
140
+ end
141
+
142
+ def test_fasta_input
143
+ out, _err = capture_io_with_input('>') do
144
+ Commands::Peptfilter.run(%w())
145
+ end
146
+ assert_equal('>', out.chomp)
147
+
148
+ out, _err = capture_io_with_input(['>', 'A', 'AALTER', '>']) do
149
+ Commands::Peptfilter.run(%w())
150
+ end
151
+ assert_equal(">\nAALTER\n>", out.chomp)
152
+ end
153
+
154
+ def test_normal_input
155
+ out, _err = capture_io_with_input(['A', 'A' * 11, 'AAAAB', 'BBBBB', 'CCCCC', 'CCCCCA']) do
156
+ Commands::Peptfilter.run(%w(--minlen 4 --maxlen 10 --lacks B --contains A))
157
+ end
158
+ assert_equal('CCCCCA', out.chomp)
159
+ end
160
+
161
+ def test_help
162
+ out, _err = capture_io_while do
163
+ assert_raises SystemExit do
164
+ Commands::Peptfilter.run(%w(-h))
165
+ end
166
+ end
167
+ assert(out.include? 'show help for this command')
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,82 @@
1
+ require_relative '../../lib/commands'
2
+
3
+ module Unipept
4
+ class Prot2peptTestCase < Unipept::TestCase
5
+ def test_normal_input
6
+ out, _err = capture_io_with_input('AALTERAALTERPAALTER') do
7
+ Commands::Prot2pept.run(%w())
8
+ end
9
+ assert_equal("AALTER\nAALTERPAALTER", out.chomp)
10
+
11
+ out, _err = capture_io_with_input('KRKPR') do
12
+ Commands::Prot2pept.run(%w())
13
+ end
14
+ assert_equal("K\nR\nKPR", out.chomp)
15
+
16
+ out, _err = capture_io_with_input(%w(AALTERAALTERPAALTER AALTERAA)) do
17
+ Commands::Prot2pept.run(%w())
18
+ end
19
+ assert_equal("AALTER\nAALTERPAALTER\nAALTER\nAA", out.chomp)
20
+ end
21
+
22
+ def test_fasta_input
23
+ out, _err = capture_io_with_input(">AKA\nAALTERAALTERPAALTER") do
24
+ Commands::Prot2pept.run(%w())
25
+ end
26
+ assert_equal(">AKA\nAALTER\nAALTERPAALTER", out.chomp)
27
+
28
+ out, _err = capture_io_with_input(">AKA\nAAL\nT\nERAALTER\nP\nAALTER") do
29
+ Commands::Prot2pept.run(%w())
30
+ end
31
+ assert_equal(">AKA\nAALTER\nAALTERPAALTER", out.chomp)
32
+
33
+ out, _err = capture_io_with_input(">AKA\nAAL\nT\n>\nERAALTER\nP\nAALTER") do
34
+ Commands::Prot2pept.run(%w())
35
+ end
36
+ assert_equal(">AKA\nAALT\n>\nER\nAALTERPAALTER", out.chomp)
37
+ end
38
+
39
+ def test_default_pattern
40
+ default_out, _err = capture_io_with_input('AALTERAALTERPAALTER') do
41
+ Commands::Prot2pept.run(%w())
42
+ end
43
+ assert_equal("AALTER\nAALTERPAALTER", default_out.chomp)
44
+
45
+ pattern_out, _err = capture_io_with_input('AALTERAALTERPAALTER') do
46
+ Commands::Prot2pept.run(['-p', '([KR])([^P])'])
47
+ end
48
+ assert_equal(default_out, pattern_out)
49
+
50
+ pattern_out, _err = capture_io_with_input('AALTERAALTERPAALTER') do
51
+ Commands::Prot2pept.run(['--pattern', '([KR])([^P])'])
52
+ end
53
+ assert_equal(default_out, pattern_out)
54
+ end
55
+
56
+ def test_pattern
57
+ out, _err = capture_io_with_input('AALTERAALTERPAALTER') do
58
+ Commands::Prot2pept.run(%w())
59
+ end
60
+ assert_equal("AALTER\nAALTERPAALTER", out.chomp)
61
+
62
+ out, _err = capture_io_with_input('AALTERAALTERPAALTER') do
63
+ Commands::Prot2pept.run(%w(-p ([KR])([^A])))
64
+ end
65
+ assert_equal("AALTERAALTER\nPAALTER", out.chomp)
66
+
67
+ out, _err = capture_io_with_input('AALTERAALTERPAALTER') do
68
+ Commands::Prot2pept.run(%w(--pattern ([KR])([^A])))
69
+ end
70
+ assert_equal("AALTERAALTER\nPAALTER", out.chomp)
71
+ end
72
+
73
+ def test_help
74
+ out, _err = capture_io_while do
75
+ assert_raises SystemExit do
76
+ Commands::Prot2pept.run(%w(-h))
77
+ end
78
+ end
79
+ assert(out.include? 'show help for this command')
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,37 @@
1
+ require_relative '../../lib/commands'
2
+
3
+ module Unipept
4
+ class UnipeptTestCase < Unipept::TestCase
5
+ def test_help
6
+ out, _err = capture_io_while do
7
+ assert_raises SystemExit do
8
+ Commands::Unipept.run(%w(-h))
9
+ end
10
+ end
11
+ assert(out.include? 'show help for this command')
12
+
13
+ out, _err = capture_io_while do
14
+ assert_raises SystemExit do
15
+ Commands::Unipept.run(%w(--help))
16
+ end
17
+ end
18
+ assert(out.include? 'show help for this command')
19
+ end
20
+
21
+ def test_no_valid_subcommand
22
+ _out, err = capture_io_while do
23
+ assert_raises SystemExit do
24
+ Commands::Unipept.run(%w())
25
+ end
26
+ end
27
+ assert(err.include? 'show help for this command')
28
+ end
29
+
30
+ def test_version
31
+ out, _err = capture_io_while do
32
+ Commands::Unipept.run(%w(-v))
33
+ end
34
+ assert_equal(VERSION, out.chomp)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,136 @@
1
+ require_relative '../../lib/commands'
2
+
3
+ module Unipept
4
+ class UniprotTestCase < Unipept::TestCase
5
+ def test_argument_input
6
+ out, _err = capture_io_while do
7
+ Commands::Uniprot.run(%w(Q6GZX3))
8
+ end
9
+ assert_equal(1, out.split(/\n/).length)
10
+
11
+ out, _err = capture_io_while do
12
+ Commands::Uniprot.run(%w(Q6GZX3 Q6GZX4))
13
+ end
14
+ assert_equal(2, out.split(/\n/).length)
15
+
16
+ out, _err = capture_io_while do
17
+ Commands::Uniprot.run(%w(-f fasta Q6GZX3 Q6GZX4))
18
+ end
19
+ assert_equal(2, out.count('>'))
20
+
21
+ out, _err = capture_io_while do
22
+ Commands::Uniprot.run(%w(--format fasta Q6GZX3 Q6GZX4))
23
+ end
24
+ assert_equal(2, out.count('>'))
25
+ end
26
+
27
+ def test_stdin_input
28
+ out, _err = capture_io_with_input('Q6GZX3') do
29
+ Commands::Uniprot.run(%w())
30
+ end
31
+ assert_equal(1, out.split(/\n/).length)
32
+
33
+ out, _err = capture_io_with_input(%w(Q6GZX3 Q6GZX4)) do
34
+ Commands::Uniprot.run(%w())
35
+ end
36
+ assert_equal(2, out.split(/\n/).length)
37
+
38
+ out, _err = capture_io_with_input(%w(Q6GZX3 Q6GZX4)) do
39
+ Commands::Uniprot.run(%w(-f fasta))
40
+ end
41
+ assert_equal(2, out.count('>'))
42
+
43
+ out, _err = capture_io_with_input(%w(Q6GZX3 Q6GZX4)) do
44
+ Commands::Uniprot.run(%w(--format fasta))
45
+ end
46
+ assert_equal(2, out.count('>'))
47
+ end
48
+
49
+ def test_argument_input_priority
50
+ out, _err = capture_io_with_input('Q6GZX3') do
51
+ Commands::Uniprot.run(%w(Q6GZX3 Q6GZX4))
52
+ end
53
+ assert_equal(2, out.split(/\n/).length)
54
+
55
+ out, _err = capture_io_with_input(%w(Q6GZX3 Q6GZX4)) do
56
+ Commands::Uniprot.run(%w(Q6GZX3))
57
+ end
58
+ assert_equal(1, out.split(/\n/).length)
59
+ end
60
+
61
+ def test_invalid_format
62
+ out, err = capture_io_while do
63
+ assert_raises SystemExit do
64
+ Commands::Uniprot.run(%w(--format xxx))
65
+ end
66
+ end
67
+ assert_equal('', out)
68
+ assert(err.include? 'xxx is not a valid output format')
69
+ end
70
+
71
+ def test_default_format
72
+ out_default, _err = capture_io_while do
73
+ Commands::Uniprot.run(%w(Q6GZX3))
74
+ end
75
+ assert_equal(1, out_default.split(/\n/).length)
76
+
77
+ out_sequence, _err = capture_io_while do
78
+ Commands::Uniprot.run(%w(-f sequence Q6GZX3))
79
+ end
80
+ assert_equal(out_default, out_sequence)
81
+
82
+ out_sequence, _err = capture_io_while do
83
+ Commands::Uniprot.run(%w(--format sequence Q6GZX3))
84
+ end
85
+ assert_equal(out_default, out_sequence)
86
+ end
87
+
88
+ def test_format_options
89
+ # fasta txt xml rdf gff sequence
90
+ out, err = capture_io_while do
91
+ Commands::Uniprot.run(%w(-f fasta Q6GZX3))
92
+ end
93
+ assert(!out.empty?)
94
+ assert(err.empty?)
95
+
96
+ out, err = capture_io_while do
97
+ Commands::Uniprot.run(%w(-f txt Q6GZX3))
98
+ end
99
+ assert(!out.empty?)
100
+ assert(err.empty?)
101
+
102
+ out, err = capture_io_while do
103
+ Commands::Uniprot.run(%w(-f xml Q6GZX3))
104
+ end
105
+ assert(!out.empty?)
106
+ assert(err.empty?)
107
+
108
+ out, err = capture_io_while do
109
+ Commands::Uniprot.run(%w(-f rdf Q6GZX3))
110
+ end
111
+ assert(!out.empty?)
112
+ assert(err.empty?)
113
+
114
+ out, err = capture_io_while do
115
+ Commands::Uniprot.run(%w(-f gff Q6GZX3))
116
+ end
117
+ assert(!out.empty?)
118
+ assert(err.empty?)
119
+
120
+ out, err = capture_io_while do
121
+ Commands::Uniprot.run(%w(-f sequence Q6GZX3))
122
+ end
123
+ assert(!out.empty?)
124
+ assert(err.empty?)
125
+ end
126
+
127
+ def test_help
128
+ out, _err = capture_io_while do
129
+ assert_raises SystemExit do
130
+ Commands::Uniprot.run(%w(-h))
131
+ end
132
+ end
133
+ assert(out.include? 'show help for this command')
134
+ end
135
+ end
136
+ end