rbbt-util 5.42.0 → 5.44.0

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