rbbt-util 5.43.0 → 5.44.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rbbt/association/util.rb +1 -1
  3. data/lib/rbbt/hpc/batch.rb +19 -17
  4. data/lib/rbbt/tsv/accessor.rb +6 -11
  5. data/lib/rbbt/tsv/dumper.rb +21 -10
  6. data/lib/rbbt/tsv/index.rb +2 -1
  7. data/lib/rbbt/util/misc/math.rb +0 -1
  8. data/lib/rbbt/util/open.rb +1 -1
  9. data/lib/rbbt/workflow/step/info.rb +1 -0
  10. data/lib/rbbt/workflow/step.rb +2 -1
  11. data/python/rbbt/__init__.py +2 -2
  12. data/share/rbbt_commands/workflow/task +1 -1
  13. metadata +4 -220
  14. data/test/rbbt/annotations/test_util.rb +0 -43
  15. data/test/rbbt/association/test_database.rb +0 -87
  16. data/test/rbbt/association/test_index.rb +0 -127
  17. data/test/rbbt/association/test_item.rb +0 -15
  18. data/test/rbbt/association/test_open.rb +0 -63
  19. data/test/rbbt/association/test_util.rb +0 -108
  20. data/test/rbbt/entity/test_identifiers.rb +0 -34
  21. data/test/rbbt/hpc/orchestrate/test_batches.rb +0 -70
  22. data/test/rbbt/hpc/orchestrate/test_chains.rb +0 -108
  23. data/test/rbbt/hpc/orchestrate/test_rules.rb +0 -59
  24. data/test/rbbt/hpc/test_batch.rb +0 -64
  25. data/test/rbbt/hpc/test_hpc_test_workflows.rb +0 -0
  26. data/test/rbbt/hpc/test_orchestrate.rb +0 -144
  27. data/test/rbbt/hpc/test_pbs.rb +0 -43
  28. data/test/rbbt/hpc/test_slurm.rb +0 -28
  29. data/test/rbbt/knowledge_base/test_enrichment.rb +0 -50
  30. data/test/rbbt/knowledge_base/test_entity.rb +0 -62
  31. data/test/rbbt/knowledge_base/test_query.rb +0 -46
  32. data/test/rbbt/knowledge_base/test_registry.rb +0 -74
  33. data/test/rbbt/knowledge_base/test_syndicate.rb +0 -48
  34. data/test/rbbt/knowledge_base/test_traverse.rb +0 -133
  35. data/test/rbbt/persist/test_tsv.rb +0 -88
  36. data/test/rbbt/persist/tsv/test_cdb.rb +0 -18
  37. data/test/rbbt/persist/tsv/test_kyotocabinet.rb +0 -27
  38. data/test/rbbt/persist/tsv/test_leveldb.rb +0 -18
  39. data/test/rbbt/persist/tsv/test_lmdb.rb +0 -20
  40. data/test/rbbt/persist/tsv/test_sharder.rb +0 -164
  41. data/test/rbbt/persist/tsv/test_tokyocabinet.rb +0 -262
  42. data/test/rbbt/resource/test_path.rb +0 -49
  43. data/test/rbbt/test_annotations.rb +0 -167
  44. data/test/rbbt/test_association.rb +0 -103
  45. data/test/rbbt/test_entity.rb +0 -252
  46. data/test/rbbt/test_fix_width_table.rb +0 -135
  47. data/test/rbbt/test_knowledge_base.rb +0 -226
  48. data/test/rbbt/test_monitor.rb +0 -11
  49. data/test/rbbt/test_packed_index.rb +0 -68
  50. data/test/rbbt/test_persist.rb +0 -85
  51. data/test/rbbt/test_resource.rb +0 -110
  52. data/test/rbbt/test_tsv.rb +0 -669
  53. data/test/rbbt/test_workflow.rb +0 -609
  54. data/test/rbbt/tsv/parallel/test_through.rb +0 -40
  55. data/test/rbbt/tsv/parallel/test_traverse.rb +0 -456
  56. data/test/rbbt/tsv/test_accessor.rb +0 -319
  57. data/test/rbbt/tsv/test_attach.rb +0 -715
  58. data/test/rbbt/tsv/test_change_id.rb +0 -61
  59. data/test/rbbt/tsv/test_csv.rb +0 -49
  60. data/test/rbbt/tsv/test_excel.rb +0 -171
  61. data/test/rbbt/tsv/test_field_index.rb +0 -19
  62. data/test/rbbt/tsv/test_filter.rb +0 -187
  63. data/test/rbbt/tsv/test_index.rb +0 -308
  64. data/test/rbbt/tsv/test_manipulate.rb +0 -334
  65. data/test/rbbt/tsv/test_marshal.rb +0 -24
  66. data/test/rbbt/tsv/test_matrix.rb +0 -20
  67. data/test/rbbt/tsv/test_parallel.rb +0 -7
  68. data/test/rbbt/tsv/test_parser.rb +0 -101
  69. data/test/rbbt/tsv/test_stream.rb +0 -253
  70. data/test/rbbt/tsv/test_util.rb +0 -52
  71. data/test/rbbt/util/R/test_eval.rb +0 -43
  72. data/test/rbbt/util/R/test_model.rb +0 -128
  73. data/test/rbbt/util/R/test_plot.rb +0 -38
  74. data/test/rbbt/util/concurrency/processes/test_socket.rb +0 -70
  75. data/test/rbbt/util/concurrency/test_processes.rb +0 -192
  76. data/test/rbbt/util/concurrency/test_threads.rb +0 -40
  77. data/test/rbbt/util/log/test_progress.rb +0 -111
  78. data/test/rbbt/util/misc/test_bgzf.rb +0 -48
  79. data/test/rbbt/util/misc/test_communication.rb +0 -13
  80. data/test/rbbt/util/misc/test_development.rb +0 -26
  81. data/test/rbbt/util/misc/test_format.rb +0 -10
  82. data/test/rbbt/util/misc/test_indiferent_hash.rb +0 -14
  83. data/test/rbbt/util/misc/test_lock.rb +0 -77
  84. data/test/rbbt/util/misc/test_multipart_payload.rb +0 -202
  85. data/test/rbbt/util/misc/test_omics.rb +0 -116
  86. data/test/rbbt/util/misc/test_pipes.rb +0 -343
  87. data/test/rbbt/util/misc/test_serialize.rb +0 -24
  88. data/test/rbbt/util/python/test_util.rb +0 -25
  89. data/test/rbbt/util/simpleopt/test_get.rb +0 -12
  90. data/test/rbbt/util/simpleopt/test_parse.rb +0 -10
  91. data/test/rbbt/util/simpleopt/test_setup.rb +0 -76
  92. data/test/rbbt/util/test_R.rb +0 -37
  93. data/test/rbbt/util/test_chain_methods.rb +0 -22
  94. data/test/rbbt/util/test_cmd.rb +0 -87
  95. data/test/rbbt/util/test_colorize.rb +0 -22
  96. data/test/rbbt/util/test_concurrency.rb +0 -6
  97. data/test/rbbt/util/test_config.rb +0 -69
  98. data/test/rbbt/util/test_excel2tsv.rb +0 -10
  99. data/test/rbbt/util/test_filecache.rb +0 -36
  100. data/test/rbbt/util/test_log.rb +0 -52
  101. data/test/rbbt/util/test_migrate.rb +0 -34
  102. data/test/rbbt/util/test_misc.rb +0 -728
  103. data/test/rbbt/util/test_open.rb +0 -200
  104. data/test/rbbt/util/test_procpath.rb +0 -23
  105. data/test/rbbt/util/test_python.rb +0 -144
  106. data/test/rbbt/util/test_semaphore.rb +0 -36
  107. data/test/rbbt/util/test_simpleDSL.rb +0 -55
  108. data/test/rbbt/util/test_simpleopt.rb +0 -11
  109. data/test/rbbt/util/test_ssh.rb +0 -10
  110. data/test/rbbt/util/test_tmpfile.rb +0 -32
  111. data/test/rbbt/workflow/step/test_dependencies.rb +0 -295
  112. data/test/rbbt/workflow/step/test_save_load_inputs.rb +0 -136
  113. data/test/rbbt/workflow/test_doc.rb +0 -30
  114. data/test/rbbt/workflow/test_remote_workflow.rb +0 -99
  115. data/test/rbbt/workflow/test_schedule.rb +0 -0
  116. data/test/rbbt/workflow/test_step.rb +0 -231
  117. data/test/rbbt/workflow/test_task.rb +0 -85
  118. data/test/rbbt/workflow/util/test_archive.rb +0 -27
  119. data/test/rbbt/workflow/util/test_data.rb +0 -67
  120. data/test/rbbt/workflow/util/test_orchestrator.rb +0 -263
  121. data/test/test_helper.rb +0 -114
