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.
- checksums.yaml +4 -4
- data/lib/rbbt/association/util.rb +1 -1
- data/lib/rbbt/hpc/batch.rb +19 -17
- data/lib/rbbt/tsv/accessor.rb +6 -11
- data/lib/rbbt/tsv/dumper.rb +21 -10
- data/lib/rbbt/tsv/index.rb +2 -1
- data/lib/rbbt/util/misc/math.rb +0 -1
- data/lib/rbbt/util/open.rb +1 -1
- data/lib/rbbt/workflow/step/info.rb +1 -0
- data/lib/rbbt/workflow/step.rb +2 -1
- data/python/rbbt/__init__.py +2 -2
- data/share/rbbt_commands/workflow/task +1 -1
- metadata +4 -220
- data/test/rbbt/annotations/test_util.rb +0 -43
- data/test/rbbt/association/test_database.rb +0 -87
- data/test/rbbt/association/test_index.rb +0 -127
- data/test/rbbt/association/test_item.rb +0 -15
- data/test/rbbt/association/test_open.rb +0 -63
- data/test/rbbt/association/test_util.rb +0 -108
- data/test/rbbt/entity/test_identifiers.rb +0 -34
- data/test/rbbt/hpc/orchestrate/test_batches.rb +0 -70
- data/test/rbbt/hpc/orchestrate/test_chains.rb +0 -108
- data/test/rbbt/hpc/orchestrate/test_rules.rb +0 -59
- data/test/rbbt/hpc/test_batch.rb +0 -64
- data/test/rbbt/hpc/test_hpc_test_workflows.rb +0 -0
- data/test/rbbt/hpc/test_orchestrate.rb +0 -144
- data/test/rbbt/hpc/test_pbs.rb +0 -43
- data/test/rbbt/hpc/test_slurm.rb +0 -28
- data/test/rbbt/knowledge_base/test_enrichment.rb +0 -50
- data/test/rbbt/knowledge_base/test_entity.rb +0 -62
- data/test/rbbt/knowledge_base/test_query.rb +0 -46
- data/test/rbbt/knowledge_base/test_registry.rb +0 -74
- data/test/rbbt/knowledge_base/test_syndicate.rb +0 -48
- data/test/rbbt/knowledge_base/test_traverse.rb +0 -133
- data/test/rbbt/persist/test_tsv.rb +0 -88
- data/test/rbbt/persist/tsv/test_cdb.rb +0 -18
- data/test/rbbt/persist/tsv/test_kyotocabinet.rb +0 -27
- data/test/rbbt/persist/tsv/test_leveldb.rb +0 -18
- data/test/rbbt/persist/tsv/test_lmdb.rb +0 -20
- data/test/rbbt/persist/tsv/test_sharder.rb +0 -164
- data/test/rbbt/persist/tsv/test_tokyocabinet.rb +0 -262
- data/test/rbbt/resource/test_path.rb +0 -49
- data/test/rbbt/test_annotations.rb +0 -167
- data/test/rbbt/test_association.rb +0 -103
- data/test/rbbt/test_entity.rb +0 -252
- data/test/rbbt/test_fix_width_table.rb +0 -135
- data/test/rbbt/test_knowledge_base.rb +0 -226
- data/test/rbbt/test_monitor.rb +0 -11
- data/test/rbbt/test_packed_index.rb +0 -68
- data/test/rbbt/test_persist.rb +0 -85
- data/test/rbbt/test_resource.rb +0 -110
- data/test/rbbt/test_tsv.rb +0 -669
- data/test/rbbt/test_workflow.rb +0 -609
- data/test/rbbt/tsv/parallel/test_through.rb +0 -40
- data/test/rbbt/tsv/parallel/test_traverse.rb +0 -456
- data/test/rbbt/tsv/test_accessor.rb +0 -319
- data/test/rbbt/tsv/test_attach.rb +0 -715
- data/test/rbbt/tsv/test_change_id.rb +0 -61
- data/test/rbbt/tsv/test_csv.rb +0 -49
- data/test/rbbt/tsv/test_excel.rb +0 -171
- data/test/rbbt/tsv/test_field_index.rb +0 -19
- data/test/rbbt/tsv/test_filter.rb +0 -187
- data/test/rbbt/tsv/test_index.rb +0 -308
- data/test/rbbt/tsv/test_manipulate.rb +0 -334
- data/test/rbbt/tsv/test_marshal.rb +0 -24
- data/test/rbbt/tsv/test_matrix.rb +0 -20
- data/test/rbbt/tsv/test_parallel.rb +0 -7
- data/test/rbbt/tsv/test_parser.rb +0 -101
- data/test/rbbt/tsv/test_stream.rb +0 -253
- data/test/rbbt/tsv/test_util.rb +0 -52
- data/test/rbbt/util/R/test_eval.rb +0 -43
- data/test/rbbt/util/R/test_model.rb +0 -128
- data/test/rbbt/util/R/test_plot.rb +0 -38
- data/test/rbbt/util/concurrency/processes/test_socket.rb +0 -70
- data/test/rbbt/util/concurrency/test_processes.rb +0 -192
- data/test/rbbt/util/concurrency/test_threads.rb +0 -40
- data/test/rbbt/util/log/test_progress.rb +0 -111
- data/test/rbbt/util/misc/test_bgzf.rb +0 -48
- data/test/rbbt/util/misc/test_communication.rb +0 -13
- data/test/rbbt/util/misc/test_development.rb +0 -26
- data/test/rbbt/util/misc/test_format.rb +0 -10
- data/test/rbbt/util/misc/test_indiferent_hash.rb +0 -14
- data/test/rbbt/util/misc/test_lock.rb +0 -77
- data/test/rbbt/util/misc/test_multipart_payload.rb +0 -202
- data/test/rbbt/util/misc/test_omics.rb +0 -116
- data/test/rbbt/util/misc/test_pipes.rb +0 -343
- data/test/rbbt/util/misc/test_serialize.rb +0 -24
- data/test/rbbt/util/python/test_util.rb +0 -25
- data/test/rbbt/util/simpleopt/test_get.rb +0 -12
- data/test/rbbt/util/simpleopt/test_parse.rb +0 -10
- data/test/rbbt/util/simpleopt/test_setup.rb +0 -76
- data/test/rbbt/util/test_R.rb +0 -37
- data/test/rbbt/util/test_chain_methods.rb +0 -22
- data/test/rbbt/util/test_cmd.rb +0 -87
- data/test/rbbt/util/test_colorize.rb +0 -22
- data/test/rbbt/util/test_concurrency.rb +0 -6
- data/test/rbbt/util/test_config.rb +0 -69
- data/test/rbbt/util/test_excel2tsv.rb +0 -10
- data/test/rbbt/util/test_filecache.rb +0 -36
- data/test/rbbt/util/test_log.rb +0 -52
- data/test/rbbt/util/test_migrate.rb +0 -34
- data/test/rbbt/util/test_misc.rb +0 -728
- data/test/rbbt/util/test_open.rb +0 -200
- data/test/rbbt/util/test_procpath.rb +0 -23
- data/test/rbbt/util/test_python.rb +0 -144
- data/test/rbbt/util/test_semaphore.rb +0 -36
- data/test/rbbt/util/test_simpleDSL.rb +0 -55
- data/test/rbbt/util/test_simpleopt.rb +0 -11
- data/test/rbbt/util/test_ssh.rb +0 -10
- data/test/rbbt/util/test_tmpfile.rb +0 -32
- data/test/rbbt/workflow/step/test_dependencies.rb +0 -295
- data/test/rbbt/workflow/step/test_save_load_inputs.rb +0 -136
- data/test/rbbt/workflow/test_doc.rb +0 -30
- data/test/rbbt/workflow/test_remote_workflow.rb +0 -99
- data/test/rbbt/workflow/test_schedule.rb +0 -0
- data/test/rbbt/workflow/test_step.rb +0 -231
- data/test/rbbt/workflow/test_task.rb +0 -85
- data/test/rbbt/workflow/util/test_archive.rb +0 -27
- data/test/rbbt/workflow/util/test_data.rb +0 -67
- data/test/rbbt/workflow/util/test_orchestrator.rb +0 -263
- data/test/test_helper.rb +0 -114
@@ -1,715 +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
|
-
|
219
|
-
tsv2.identifiers = Rbbt.tmp.test.test2.identifiers.produce.find #.to_s
|
220
|
-
|
221
|
-
tsv1.attach tsv2, :fields => ["OtherID"] #, :persist_input => true
|
222
|
-
|
223
|
-
assert_equal tsv1.fields, %w(ValueA ValueB OtherID)
|
224
|
-
assert_equal %w(Id1 Id2), tsv1["row1"]["OtherID"]
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_find_path
|
228
|
-
content1 =<<-EOF
|
229
|
-
#: :sep=/\\s+/#:case_insensitive=false
|
230
|
-
#Id ValueA ValueB
|
231
|
-
row1 a|aa|aaa b
|
232
|
-
row2 A B
|
233
|
-
EOF
|
234
|
-
|
235
|
-
content2 =<<-EOF
|
236
|
-
#: :sep=/\\s+/#:case_insensitive=false
|
237
|
-
#OtherID ValueE
|
238
|
-
Id1|Id2 e
|
239
|
-
Id3 E
|
240
|
-
EOF
|
241
|
-
|
242
|
-
content_identifiers =<<-EOF
|
243
|
-
#: :sep=/\\s+/#:case_insensitive=false
|
244
|
-
#Id ValueE
|
245
|
-
row1 e
|
246
|
-
row2 E
|
247
|
-
EOF
|
248
|
-
|
249
|
-
tsv1 = tsv2 = identifiers = nil
|
250
|
-
TmpFile.with_file(content1) do |filename|
|
251
|
-
tsv1 = TSV.open(Path.setup(filename), :key => "Id")
|
252
|
-
end
|
253
|
-
|
254
|
-
TmpFile.with_file(content2) do |filename|
|
255
|
-
tsv2 = TSV.open(Path.setup(filename), :double)
|
256
|
-
end
|
257
|
-
|
258
|
-
TmpFile.with_file(content_identifiers) do |filename|
|
259
|
-
identifiers = TSV.open(Path.setup(filename), :flat, :sep => /\s+/)
|
260
|
-
end
|
261
|
-
|
262
|
-
tsv1.identifiers = identifiers
|
263
|
-
|
264
|
-
tsv1.attach tsv2
|
265
|
-
|
266
|
-
assert_equal %w(ValueA ValueB ValueE), tsv1.fields
|
267
|
-
end
|
268
|
-
|
269
|
-
def test_merge_different_rows
|
270
|
-
file1 =<<-EOF
|
271
|
-
row6 dd dd ee
|
272
|
-
row1 a b c
|
273
|
-
row2 A B C
|
274
|
-
row3 1 2 3
|
275
|
-
EOF
|
276
|
-
file2 =<<-EOF
|
277
|
-
row20 rr rr
|
278
|
-
row1 d e
|
279
|
-
row2 D E
|
280
|
-
row4 x y z
|
281
|
-
EOF
|
282
|
-
result =<<-EOF
|
283
|
-
row1 a b c d e
|
284
|
-
row2 A B C D E
|
285
|
-
row20 rr rr
|
286
|
-
row3 1 2 3
|
287
|
-
row4 x y z
|
288
|
-
row6 dd dd ee
|
289
|
-
EOF
|
290
|
-
|
291
|
-
TmpFile.with_file do |f|
|
292
|
-
TSV.merge_different_fields(StringIO.new(file1), StringIO.new(file2), f, :sep => " ")
|
293
|
-
assert_equal result, Open.read(f)
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
def test_merge_different_rows_tsv
|
298
|
-
file1 =<<-EOF
|
299
|
-
row6 dd dd ee
|
300
|
-
row1 a b c
|
301
|
-
row2 A B C
|
302
|
-
row3 1 2 3
|
303
|
-
EOF
|
304
|
-
file2 =<<-EOF
|
305
|
-
row20 rr rr
|
306
|
-
row1 d e
|
307
|
-
row2 D E
|
308
|
-
row4 x y
|
309
|
-
EOF
|
310
|
-
result =<<-EOF
|
311
|
-
row1 a b c d e
|
312
|
-
row2 A B C D E
|
313
|
-
row20 rr rr
|
314
|
-
row3 1 2 3
|
315
|
-
row4 x y
|
316
|
-
row6 dd dd ee
|
317
|
-
EOF
|
318
|
-
|
319
|
-
TmpFile.with_file do |f|
|
320
|
-
tsv1 = TSV.open StringIO.new(file1), :sep => " "
|
321
|
-
tsv2 = TSV.open StringIO.new(file2), :sep => " "
|
322
|
-
tsv_r = tsv1.merge_different_fields tsv2
|
323
|
-
assert_equal result, tsv_r.to_s(tsv_r.keys.sort, true).gsub(/\t/,' ')
|
324
|
-
end
|
325
|
-
end
|
326
|
-
|
327
|
-
def test_merge_different_rows_split_lines
|
328
|
-
file1 =<<-EOF
|
329
|
-
#ID,letterA,letterB,letterC
|
330
|
-
row6,dd,dd,ee
|
331
|
-
row1,a,b,c
|
332
|
-
row1,aa,bb,cc
|
333
|
-
row2,A,B,C
|
334
|
-
row3,1,2,3
|
335
|
-
EOF
|
336
|
-
file2 =<<-EOF
|
337
|
-
#ID,letterD,letterE
|
338
|
-
row20,rr,rr
|
339
|
-
row1,d,e
|
340
|
-
row2,D,E
|
341
|
-
row4,x,y
|
342
|
-
EOF
|
343
|
-
|
344
|
-
# Might be slightly different ...
|
345
|
-
result1 =<<-EOF
|
346
|
-
#: :sep=,
|
347
|
-
#ID,letterA,letterB,letterC,letterD,letterE
|
348
|
-
row1,aa|a,bb|b,cc|c,d,e
|
349
|
-
row2,A,B,C,D,E
|
350
|
-
row20,,,,rr,rr
|
351
|
-
row3,1,2,3,,
|
352
|
-
row4,,,,x,y
|
353
|
-
row6,dd,dd,ee,,
|
354
|
-
EOF
|
355
|
-
result2 =<<-EOF
|
356
|
-
#: :sep=,
|
357
|
-
#ID,letterA,letterB,letterC,letterD,letterE
|
358
|
-
row1,a|aa,b|bb,c|cc,d,e
|
359
|
-
row2,A,B,C,D,E
|
360
|
-
row20,,,,rr,rr
|
361
|
-
row3,1,2,3,,
|
362
|
-
row4,,,,x,y
|
363
|
-
row6,dd,dd,ee,,
|
364
|
-
EOF
|
365
|
-
|
366
|
-
TmpFile.with_file do |f|
|
367
|
-
TSV.merge_different_fields StringIO.new(file1), StringIO.new(file2), f, :sep => ','
|
368
|
-
# ... so check for either
|
369
|
-
assert(Open.read(f) == result1 || Open.read(f) == result2)
|
370
|
-
end
|
371
|
-
end
|
372
|
-
|
373
|
-
def test_merge_different_rows_split_lines_tsv
|
374
|
-
file1 =<<-EOF
|
375
|
-
row6,dd,dd,ee
|
376
|
-
row1,a,b,c
|
377
|
-
row1,aa,bb,cc
|
378
|
-
row2,A,B,C
|
379
|
-
row3,1,2,3
|
380
|
-
EOF
|
381
|
-
file2 =<<-EOF
|
382
|
-
row20,rr,rr
|
383
|
-
row1,d,e
|
384
|
-
row2,D,E
|
385
|
-
row4,x,y
|
386
|
-
EOF
|
387
|
-
result =<<-EOF
|
388
|
-
row1,aa|a,bb|b,cc|c,d,e
|
389
|
-
row2,A,B,C,D,E
|
390
|
-
row20,,,,rr,rr
|
391
|
-
row3,1,2,3,,
|
392
|
-
row4,,,,x,y
|
393
|
-
row6,dd,dd,ee,,
|
394
|
-
EOF
|
395
|
-
|
396
|
-
TmpFile.with_file do |f|
|
397
|
-
data1 = TSV.open StringIO.new(file1), :sep => ',', :merge => true
|
398
|
-
data2 = TSV.open StringIO.new(file2), :sep => ',', :merge => true
|
399
|
-
data3 = data1.merge_different_fields(data2)
|
400
|
-
data3.each do |key, list|
|
401
|
-
list.each do |l| l.replace l.sort_by{|v| v.length}.reverse end
|
402
|
-
end
|
403
|
-
|
404
|
-
assert_equal result, data3.to_s(:sort, true).gsub(/\t/,',')
|
405
|
-
end
|
406
|
-
end
|
407
|
-
|
408
|
-
def test_merge_rows
|
409
|
-
file1 =<<-EOF
|
410
|
-
#ID,letterA,letterB,letterC
|
411
|
-
row1,a,b,c
|
412
|
-
row1,aa,bb,cc
|
413
|
-
row2,A,B,C
|
414
|
-
row3,1,2,3
|
415
|
-
EOF
|
416
|
-
TmpFile.with_file(file1) do |input|
|
417
|
-
TmpFile.with_file() do |output|
|
418
|
-
TSV.merge_row_fields Open.open(input), output, :sep => ','
|
419
|
-
assert Open.read(output) =~ /^#ID,letterA,letterB,letterC$/
|
420
|
-
assert Open.read(output).index "a|aa"
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
|
-
|
425
|
-
end
|
426
|
-
|
427
|
-
def test_one2one
|
428
|
-
content1 =<<-EOF
|
429
|
-
#Id ValueA ValueB
|
430
|
-
row1 a|aa|aaa b
|
431
|
-
row2 A B
|
432
|
-
row3 A b|bb
|
433
|
-
EOF
|
434
|
-
|
435
|
-
content2 =<<-EOF
|
436
|
-
#ValueB OtherID
|
437
|
-
b Id1|Id2
|
438
|
-
B Id3
|
439
|
-
bb Id4
|
440
|
-
EOF
|
441
|
-
tsv1 = tsv2 = nil
|
442
|
-
TmpFile.with_file(content1) do |filename|
|
443
|
-
tsv1 = TSV.open(File.open(filename), :double, :sep => /\s+/)
|
444
|
-
end
|
445
|
-
|
446
|
-
TmpFile.with_file(content2) do |filename|
|
447
|
-
tsv2 = TSV.open(File.open(filename), :double, :sep => /\s+/)
|
448
|
-
end
|
449
|
-
|
450
|
-
tsv1.attach tsv2, :one2one => true
|
451
|
-
|
452
|
-
assert_equal %w(ValueA ValueB OtherID), tsv1.fields
|
453
|
-
assert_equal %w(Id1 Id4), tsv1["row3"]["OtherID"]
|
454
|
-
end
|
455
|
-
|
456
|
-
def test_attach_flat
|
457
|
-
content1 =<<-EOF
|
458
|
-
#Id ValueA ValueB
|
459
|
-
row1 a|aa|aaa b
|
460
|
-
row2 A B
|
461
|
-
EOF
|
462
|
-
|
463
|
-
content2 =<<-EOF
|
464
|
-
#ValueA OtherID
|
465
|
-
a Id1|Id2
|
466
|
-
A Id3
|
467
|
-
EOF
|
468
|
-
|
469
|
-
tsv1 = tsv2 = index = nil
|
470
|
-
TmpFile.with_file(content1) do |filename|
|
471
|
-
tsv1 = TSV.open(File.open(filename), :flat, :fields => ["ValueA"], :sep => /\s+/)
|
472
|
-
end
|
473
|
-
|
474
|
-
TmpFile.with_file(content2) do |filename|
|
475
|
-
tsv2 = TSV.open(File.open(filename), :double, :sep => /\s+/)
|
476
|
-
end
|
477
|
-
|
478
|
-
res = tsv1.attach tsv2, :fields => ["OtherID"]
|
479
|
-
assert res["row2"].include? "Id3"
|
480
|
-
assert ! res["row2"].include?("b")
|
481
|
-
end
|
482
|
-
|
483
|
-
def test_attached_parenthesis
|
484
|
-
|
485
|
-
content1 =<<-EOF
|
486
|
-
#Id,ValueA,bar (ValueB)
|
487
|
-
row1,a|aa|aaa,b
|
488
|
-
row2,A,B
|
489
|
-
EOF
|
490
|
-
|
491
|
-
content2 =<<-EOF
|
492
|
-
#foo (ValueA),OtherID
|
493
|
-
a,Id1|Id2
|
494
|
-
A,Id3
|
495
|
-
EOF
|
496
|
-
|
497
|
-
content3 =<<-EOF
|
498
|
-
#ValueB,ValueC
|
499
|
-
b,c
|
500
|
-
B,C
|
501
|
-
EOF
|
502
|
-
|
503
|
-
content4 =<<-EOF
|
504
|
-
#foobar (Id),ValueD
|
505
|
-
row1,d
|
506
|
-
row5,D
|
507
|
-
EOF
|
508
|
-
|
509
|
-
tsv1 = tsv2 = tsv3 = tsv4 = index = nil
|
510
|
-
TmpFile.with_file(content1) do |filename|
|
511
|
-
tsv1 = TSV.open(File.open(filename), :double, :sep => ',')
|
512
|
-
end
|
513
|
-
|
514
|
-
TmpFile.with_file(content2) do |filename|
|
515
|
-
tsv2 = TSV.open(File.open(filename), :double, :sep => ',')
|
516
|
-
end
|
517
|
-
|
518
|
-
TmpFile.with_file(content3) do |filename|
|
519
|
-
tsv3 = TSV.open(File.open(filename), :double, :sep => ',')
|
520
|
-
end
|
521
|
-
|
522
|
-
TmpFile.with_file(content4) do |filename|
|
523
|
-
tsv4 = TSV.open(File.open(filename), :double, :sep => ',')
|
524
|
-
end
|
525
|
-
|
526
|
-
|
527
|
-
assert_equal tsv1.attach(tsv2)["row1"]["OtherID"], %w(Id1 Id2)
|
528
|
-
assert_equal tsv1.attach(tsv2)["row2"]["OtherID"], %w(Id3)
|
529
|
-
|
530
|
-
assert_equal tsv1.attach(tsv4)["row1"]["ValueD"], %w(d)
|
531
|
-
assert_equal tsv4.attach(tsv1)["row1"]["bar (ValueB)"], %w(b)
|
532
|
-
assert_equal tsv3.attach(tsv1)["b"]["ValueD"], %w(d)
|
533
|
-
end
|
534
|
-
|
535
|
-
def test_attach_single_nils
|
536
|
-
content1 =<<-EOF
|
537
|
-
#Id,ValueA
|
538
|
-
row1,
|
539
|
-
row2,AA
|
540
|
-
EOF
|
541
|
-
content2 =<<-EOF
|
542
|
-
#Id,ValueB
|
543
|
-
row1,B
|
544
|
-
row2,BB
|
545
|
-
EOF
|
546
|
-
content3 =<<-EOF
|
547
|
-
#Id,ValueC
|
548
|
-
row1,
|
549
|
-
row2,CC
|
550
|
-
EOF
|
551
|
-
|
552
|
-
tsv1 = tsv2 = tsv3 = tsv4 = index = nil
|
553
|
-
TmpFile.with_file(content1) do |filename|
|
554
|
-
tsv1 = TSV.open(File.open(filename), :double, :sep => ',', :type => :single)
|
555
|
-
tsv1.keys.each{|k| tsv1[k] = nil if tsv1[k] == ""}
|
556
|
-
end
|
557
|
-
|
558
|
-
TmpFile.with_file(content2) do |filename|
|
559
|
-
tsv2 = TSV.open(File.open(filename), :double, :sep => ',', :type => :single)
|
560
|
-
tsv2.keys.each{|k| tsv2[k] = nil if tsv2[k] == ""}
|
561
|
-
end
|
562
|
-
|
563
|
-
TmpFile.with_file(content3) do |filename|
|
564
|
-
tsv3 = TSV.open(File.open(filename), :double, :sep => ',', :type => :single)
|
565
|
-
tsv3.keys.each{|k| tsv3[k] = nil if tsv3[k] == ""}
|
566
|
-
end
|
567
|
-
|
568
|
-
assert_equal [nil, "B", nil], tsv1.attach(tsv2, :complete => true).attach(tsv3, :complete => true)["row1"]
|
569
|
-
end
|
570
|
-
|
571
|
-
def test_attach_index_both_non_key
|
572
|
-
content1 =<<-EOF
|
573
|
-
#: :sep=/\\s+/
|
574
|
-
#Id ValueA ValueB
|
575
|
-
row1 a|aa|aaa b
|
576
|
-
row2 A B
|
577
|
-
EOF
|
578
|
-
|
579
|
-
content2 =<<-EOF
|
580
|
-
#: :sep=/\\s+/
|
581
|
-
#ValueE OtherID
|
582
|
-
e Id1|Id2
|
583
|
-
E Id3
|
584
|
-
EOF
|
585
|
-
|
586
|
-
content_index =<<-EOF
|
587
|
-
#: :sep=/\\s+/
|
588
|
-
#ValueA OtherID
|
589
|
-
a Id1
|
590
|
-
A Id3
|
591
|
-
EOF
|
592
|
-
|
593
|
-
Rbbt.claim Rbbt.tmp.test.test1.data, :string, content1
|
594
|
-
Rbbt.claim Rbbt.tmp.test.test2.data, :string, content2
|
595
|
-
Rbbt.claim Rbbt.tmp.test.test2.identifiers, :string, content_index
|
596
|
-
|
597
|
-
tsv1 = tsv2 = nil
|
598
|
-
|
599
|
-
tsv1 = Rbbt.tmp.test.test1.data.produce(true).tsv :double, :sep => /\s+/
|
600
|
-
tsv2 = Rbbt.tmp.test.test2.data.produce(true).tsv :double, :sep => /\s+/
|
601
|
-
|
602
|
-
tsv2.identifiers = Rbbt.tmp.test.test2.identifiers.produce(true).produce.find #.to_s
|
603
|
-
|
604
|
-
tsv1.attach tsv2, :fields => ["ValueE"] #, :persist_input => true
|
605
|
-
assert_equal [["a", "aa", "aaa"], ["b"], ["e"]], tsv1["row1"]
|
606
|
-
|
607
|
-
end
|
608
|
-
|
609
|
-
def test_attach_both_non_key
|
610
|
-
content1 =<<-EOF
|
611
|
-
#: :sep=/\\s+/
|
612
|
-
#Id ValueA ValueB
|
613
|
-
row1 a|aa|aaa b
|
614
|
-
row2 A B
|
615
|
-
EOF
|
616
|
-
|
617
|
-
content2 =<<-EOF
|
618
|
-
#: :sep=/\\s+/
|
619
|
-
#ValueE ValueB
|
620
|
-
e b
|
621
|
-
E B
|
622
|
-
EOF
|
623
|
-
Rbbt.claim Rbbt.tmp.test.test1.data, :string, content1
|
624
|
-
Rbbt.claim Rbbt.tmp.test.test2.data, :string, content2
|
625
|
-
|
626
|
-
tsv1 = tsv2 = nil
|
627
|
-
|
628
|
-
tsv1 = Rbbt.tmp.test.test1.data.produce(true).tsv :double, :sep => /\s+/
|
629
|
-
tsv2 = Rbbt.tmp.test.test2.data.produce(true).tsv :double, :sep => /\s+/
|
630
|
-
|
631
|
-
tsv1.attach tsv2, :fields => ["ValueE"] #, :persist_input => true
|
632
|
-
assert_equal [["a", "aa", "aaa"], ["b"], ["e"]], tsv1["row1"]
|
633
|
-
|
634
|
-
end
|
635
|
-
|
636
|
-
def test_attach_complete
|
637
|
-
content1 =<<-EOF
|
638
|
-
#: :sep=/\\s+/
|
639
|
-
#Id ValueA
|
640
|
-
row1 a|aa|aaa
|
641
|
-
row2 A
|
642
|
-
EOF
|
643
|
-
|
644
|
-
content2 =<<-EOF
|
645
|
-
#: :sep=/\\s+/
|
646
|
-
#Id ValueB
|
647
|
-
row1 b
|
648
|
-
row3 C
|
649
|
-
EOF
|
650
|
-
Rbbt.claim Rbbt.tmp.test.test1.data, :string, content1
|
651
|
-
Rbbt.claim Rbbt.tmp.test.test2.data, :string, content2
|
652
|
-
|
653
|
-
tsv1 = tsv2 = nil
|
654
|
-
|
655
|
-
tsv1 = Rbbt.tmp.test.test1.data.produce(true).tsv :double, :sep => /\s+/
|
656
|
-
tsv2 = Rbbt.tmp.test.test2.data.produce(true).tsv :double, :sep => /\s+/
|
657
|
-
|
658
|
-
tsv1.attach tsv2, :complete => true
|
659
|
-
assert_equal [[], ["C"]], tsv1["row3"]
|
660
|
-
|
661
|
-
tsv1 = Rbbt.tmp.test.test1.data.produce(true).tsv :double, :sep => /\s+/
|
662
|
-
tsv2 = Rbbt.tmp.test.test2.data.produce(true).tsv :double, :sep => /\s+/
|
663
|
-
|
664
|
-
tsv1.attach tsv2, :complete => ["AA"]
|
665
|
-
assert_equal [["AA"], ["C"]], tsv1["row3"]
|
666
|
-
end
|
667
|
-
|
668
|
-
def test_attach_complete_identifiers
|
669
|
-
content1 =<<-EOF
|
670
|
-
#: :sep=/\\s+/
|
671
|
-
#Id ValueA
|
672
|
-
row1 a|aa|aaa
|
673
|
-
row2 A
|
674
|
-
EOF
|
675
|
-
|
676
|
-
content2 =<<-EOF
|
677
|
-
#: :sep=/\\s+/
|
678
|
-
#Id2 ValueB
|
679
|
-
ROW_1 b
|
680
|
-
ROW_2 C
|
681
|
-
EOF
|
682
|
-
|
683
|
-
identifiers =<<-EOF
|
684
|
-
#: :sep=/\\s+/
|
685
|
-
#Id Id2
|
686
|
-
row1 ROW_1
|
687
|
-
row2 ROW_2
|
688
|
-
row3 ROW_3
|
689
|
-
EOF
|
690
|
-
Rbbt.claim Rbbt.tmp.test.test1.data, :string, content1
|
691
|
-
Rbbt.claim Rbbt.tmp.test.test2.data, :string, content2
|
692
|
-
Rbbt.claim Rbbt.tmp.test.identifiers.data, :string, identifiers
|
693
|
-
|
694
|
-
tsv1 = tsv2 = nil
|
695
|
-
|
696
|
-
tsv1 = Rbbt.tmp.test.test1.data.produce(true).tsv :double, :sep => /\s+/
|
697
|
-
tsv2 = Rbbt.tmp.test.test2.data.produce(true).tsv :double, :sep => /\s+/
|
698
|
-
ids = Rbbt.tmp.test.identifiers.data.produce(true).tsv :double, :sep => /\s+/
|
699
|
-
|
700
|
-
tsv1.identifiers = ids
|
701
|
-
|
702
|
-
tsv1.attach tsv2
|
703
|
-
assert_equal [["A"], ["C"]], tsv1["row2"]
|
704
|
-
|
705
|
-
tsv1 = Rbbt.tmp.test.test1.data.produce(true).tsv :double, :sep => /\s+/
|
706
|
-
tsv2 = Rbbt.tmp.test.test2.data.produce(true).tsv :double, :sep => /\s+/
|
707
|
-
ids = Rbbt.tmp.test.identifiers.data.produce(true).tsv :double, :sep => /\s+/
|
708
|
-
|
709
|
-
tsv1.identifiers = ids
|
710
|
-
|
711
|
-
tsv1.attach tsv2, :complete => true
|
712
|
-
assert_equal [["A"], ["C"]], tsv1["row2"]
|
713
|
-
end
|
714
|
-
end
|
715
|
-
|