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,718 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
2
- require 'rbbt/tsv'
3
- require 'rbbt/tsv/attach'
4
- require 'rbbt'
5
-
6
- class TestAttach < Test::Unit::TestCase
7
- def test_attach_same_key
8
- content1 =<<-EOF
9
- #Id ValueA ValueB
10
- row1 a|aa|aaa b
11
- row2 A B
12
- EOF
13
-
14
- content2 =<<-EOF
15
- #ID ValueB OtherID
16
- row1 b Id1|Id2
17
- row3 B Id3
18
- EOF
19
-
20
- tsv1 = tsv2 = nil
21
- TmpFile.with_file(content1) do |filename|
22
- tsv1 = TSV.open(File.open(filename), :double, :sep => /\s+/)
23
- end
24
-
25
- TmpFile.with_file(content2) do |filename|
26
- tsv2 = TSV.open(File.open(filename), :double, :sep => /\s+/)
27
- end
28
-
29
- tsv1.attach_same_key tsv2, "OtherID"
30
-
31
- assert_equal %w(ValueA ValueB OtherID), tsv1.fields
32
- assert_equal %w(Id1 Id2), tsv1["row1"]["OtherID"]
33
-
34
- TmpFile.with_file(content1) do |filename|
35
- tsv1 = TSV.open(File.open(filename), :double, :sep => /\s+/)
36
- end
37
-
38
- tsv1.attach_same_key tsv2
39
-
40
- assert_equal %w(ValueA ValueB OtherID), tsv1.fields
41
-
42
- tsv1 = tsv2 = nil
43
- TmpFile.with_file(content1) do |filename|
44
- tsv1 = TSV.open(File.open(filename), :list, :sep => /\s+/)
45
- end
46
-
47
- TmpFile.with_file(content2) do |filename|
48
- tsv2 = TSV.open(File.open(filename), :double, :sep => /\s+/)
49
- end
50
-
51
- tsv1.attach_same_key tsv2, "OtherID"
52
-
53
- assert_equal %w(ValueA ValueB OtherID), tsv1.fields
54
- assert_equal "Id1", tsv1["row1"]["OtherID"]
55
- end
56
-
57
- def test_attach_source_field
58
- content1 =<<-EOF
59
- #Id ValueA ValueB
60
- row1 a|aa|aaa b
61
- row2 A B
62
- EOF
63
-
64
- content2 =<<-EOF
65
- #ValueB OtherID
66
- b Id1|Id2
67
- B Id3
68
- EOF
69
-
70
- tsv1 = tsv2 = nil
71
- TmpFile.with_file(content1) do |filename|
72
- tsv1 = TSV.open(File.open(filename), :double, :sep => /\s+/)
73
- end
74
-
75
- TmpFile.with_file(content2) do |filename|
76
- tsv2 = TSV.open(File.open(filename), :double, :sep => /\s+/)
77
- end
78
-
79
- tsv1.attach_source_key tsv2, "ValueB"
80
-
81
- assert_equal %w(ValueA ValueB OtherID), tsv1.fields
82
- assert_equal %w(Id1 Id2), tsv1["row1"]["OtherID"]
83
-
84
- TmpFile.with_file(content1) do |filename|
85
- tsv1 = TSV.open(File.open(filename), :list, :sep => /\s+/)
86
- end
87
-
88
- tsv1.attach_source_key tsv2, "ValueB"
89
-
90
- assert_equal %w(ValueA ValueB OtherID), tsv1.fields
91
- assert_equal "Id1", tsv1["row1"]["OtherID"]
92
- end
93
-
94
- def test_attach_index
95
- content1 =<<-EOF
96
- #Id ValueA ValueB
97
- row1 a|aa|aaa b
98
- row2 A B
99
- EOF
100
-
101
- content2 =<<-EOF
102
- #ValueE OtherID
103
- e Id1|Id2
104
- E Id3
105
- EOF
106
-
107
- content_index =<<-EOF
108
- #Id ValueE
109
- row1 e
110
- row2 E
111
- EOF
112
-
113
- tsv1 = tsv2 = index = nil
114
- TmpFile.with_file(content1) do |filename|
115
- tsv1 = TSV.open(File.open(filename), :double, :sep => /\s+/)
116
- end
117
-
118
- TmpFile.with_file(content2) do |filename|
119
- tsv2 = TSV.open(File.open(filename), :double, :sep => /\s+/)
120
- end
121
-
122
- TmpFile.with_file(content_index) do |filename|
123
- index = TSV.open(File.open(filename), :flat, :sep => /\s+/)
124
- end
125
-
126
- tsv1.attach_index tsv2, index
127
-
128
- assert_equal %w(ValueA ValueB OtherID), tsv1.fields
129
- assert_equal %w(Id1 Id2), tsv1["row1"]["OtherID"]
130
-
131
- TmpFile.with_file(content1) do |filename|
132
- tsv1 = TSV.open(File.open(filename), :list, :sep => /\s+/)
133
- end
134
-
135
- tsv1.attach_index tsv2, index
136
-
137
- assert_equal %w(ValueA ValueB OtherID), tsv1.fields
138
- assert_equal "Id1", tsv1["row1"]["OtherID"]
139
- end
140
-
141
- def test_attach
142
- content1 =<<-EOF
143
- #Id ValueA ValueB
144
- row1 a|aa|aaa b
145
- row2 A B
146
- EOF
147
-
148
- content2 =<<-EOF
149
- #Id ValueB OtherID
150
- row1 b Id1|Id2
151
- row3 B Id3
152
- EOF
153
-
154
- content3 =<<-EOF
155
- #ValueB OtherID
156
- b Id1|Id2
157
- B Id3
158
- EOF
159
- tsv1 = tsv2 = tsv3 = nil
160
- TmpFile.with_file(content1) do |filename|
161
- tsv1 = TSV.open(File.open(filename), :double, :sep => /\s+/)
162
- end
163
-
164
- TmpFile.with_file(content2) do |filename|
165
- tsv2 = TSV.open(File.open(filename), :double, :sep => /\s+/)
166
- end
167
-
168
- TmpFile.with_file(content3) do |filename|
169
- tsv3 = TSV.open(File.open(filename), :double, :sep => /\s+/)
170
- end
171
-
172
- tsv1.attach tsv2, :fields => "OtherID"
173
-
174
- assert_equal %w(ValueA ValueB OtherID), tsv1.fields
175
- assert_equal %w(Id1 Id2), tsv1["row1"]["OtherID"]
176
-
177
- TmpFile.with_file(content1) do |filename|
178
- tsv1 = TSV.open(File.open(filename), :double, :sep => /\s+/)
179
- end
180
-
181
- tsv1.attach tsv3
182
-
183
- assert_equal %w(ValueA ValueB OtherID), tsv1.fields
184
- assert_equal %w(Id1 Id2), tsv1["row1"]["OtherID"]
185
-
186
- end
187
-
188
- def test_attach_using_index
189
- content1 =<<-EOF
190
- #: :sep=/\\s+/
191
- #Id ValueA ValueB
192
- row1 a|aa|aaa b
193
- row2 A B
194
- EOF
195
-
196
- content2 =<<-EOF
197
- #: :sep=/\\s+/
198
- #ValueE OtherID
199
- e Id1|Id2
200
- E Id3
201
- EOF
202
-
203
- content_index =<<-EOF
204
- #: :sep=/\\s+/
205
- #Id ValueE
206
- row1 e
207
- row2 E
208
- EOF
209
-
210
- Rbbt.claim Rbbt.tmp.test.test1.data, :string, content1
211
- Rbbt.claim Rbbt.tmp.test.test2.data, :string, content2
212
- Rbbt.claim Rbbt.tmp.test.test2.identifiers, :string, content_index
213
-
214
- tsv1 = tsv2 = nil
215
-
216
- tsv1 = Rbbt.tmp.test.test1.data.produce(true).tsv :double, :sep => /\s+/
217
- tsv2 = Rbbt.tmp.test.test2.data.produce(true).tsv :double, :sep => /\s+/
218
- Log.tsv tsv2
219
-
220
- tsv2.identifiers = Rbbt.tmp.test.test2.identifiers.produce.find #.to_s
221
-
222
- tsv1.attach tsv2, :fields => ["OtherID"] #, :persist_input => true
223
-
224
- assert_equal tsv1.fields, %w(ValueA ValueB OtherID)
225
- assert_equal %w(Id1 Id2), tsv1["row1"]["OtherID"]
226
- end
227
-
228
- def test_find_path
229
- content1 =<<-EOF
230
- #: :sep=/\\s+/#:case_insensitive=false
231
- #Id ValueA ValueB
232
- row1 a|aa|aaa b
233
- row2 A B
234
- EOF
235
-
236
- content2 =<<-EOF
237
- #: :sep=/\\s+/#:case_insensitive=false
238
- #OtherID ValueE
239
- Id1|Id2 e
240
- Id3 E
241
- EOF
242
-
243
- content_identifiers =<<-EOF
244
- #: :sep=/\\s+/#:case_insensitive=false
245
- #Id ValueE
246
- row1 e
247
- row2 E
248
- EOF
249
-
250
- tsv1 = tsv2 = identifiers = nil
251
- TmpFile.with_file(content1) do |filename|
252
- tsv1 = TSV.open(Path.setup(filename), :key => "Id")
253
- end
254
-
255
- TmpFile.with_file(content2) do |filename|
256
- tsv2 = TSV.open(Path.setup(filename), :double)
257
- end
258
-
259
- TmpFile.with_file(content_identifiers) do |filename|
260
- identifiers = TSV.open(Path.setup(filename), :flat, :sep => /\s+/)
261
- end
262
-
263
- tsv1.identifiers = identifiers
264
-
265
- tsv1.attach tsv2
266
-
267
- assert_equal %w(ValueA ValueB ValueE), tsv1.fields
268
- end
269
-
270
- def test_merge_different_rows
271
- file1 =<<-EOF
272
- row6 dd dd ee
273
- row1 a b c
274
- row2 A B C
275
- row3 1 2 3
276
- EOF
277
- file2 =<<-EOF
278
- row20 rr rr
279
- row1 d e
280
- row2 D E
281
- row4 x y z
282
- EOF
283
- result =<<-EOF
284
- row1 a b c d e
285
- row2 A B C D E
286
- row20 rr rr
287
- row3 1 2 3
288
- row4 x y z
289
- row6 dd dd ee
290
- EOF
291
-
292
- TmpFile.with_file do |f|
293
- TSV.merge_different_fields(StringIO.new(file1), StringIO.new(file2), f, :sep => " ")
294
- assert_equal result, Open.read(f)
295
- end
296
- end
297
-
298
- def test_merge_different_rows_tsv
299
- file1 =<<-EOF
300
- row6 dd dd ee
301
- row1 a b c
302
- row2 A B C
303
- row3 1 2 3
304
- EOF
305
- file2 =<<-EOF
306
- row20 rr rr
307
- row1 d e
308
- row2 D E
309
- row4 x y
310
- EOF
311
- result =<<-EOF
312
- row1 a b c d e
313
- row2 A B C D E
314
- row20 rr rr
315
- row3 1 2 3
316
- row4 x y
317
- row6 dd dd ee
318
- EOF
319
-
320
- TmpFile.with_file do |f|
321
- tsv1 = TSV.open StringIO.new(file1), :sep => " "
322
- tsv2 = TSV.open StringIO.new(file2), :sep => " "
323
- tsv_r = tsv1.merge_different_fields tsv2
324
- assert_equal result, tsv_r.to_s(tsv_r.keys.sort, true).gsub(/\t/,' ')
325
- end
326
- end
327
-
328
- def test_merge_different_rows_split_lines
329
- file1 =<<-EOF
330
- #ID,letterA,letterB,letterC
331
- row6,dd,dd,ee
332
- row1,a,b,c
333
- row1,aa,bb,cc
334
- row2,A,B,C
335
- row3,1,2,3
336
- EOF
337
- file2 =<<-EOF
338
- #ID,letterD,letterE
339
- row20,rr,rr
340
- row1,d,e
341
- row2,D,E
342
- row4,x,y
343
- EOF
344
-
345
- # Might be slightly different ...
346
- result1 =<<-EOF
347
- #: :sep=,
348
- #ID,letterA,letterB,letterC,letterD,letterE
349
- row1,aa|a,bb|b,cc|c,d,e
350
- row2,A,B,C,D,E
351
- row20,,,,rr,rr
352
- row3,1,2,3,,
353
- row4,,,,x,y
354
- row6,dd,dd,ee,,
355
- EOF
356
- result2 =<<-EOF
357
- #: :sep=,
358
- #ID,letterA,letterB,letterC,letterD,letterE
359
- row1,a|aa,b|bb,c|cc,d,e
360
- row2,A,B,C,D,E
361
- row20,,,,rr,rr
362
- row3,1,2,3,,
363
- row4,,,,x,y
364
- row6,dd,dd,ee,,
365
- EOF
366
-
367
- TmpFile.with_file do |f|
368
- TSV.merge_different_fields StringIO.new(file1), StringIO.new(file2), f, :sep => ','
369
- # ... so check for either
370
- assert(Open.read(f) == result1 || Open.read(f) == result2)
371
- end
372
- end
373
-
374
- def test_merge_different_rows_split_lines_tsv
375
- file1 =<<-EOF
376
- row6,dd,dd,ee
377
- row1,a,b,c
378
- row1,aa,bb,cc
379
- row2,A,B,C
380
- row3,1,2,3
381
- EOF
382
- file2 =<<-EOF
383
- row20,rr,rr
384
- row1,d,e
385
- row2,D,E
386
- row4,x,y
387
- EOF
388
- result =<<-EOF
389
- row1,aa|a,bb|b,cc|c,d,e
390
- row2,A,B,C,D,E
391
- row20,,,,rr,rr
392
- row3,1,2,3,,
393
- row4,,,,x,y
394
- row6,dd,dd,ee,,
395
- EOF
396
-
397
- TmpFile.with_file do |f|
398
- data1 = TSV.open StringIO.new(file1), :sep => ',', :merge => true
399
- data2 = TSV.open StringIO.new(file2), :sep => ',', :merge => true
400
- data3 = data1.merge_different_fields(data2)
401
- data3.each do |key, list|
402
- list.each do |l| l.replace l.sort_by{|v| v.length}.reverse end
403
- end
404
-
405
- assert_equal result, data3.to_s(:sort, true).gsub(/\t/,',')
406
- end
407
- end
408
-
409
- def test_merge_rows
410
- file1 =<<-EOF
411
- #ID,letterA,letterB,letterC
412
- row1,a,b,c
413
- row1,aa,bb,cc
414
- row2,A,B,C
415
- row3,1,2,3
416
- EOF
417
- TmpFile.with_file(file1) do |input|
418
- TmpFile.with_file() do |output|
419
- TSV.merge_row_fields Open.open(input), output, :sep => ','
420
- assert Open.read(output) =~ /^#ID,letterA,letterB,letterC$/
421
- assert Open.read(output).index "a|aa"
422
- end
423
- end
424
-
425
-
426
- end
427
-
428
- def test_one2one
429
- content1 =<<-EOF
430
- #Id ValueA ValueB
431
- row1 a|aa|aaa b
432
- row2 A B
433
- row3 A b|bb
434
- EOF
435
-
436
- content2 =<<-EOF
437
- #ValueB OtherID
438
- b Id1|Id2
439
- B Id3
440
- bb Id4
441
- EOF
442
- tsv1 = tsv2 = nil
443
- TmpFile.with_file(content1) do |filename|
444
- tsv1 = TSV.open(File.open(filename), :double, :sep => /\s+/)
445
- end
446
-
447
- TmpFile.with_file(content2) do |filename|
448
- tsv2 = TSV.open(File.open(filename), :double, :sep => /\s+/)
449
- end
450
-
451
- tsv1.attach tsv2, :one2one => true
452
-
453
- assert_equal %w(ValueA ValueB OtherID), tsv1.fields
454
- assert_equal %w(Id1 Id4), tsv1["row3"]["OtherID"]
455
- end
456
-
457
- def test_attach_flat
458
- content1 =<<-EOF
459
- #Id ValueA ValueB
460
- row1 a|aa|aaa b
461
- row2 A B
462
- EOF
463
-
464
- content2 =<<-EOF
465
- #ValueA OtherID
466
- a Id1|Id2
467
- A Id3
468
- EOF
469
-
470
- tsv1 = tsv2 = index = nil
471
- TmpFile.with_file(content1) do |filename|
472
- tsv1 = TSV.open(File.open(filename), :flat, :fields => ["ValueA"], :sep => /\s+/)
473
- end
474
-
475
- TmpFile.with_file(content2) do |filename|
476
- tsv2 = TSV.open(File.open(filename), :double, :sep => /\s+/)
477
- end
478
-
479
- res = tsv1.attach tsv2, :fields => ["OtherID"]
480
- assert res["row2"].include? "Id3"
481
- assert ! res["row2"].include?("b")
482
- end
483
-
484
- def test_attached_parenthesis
485
-
486
- content1 =<<-EOF
487
- #Id,ValueA,bar (ValueB)
488
- row1,a|aa|aaa,b
489
- row2,A,B
490
- EOF
491
-
492
- content2 =<<-EOF
493
- #foo (ValueA),OtherID
494
- a,Id1|Id2
495
- A,Id3
496
- EOF
497
-
498
- content3 =<<-EOF
499
- #ValueB,ValueC
500
- b,c
501
- B,C
502
- EOF
503
-
504
- content4 =<<-EOF
505
- #foobar (Id),ValueD
506
- row1,d
507
- row5,D
508
- EOF
509
-
510
- tsv1 = tsv2 = tsv3 = tsv4 = index = nil
511
- TmpFile.with_file(content1) do |filename|
512
- tsv1 = TSV.open(File.open(filename), :double, :sep => ',')
513
- end
514
-
515
- TmpFile.with_file(content2) do |filename|
516
- tsv2 = TSV.open(File.open(filename), :double, :sep => ',')
517
- end
518
-
519
- TmpFile.with_file(content3) do |filename|
520
- tsv3 = TSV.open(File.open(filename), :double, :sep => ',')
521
- end
522
-
523
- TmpFile.with_file(content4) do |filename|
524
- tsv4 = TSV.open(File.open(filename), :double, :sep => ',')
525
- end
526
-
527
-
528
- assert_equal tsv1.attach(tsv2)["row1"]["OtherID"], %w(Id1 Id2)
529
- assert_equal tsv1.attach(tsv2)["row2"]["OtherID"], %w(Id3)
530
-
531
- assert_equal tsv1.attach(tsv4)["row1"]["ValueD"], %w(d)
532
- assert_equal tsv4.attach(tsv1)["row1"]["bar (ValueB)"], %w(b)
533
- assert_equal tsv3.attach(tsv1)["b"]["ValueD"], %w(d)
534
- end
535
-
536
- def test_attach_single_nils
537
- content1 =<<-EOF
538
- #Id,ValueA
539
- row1,
540
- row2,AA
541
- EOF
542
- content2 =<<-EOF
543
- #Id,ValueB
544
- row1,B
545
- row2,BB
546
- EOF
547
- content3 =<<-EOF
548
- #Id,ValueC
549
- row1,
550
- row2,CC
551
- EOF
552
-
553
- tsv1 = tsv2 = tsv3 = tsv4 = index = nil
554
- TmpFile.with_file(content1) do |filename|
555
- tsv1 = TSV.open(File.open(filename), :double, :sep => ',', :type => :single)
556
- tsv1.keys.each{|k| tsv1[k] = nil if tsv1[k] == ""}
557
- end
558
-
559
- TmpFile.with_file(content2) do |filename|
560
- tsv2 = TSV.open(File.open(filename), :double, :sep => ',', :type => :single)
561
- tsv2.keys.each{|k| tsv2[k] = nil if tsv2[k] == ""}
562
- end
563
-
564
- TmpFile.with_file(content3) do |filename|
565
- tsv3 = TSV.open(File.open(filename), :double, :sep => ',', :type => :single)
566
- tsv3.keys.each{|k| tsv3[k] = nil if tsv3[k] == ""}
567
- end
568
-
569
- assert_equal [nil, "B", nil], tsv1.attach(tsv2, :complete => true).attach(tsv3, :complete => true)["row1"]
570
- end
571
-
572
- def test_attach_index_both_non_key
573
- content1 =<<-EOF
574
- #: :sep=/\\s+/
575
- #Id ValueA ValueB
576
- row1 a|aa|aaa b
577
- row2 A B
578
- EOF
579
-
580
- content2 =<<-EOF
581
- #: :sep=/\\s+/
582
- #ValueE OtherID
583
- e Id1|Id2
584
- E Id3
585
- EOF
586
-
587
- content_index =<<-EOF
588
- #: :sep=/\\s+/
589
- #ValueA OtherID
590
- a Id1
591
- A Id3
592
- EOF
593
-
594
- Rbbt.claim Rbbt.tmp.test.test1.data, :string, content1
595
- Rbbt.claim Rbbt.tmp.test.test2.data, :string, content2
596
- Rbbt.claim Rbbt.tmp.test.test2.identifiers, :string, content_index
597
-
598
- tsv1 = tsv2 = nil
599
-
600
- tsv1 = Rbbt.tmp.test.test1.data.produce(true).tsv :double, :sep => /\s+/
601
- tsv2 = Rbbt.tmp.test.test2.data.produce(true).tsv :double, :sep => /\s+/
602
-
603
- tsv2.identifiers = Rbbt.tmp.test.test2.identifiers.produce(true).produce.find #.to_s
604
-
605
- tsv1.attach tsv2, :fields => ["ValueE"] #, :persist_input => true
606
- Log.tsv tsv1
607
- ppp tsv1
608
-
609
- end
610
-
611
- def test_attach_both_non_key
612
- content1 =<<-EOF
613
- #: :sep=/\\s+/
614
- #Id ValueA ValueB
615
- row1 a|aa|aaa b
616
- row2 A B
617
- EOF
618
-
619
- content2 =<<-EOF
620
- #: :sep=/\\s+/
621
- #ValueE ValueB
622
- e b
623
- E B
624
- EOF
625
- Rbbt.claim Rbbt.tmp.test.test1.data, :string, content1
626
- Rbbt.claim Rbbt.tmp.test.test2.data, :string, content2
627
-
628
- tsv1 = tsv2 = nil
629
-
630
- tsv1 = Rbbt.tmp.test.test1.data.produce(true).tsv :double, :sep => /\s+/
631
- tsv2 = Rbbt.tmp.test.test2.data.produce(true).tsv :double, :sep => /\s+/
632
-
633
- tsv1.attach tsv2, :fields => ["ValueE"] #, :persist_input => true
634
- Log.tsv tsv1
635
-
636
- end
637
-
638
- def test_attach_complete
639
- content1 =<<-EOF
640
- #: :sep=/\\s+/
641
- #Id ValueA
642
- row1 a|aa|aaa
643
- row2 A
644
- EOF
645
-
646
- content2 =<<-EOF
647
- #: :sep=/\\s+/
648
- #Id ValueB
649
- row1 b
650
- row3 C
651
- EOF
652
- Rbbt.claim Rbbt.tmp.test.test1.data, :string, content1
653
- Rbbt.claim Rbbt.tmp.test.test2.data, :string, content2
654
-
655
- tsv1 = tsv2 = nil
656
-
657
- tsv1 = Rbbt.tmp.test.test1.data.produce(true).tsv :double, :sep => /\s+/
658
- tsv2 = Rbbt.tmp.test.test2.data.produce(true).tsv :double, :sep => /\s+/
659
-
660
- tsv1.attach tsv2, :complete => true
661
- assert_equal [[], ["C"]], tsv1["row3"]
662
-
663
- tsv1 = Rbbt.tmp.test.test1.data.produce(true).tsv :double, :sep => /\s+/
664
- tsv2 = Rbbt.tmp.test.test2.data.produce(true).tsv :double, :sep => /\s+/
665
-
666
- ppp tsv1.attach tsv2, :complete => ["AA"]
667
- tsv1.attach tsv2, :complete => ["AA"]
668
- assert_equal [["AA"], ["C"]], tsv1["row3"]
669
- end
670
-
671
- def test_attach_complete_identifiers
672
- content1 =<<-EOF
673
- #: :sep=/\\s+/
674
- #Id ValueA
675
- row1 a|aa|aaa
676
- row2 A
677
- EOF
678
-
679
- content2 =<<-EOF
680
- #: :sep=/\\s+/
681
- #Id2 ValueB
682
- ROW_1 b
683
- ROW_2 C
684
- EOF
685
-
686
- identifiers =<<-EOF
687
- #: :sep=/\\s+/
688
- #Id Id2
689
- row1 ROW_1
690
- row2 ROW_2
691
- row3 ROW_3
692
- EOF
693
- Rbbt.claim Rbbt.tmp.test.test1.data, :string, content1
694
- Rbbt.claim Rbbt.tmp.test.test2.data, :string, content2
695
- Rbbt.claim Rbbt.tmp.test.identifiers.data, :string, identifiers
696
-
697
- tsv1 = tsv2 = nil
698
-
699
- tsv1 = Rbbt.tmp.test.test1.data.produce(true).tsv :double, :sep => /\s+/
700
- tsv2 = Rbbt.tmp.test.test2.data.produce(true).tsv :double, :sep => /\s+/
701
- ids = Rbbt.tmp.test.identifiers.data.produce(true).tsv :double, :sep => /\s+/
702
-
703
- tsv1.identifiers = ids
704
-
705
- tsv1.attach tsv2
706
- assert_equal [["A"], ["C"]], tsv1["row2"]
707
-
708
- tsv1 = Rbbt.tmp.test.test1.data.produce(true).tsv :double, :sep => /\s+/
709
- tsv2 = Rbbt.tmp.test.test2.data.produce(true).tsv :double, :sep => /\s+/
710
- ids = Rbbt.tmp.test.identifiers.data.produce(true).tsv :double, :sep => /\s+/
711
-
712
- tsv1.identifiers = ids
713
-
714
- tsv1.attach tsv2, :complete => true
715
- assert_equal [["A"], ["C"]], tsv1["row2"]
716
- end
717
- end
718
-