@@ -1,308 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
2
- require 'rbbt/tsv'
3
- require 'rbbt/tsv/index'
4
-
5
- class TestTSVManipulate < Test::Unit::TestCase
6
-
7
- def load_segment_data(data)
8
- tsv = TSV.open(data, :list, :sep=>":", :cast => proc{|e| e =~ /(\s*)(_*)/; ($1.length..($1.length + $2.length - 1))})
9
-
10
- tsv.add_field "Start" do |key, values|
11
- values["Range"].first
12
- end
13
-
14
- tsv.add_field "End" do |key, values|
15
- values["Range"].last
16
- end
17
-
18
- tsv = tsv.slice ["Start", "End"]
19
-
20
- tsv
21
- end
22
-
23
- def test_index
24
- content =<<-EOF
25
- #Id ValueA ValueB OtherID
26
- row1 a|aa|aaa b Id1|Id2
27
- row2 A B Id3
28
- EOF
29
-
30
- TmpFile.with_file(content) do |filename|
31
- tsv = TSV.open(File.open(filename), :sep => /\s+/, :key_field => "OtherID", :persistence => false)
32
- index = tsv.index(:persistence => true)
33
- assert index["row1"].include? "Id1"
34
- assert_equal "OtherID", index.fields.first
35
- end
36
-
37
- end
38
-
39
- def test_index_fields_key
40
- content =<<-EOF
41
- #Id ValueA ValueB OtherID
42
- row1 a|aa|aaa b Id1|Id2
43
- row2 A B Id3
44
- EOF
45
-
46
- TmpFile.with_file(content) do |filename|
47
- tsv = TSV.open(File.open(filename), :sep => /\s+/, :key_field => "OtherID", :persistence => false)
48
- index = tsv.index(:persistence => false, :fields => ["Id"], :target => "ValueA")
49
- assert_equal "A", index["row2"]
50
- end
51
-
52
- end
53
-
54
- def test_best_index
55
- content =<<-EOF
56
- #Id ValueA ValueB OtherID
57
- row1 a|aa|aaa b|A Id1
58
- row2 A a|B Id3
59
- row3 A a|B Id4
60
- EOF
61
-
62
- TmpFile.with_file(content) do |filename|
63
- tsv = TSV.open(File.open(filename), :sep => /\s+/, :key_field => "OtherID")
64
- index = tsv.index(:order => true)
65
- assert_equal "Id1", index['a']
66
- assert_equal "Id3", index['A']
67
- assert_equal "OtherID", index.fields.first
68
-
69
- index = tsv.index(:order => false)
70
- assert_equal "Id1", index['a']
71
- end
72
-
73
- TmpFile.with_file(content) do |filename|
74
- tsv = TSV.open(File.open(filename), :sep => /\s+/, :key_field => "OtherID")
75
- index = tsv.index
76
- assert index["row1"].include? "Id1"
77
- assert_equal "OtherID", index.fields.first
78
- end
79
- end
80
-
81
-
82
- def test_index_from_persit
83
- content =<<-EOF
84
- #Id ValueA ValueB OtherID
85
- row1 a|aa|aaa b|A Id1
86
- row2 A a|B Id3
87
- row3 A a|B Id4
88
- EOF
89
-
90
- TmpFile.with_file(content) do |filename|
91
- tsv = TSV.open(Open.open(filename), :sep => /\s+/, :key_field => "OtherID", :persist => true)
92
- index = tsv.index(:order => true)
93
- assert_equal "Id1", index['a']
94
- assert_equal "Id3", index['A']
95
- assert_equal "OtherID", index.fields.first
96
- end
97
- end
98
-
99
- def test_index_to_persist
100
- content =<<-EOF
101
- #Id ValueA ValueB OtherID
102
- row1 a|aa|aaa b|A Id1
103
- row2 A a|B Id3
104
- row3 A a|B Id4
105
- EOF
106
-
107
- TmpFile.with_file(content) do |filename|
108
- tsv = TSV.open(Open.open(filename), :sep => /\s+/, :key_field => "OtherID", :persist => true)
109
-
110
- index = tsv.index(:order => true, :persist => true)
111
- assert_equal "Id1", index['a']
112
- assert_equal "Id3", index['A']
113
- assert_equal "OtherID", index.fields.first
114
- assert_equal "Id1", index['a']
115
-
116
- index = tsv.index(:order => true, :persist => false)
117
- assert_equal "Id1", index['a']
118
-
119
- tsv.delete "Id1"
120
-
121
- index = tsv.index(:order => true, :persist => false)
122
- assert_equal "Id3", index['a']
123
-
124
- index = tsv.index(:order => true, :persist => true)
125
- assert_equal "Id1", index['a']
126
- assert_equal "Id3", index['A']
127
- assert_equal "OtherID", index.fields.first
128
- assert_equal "Id1", index['a']
129
-
130
- end
131
- end
132
-
133
- def test_index_static
134
- content =<<-EOF
135
- #Id ValueA ValueB OtherID
136
- row1 a|aa|aaa b|B Id1
137
- row2 A bb Id3
138
- row3 AA bb Id4
139
- EOF
140
-
141
- TmpFile.with_file(content) do |filename|
142
- index = TSV.index(filename, :target => "OtherID", :data_sep => /\s+/, :order => true, :persist => true, :data_persist => true)
143
- assert_equal "Id1", index['a']
144
- assert_equal "Id3", index['A']
145
- assert_equal "OtherID", index.fields.first
146
- end
147
- end
148
-
149
- def test_index_static_persist
150
- content =<<-EOF
151
- #Id ValueA ValueB OtherID
152
- row1 a|aa|aaa b|A Id1
153
- row2 A a|B Id3
154
- row3 A a|B Id4
155
- EOF
156
-
157
- TmpFile.with_file(content) do |filename|
158
- index = TSV.index(filename, :target => "OtherID", :data_sep => /\s+/, :order => true, :persist => false)
159
- assert_equal "Id1", index['a']
160
- assert_equal "Id3", index['A']
161
- assert_equal "OtherID", index.fields.first
162
-
163
- index = TSV.index(filename, :target => "OtherID", :data_sep => /\s+/, :order => true, :persist => true)
164
- assert_equal "Id1", index['a']
165
- assert_equal "Id3", index['A']
166
- assert_equal "OtherID", index.fields.first
167
-
168
- Open.write(filename, Open.read(filename).sub(/row1.*Id1\n/,''))
169
-
170
- index = TSV.index(filename, :target => "OtherID", :data_sep => /\s+/, :order => true, :persist => true)
171
- assert_equal "Id1", index['a']
172
- assert_equal "Id3", index['A']
173
- assert_equal "OtherID", index.fields.first
174
- assert index.include?('aaa')
175
-
176
- index = TSV.index(filename, :target => "OtherID", :data_sep => /\s+/, :order => true, :persist => false)
177
- assert ! index.include?('aaa')
178
- end
179
- end
180
-
181
- def test_pos_index
182
- content =<<-EOF
183
- #Id ValueA ValueB Pos
184
- row1 a|aa|aaa b 0|10
185
- row2 A B 30
186
- EOF
187
-
188
- TmpFile.with_file(content) do |filename|
189
- tsv = TSV.open(File.open(filename), :double, :sep => /\s+/)
190
- index = tsv.pos_index("Pos")
191
- assert_equal ["row1"], index[10]
192
- end
193
- end
194
-
195
- def test_range_index
196
- content =<<-EOF
197
- #Id ValueA ValueB Pos1 Pos2
198
- row1 a|aa|aaa b 0|10 10|30
199
- row2 A B 30 35
200
- EOF
201
-
202
- TmpFile.with_file(content) do |filename|
203
- tsv = TSV.open(File.open(filename), :double, :sep => /\s+/)
204
- index = tsv.pos_index("Pos1")
205
- assert_equal ["row1"], index[10]
206
-
207
- index = tsv.range_index("Pos1", "Pos2")
208
- assert_equal ["row1"], index[20]
209
- end
210
- end
211
-
212
- def test_range_index2
213
- data =<<-EOF
214
- # 012345678901234567890
215
- #ID:Range
216
- a: ______
217
- b: ______
218
- c: _______
219
- d: ____
220
- e: ______
221
- f: ___
222
- g: ____
223
- EOF
224
- TmpFile.with_file(data) do |datafile|
225
- tsv = load_segment_data(datafile)
226
- f = tsv.range_index("Start", "End", :persist => true)
227
-
228
- assert_equal %w(), f[0].sort
229
- assert_equal %w(b), f[1].sort
230
- assert_equal %w(), f[20].sort
231
- assert_equal %w(), f[(20..100)].sort
232
- assert_equal %w(a b d), f[3].sort
233
- assert_equal %w(a b c d e), f[(3..4)].sort
234
- end
235
- end
236
-
237
- def test_range_index_persistent
238
- data =<<-EOF
239
- # 012345678901234567890
240
- #ID:Range
241
- a: ______
242
- b: ______
243
- c: _______
244
- d: ____
245
- e: ______
246
- f: ___
247
- g: ____
248
- EOF
249
- TmpFile.with_file(data) do |datafile|
250
- load_segment_data(datafile)
251
- TmpFile.with_file(load_segment_data(datafile).to_s) do |tsvfile|
252
- f = TSV.range_index(tsvfile, "Start", "End", :persistence => true)
253
-
254
- #assert_equal %w(), f[0].sort
255
- #assert_equal %w(b), f[1].sort
256
- #assert_equal %w(), f[20].sort
257
- #assert_equal %w(), f[(20..100)].sort
258
- #assert_equal %w(a b d), f[3].sort
259
- #assert_equal %w(a b c d e), f[(3..4)].sort
260
- end
261
- end
262
- end
263
-
264
-
265
- # #{{{ Test Attach
266
- # def test_index_headerless
267
- # content =<<-EOF
268
- #row1 a|aa|aaa b Id1|Id2
269
- #row2 A B Id3
270
- # EOF
271
- #
272
- # TmpFile.with_file(content) do |filename|
273
- # tsv = TSV.open(File.open(filename), :sep => /\s+/)
274
- # index = tsv.index(:target => 2)
275
- # assert index["row1"].include? "Id1"
276
- # end
277
- # end
278
-
279
-
280
-
281
- def test_range_index_persistent_with_filter
282
- data =<<-EOF
283
- # 012345678901234567890
284
- #ID:Range
285
- a: ______
286
- b: ______
287
- c: _______
288
- d: ____
289
- e: ______
290
- f: ___
291
- g: ____
292
- EOF
293
- TmpFile.with_file(data) do |datafile|
294
- TmpFile.with_file(load_segment_data(datafile).to_s) do |tsvfile|
295
- f = TSV.range_index(tsvfile, "Start", "End", :filters => [["field:Start", "3"]], :persist_update => true)
296
-
297
- assert_equal %w(), f[0].sort
298
- assert_equal %w(), f[1].sort
299
- assert_equal %w(), f[20].sort
300
- assert_equal %w(), f[(20..100)].sort
301
- assert_equal %w(a), f[3].sort
302
- assert_equal %w(a), f[(3..4)].sort
303
- end
304
- end
305
- end
306
-
307
- end
308
-
@@ -1,334 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), '../../', 'test_helper.rb')
2
- require 'rbbt/tsv'
3
- require 'rbbt/tsv/manipulate'
4
-
5
- class TestTSVManipulate < Test::Unit::TestCase
6
-
7
- def test_zipped
8
- content =<<-EOF
9
- #Id ValueA ValueB ValueC
10
- rowA A|AA B|BB C|CC
11
- rowa a|aa b|BB C|CC
12
- EOF
13
-
14
- TmpFile.with_file(content) do |filename|
15
- tsv = TSV.open(File.open(filename), :sep => /\s+/, :type => :double)
16
- assert_equal ["A", "AA", "a", "aa"].sort, tsv.reorder("ValueA", nil, :zipped => true).keys.sort
17
- end
18
- end
19
-
20
-
21
- def test_through
22
- content =<<-EOF
23
- #Id ValueA ValueB OtherID
24
- row1 a|aa|aaa b Id1|Id2
25
- row2 A B Id3
26
- row3 a C Id4
27
- EOF
28
-
29
- TmpFile.with_file(content) do |filename|
30
- tsv = TSV.open(File.open(filename), :sep => /\s+/)
31
-
32
- new_key, new_fields = tsv.through "ValueA" do |key, values|
33
- assert(tsv.keys.include? values["Id"].first)
34
- end
35
-
36
- assert_equal "ValueA", new_key
37
- end
38
- end
39
-
40
- def test_reorder_zipped
41
- content =<<-EOF
42
- #Id ValueA ValueB OtherID
43
- row1 a|aa|aaa b|bb|bbb Id1|Id2|Id3
44
- row2 A B Id3
45
- row3 a b_ Id1_
46
- EOF
47
-
48
- TmpFile.with_file(content) do |filename|
49
- tsv = TSV.open(File.open(filename), :sep => /\s+/)
50
-
51
- tsv1 = tsv.reorder("ValueA", nil, :zipped => true, :merge => true, :persist => true, :persist_file => '/tmp/foo.rbbt.tch')
52
-
53
- assert_equal "ValueA", tsv1.key_field
54
- assert_equal ["B"], tsv1["A"]["ValueB"]
55
- assert_equal ["bb"], tsv1["aa"]["ValueB"]
56
- assert_equal ["b","b_"], tsv1["a"]["ValueB"]
57
- assert_equal %w(Id ValueB OtherID), tsv1.fields
58
-
59
- end
60
- end
61
- def test_reorder_simple
62
- content =<<-EOF
63
- #Id ValueA ValueB OtherID
64
- row1 a|aa|aaa b Id1|Id2
65
- row2 A B Id3
66
- row3 a C Id4
67
- EOF
68
-
69
- TmpFile.with_file(content) do |filename|
70
- tsv = TSV.open(File.open(filename), :sep => /\s+/)
71
-
72
- tsv1 = tsv.reorder("ValueA")
73
-
74
- assert_equal "ValueA", tsv1.key_field
75
- assert_equal ["B"], tsv1["A"]["ValueB"]
76
- assert_equal ["b","C"], tsv1["a"]["ValueB"]
77
- assert_equal ["b"], tsv1["aa"]["ValueB"]
78
- assert_equal %w(Id ValueB OtherID), tsv1.fields
79
-
80
- end
81
- end
82
-
83
- def test_reorder_remove_field
84
- content =<<-EOF
85
- #Id ValueA ValueB OtherID
86
- row1 a|aa|aaa b Id1|Id2
87
- row2 A B Id3
88
- row3 a C Id4
89
- EOF
90
-
91
- TmpFile.with_file(content) do |filename|
92
- tsv = TSV.open(File.open(filename), :sep => /\s+/)
93
-
94
- tsv1 = tsv.reorder("ValueA", ["ValueB", "Id"])
95
-
96
- assert_equal "ValueA", tsv1.key_field
97
- assert_equal %w(ValueB Id), tsv1.fields
98
- assert_equal ["B"], tsv1["A"]["ValueB"]
99
- assert_equal ["b","C"], tsv1["a"]["ValueB"]
100
- assert_equal ["row1"], tsv1["aa"]["Id"]
101
- assert_equal ["row1","row3"], tsv1["a"]["Id"]
102
- end
103
- end
104
-
105
- def test_slice
106
- content =<<-EOF
107
- #ID ValueA ValueB Comment
108
- row1 a b c
109
- row2 A B C
110
- EOF
111
-
112
- TmpFile.with_file(content) do |filename|
113
- tsv = TSV.open(File.open(filename), :type => :double, :sep => /\s/)
114
- assert_equal [["a"],["c"]], tsv.reorder(:key, ["ValueA", "Comment"])["row1"]
115
- end
116
- end
117
-
118
- def test_slice_empty
119
- content =<<-EOF
120
- #ID ValueA ValueB Comment
121
- row1 a b c
122
- row2 A B C
123
- EOF
124
-
125
- TmpFile.with_file(content) do |filename|
126
- tsv = TSV.open(File.open(filename), :type => :list, :sep => /\s/)
127
- tsv = tsv.slice []
128
- assert tsv.fields.empty?
129
- TmpFile.with_file do |tmpfile|
130
- Open.write(tmpfile, tsv.to_s)
131
- tsv = TSV.open tmpfile
132
- assert tsv.fields.empty?
133
- end
134
- end
135
- end
136
-
137
- def test_select
138
- content =<<-EOF
139
- #Id ValueA ValueB OtherID
140
- row1 a|aa|aaa b Id1|Id2
141
- row2 A B Id3
142
- row3 a C Id4
143
- EOF
144
-
145
- TmpFile.with_file(content) do |filename|
146
- tsv = TSV.open(filename, :sep => /\s+/)
147
- assert tsv.type == :double
148
-
149
- new = tsv.select %w(b Id4)
150
- assert_equal %w(row1 row3).sort, new.keys
151
-
152
- new = tsv.select "ValueB" => %w(b Id4)
153
- assert_equal %w(row1).sort, new.keys
154
-
155
- new = tsv.select /b|Id4/
156
- assert_equal %w(row1 row3).sort, new.keys
157
-
158
- new = tsv.select "ValueB" => /b|Id4/
159
- assert_equal %w(row1).sort, new.keys
160
-
161
-
162
- new = tsv.select %w(b Id4)
163
- assert_equal %w(row1 row3).sort, new.keys.sort
164
-
165
- new = tsv.select do |k,v|
166
- v["ValueA"].include? "A"
167
- end
168
- assert_equal %w(row2).sort, new.keys.sort
169
-
170
- tsv = TSV.open(filename, :sep => /\s+/, :type => :flat)
171
- assert tsv.type != :double
172
- end
173
- end
174
-
175
- def test_select_invert
176
- content =<<-EOF
177
- #Id ValueA ValueB OtherID
178
- row1 a|aa|aaa b Id1|Id2
179
- row2 A B Id3
180
- row3 a C Id4
181
- EOF
182
-
183
- TmpFile.with_file(content) do |filename|
184
- tsv = TSV.open(filename, :sep => /\s+/)
185
- assert tsv.type == :double
186
-
187
- new = tsv.select %w(b Id4), true
188
- assert_equal %w(row2).sort, new.keys
189
-
190
- new = tsv.select /b|Id4/, true
191
- assert_equal %w(row2).sort, new.keys
192
-
193
- new = tsv.select %w(b Id4)
194
- assert_equal %w(row1 row3).sort, new.keys.sort
195
-
196
- new = tsv.select do |k,v|
197
- v["ValueA"].include? "A"
198
- end
199
- assert_equal %w(row2).sort, new.keys.sort
200
-
201
- tsv = TSV.open(filename, :sep => /\s+/, :type => :flat)
202
- assert tsv.type != :double
203
- end
204
- end
205
-
206
- def test_process
207
- content =<<-EOF
208
- #Id ValueA ValueB OtherID
209
- row1 a|aa|aaa b Id1|Id2
210
- row2 A B Id3
211
- row3 a C Id4
212
- EOF
213
-
214
- TmpFile.with_file(content) do |filename|
215
- tsv = TSV.open(File.open(filename), :sep => /\s+/)
216
-
217
- tsv.process "ValueA" do |field_values,key,values|
218
- field_values.collect{|v| "Pref:#{v}"}
219
- end
220
-
221
- assert_equal ["Pref:A"], tsv["row2"]["ValueA"]
222
- end
223
- end
224
-
225
- def test_add_field
226
- content =<<-EOF
227
- #Id LetterValue:ValueA LetterValue:ValueB OtherID
228
- row1 a|aa|aaa b Id1|Id2
229
- row2 A B Id3
230
- row3 a C Id4
231
- EOF
232
-
233
- TmpFile.with_file(content) do |filename|
234
- tsv = TSV.open(filename, :sep => /\s+/)
235
- tsv.add_field "Str length" do |k,v|
236
- (v.flatten * " ").length
237
- end
238
-
239
- assert tsv.fields.include?("Str length")
240
- end
241
- end
242
-
243
- def test_add_field_double_with_list_result
244
- content =<<-EOF
245
- #Id LetterValue:ValueA LetterValue:ValueB OtherID
246
- row1 a|aa|aaa b Id1|Id2
247
- row2 A B Id3
248
- row3 a C Id4
249
- EOF
250
-
251
- TmpFile.with_file(content) do |filename|
252
- tsv = TSV.open(filename, :sep => /\s+/)
253
-
254
- tsv.add_field "Test" do
255
- "test"
256
- end
257
-
258
- assert Array === tsv["row1"]["Test"]
259
- end
260
- end
261
-
262
- def test_through_headless
263
- content =<<-EOF
264
- row1 a|aa|aaa b Id1|Id2
265
- row2 A B Id3
266
- row3 a C Id4
267
- EOF
268
-
269
- TmpFile.with_file(content) do |filename|
270
- tsv = TSV.open(filename, :sep => /\s+/)
271
-
272
- test = false
273
- tsv.through do
274
- test = true
275
- end
276
- assert test
277
-
278
- end
279
-
280
- end
281
-
282
- def test_reorder_flat
283
- content =<<-EOF
284
- #Id ValueA
285
- row1 a aa aaa
286
- row2 A
287
- row3 a
288
- EOF
289
-
290
- TmpFile.with_file(content) do |filename|
291
- tsv = TSV.open(File.open(filename), :sep => /\s+/, :type => :flat)
292
-
293
- assert_equal ["row1", "row3"].sort, tsv.reorder("ValueA")["a"]
294
- end
295
- end
296
-
297
- def test_transpose
298
- content =<<-EOF
299
- #: :type=:list
300
- #Row vA vB vID
301
- row1 a b Id1
302
- row2 A B Id3
303
- row3 a C Id4
304
- EOF
305
-
306
- TmpFile.with_file(content) do |filename|
307
- tsv = TSV.open(filename, :sep => /\s+/)
308
-
309
- assert_equal %w(vA vB vID), tsv.transpose("Values").keys
310
- assert_equal %w(Id1 Id3 Id4), tsv.transpose("Values")["vID"]
311
- end
312
-
313
- end
314
-
315
- def test_through_flat
316
- content =<<-EOF
317
- #: :type=:flat
318
- #Row vA
319
- row1 a b Id1
320
- row2 A B Id3
321
- row3 a C Id4
322
- EOF
323
-
324
- TmpFile.with_file(content) do |filename|
325
- tsv = TSV.open(filename, :sep => /\s+/)
326
- tsv.through :key, ["vA"] do |k,v|
327
- assert_equal 3, v.length
328
- end
329
-
330
-
331
- end
332
- end
333
-
334
- end
@@ -1,24 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
- require 'rbbt/tsv'
3
- require 'rbbt/tsv/marshal'
4
- require 'rbbt/util/tmpfile'
5
- require 'test/unit'
6
-
7
- class TestTSVUtil < Test::Unit::TestCase
8
-
9
- def test_marshal
10
- content =<<-EOF
11
- #Id ValueA ValueB OtherID
12
- row1 a|aa|aaa b Id1|Id2
13
- row2 A B Id3
14
- EOF
15
-
16
- TmpFile.with_file(content) do |filename|
17
- tsv = TSV.open(filename, :sep => /\s+/)
18
-
19
- assert TSV === Marshal.load(Marshal.dump(tsv))
20
- assert_equal tsv.to_hash, Marshal.load(Marshal.dump(tsv)).to_hash
21
- assert_equal({1 => 1}, Marshal.load(Marshal.dump({1 => 1})))
22
- end
23
- end
24
- end
@@ -1,20 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
2
- require 'rbbt/tsv'
3
- require 'rbbt/tsv/matrix'
4
-
5
- class TestClass < Test::Unit::TestCase
6
- def test_matrix
7
- tsv = TSV.open <<-EOF, :sep => " ", :type => :list
8
- #X Y Z Type Case
9
- a 2 3 v l
10
- A 4 7 v L
11
- m 2 3 c l
12
- n 4 7 c L
13
- EOF
14
- tsv = TSV.open(tsv.to_s)
15
-
16
- melt = tsv.matrix_melt("Letter", "Value", "Type", "Case")
17
- assert_equal "L", melt["A~Y"][2]
18
- end
19
- end
20
-
@@ -1,7 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
2
- require 'rbbt/tsv'
3
- require 'rbbt/tsv/parallel'
4
-
5
- class TestTSVParallel < Test::Unit::TestCase
6
-
7
- end